From 716ff0652ba7a2c1d7418efc82017c9c30f47b6e Mon Sep 17 00:00:00 2001 From: Mikhail Petrov Date: Fri, 2 Feb 2024 14:39:54 +0300 Subject: [PATCH] web: Display file size in units instead of bytes, closes #149 Signed-off-by: Mikhail Petrov --- src/Components/TreeView/TreeView.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Components/TreeView/TreeView.js b/src/Components/TreeView/TreeView.js index 08ce2f3..9378d60 100644 --- a/src/Components/TreeView/TreeView.js +++ b/src/Components/TreeView/TreeView.js @@ -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 >= 1024; i += 1) { + bytes /= 1024; + } + return `${bytes === 0 ? bytes : bytes.toFixed(1)} ${units[i]}`; +} + const File = ({ params, name, @@ -155,7 +164,7 @@ const File = ({ {`Object size: `} - {objectDate.objectSize} + {formatBytes(objectDate.objectSize)}