Skip to content

Commit

Permalink
web: Display file size in units instead of bytes, closes #149
Browse files Browse the repository at this point in the history
Signed-off-by: Mikhail Petrov <[email protected]>
  • Loading branch information
mike-petrov committed Feb 2, 2024
1 parent f752f80 commit ada8fa5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Components/TreeView/TreeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ const Folder = ({ name, children }) => {
);
};

function formatBytes(bytes) {
const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
let i = 0
for (i; bytes > 1000; i += 1) {
bytes /= 1000;
}
return `${bytes === 0 ? bytes : bytes.toFixed(1)} ${units[i]}`;
}

const File = ({
params,
name,
Expand Down Expand Up @@ -155,7 +164,7 @@ const File = ({
</Heading>
<Heading size={6} weight="light">
<span>{`Object size: `}</span>
{objectDate.objectSize}
{formatBytes(objectDate.objectSize)}
</Heading>
</Section>
<Section style={{ paddingTop: 0 }}>
Expand Down

0 comments on commit ada8fa5

Please sign in to comment.