diff --git a/static/skin/index.js b/static/skin/index.js
index b46c5be90..28a452d2b 100644
--- a/static/skin/index.js
+++ b/static/skin/index.js
@@ -78,15 +78,21 @@
return result;
}
+ function humanFriendlyNumStr(num, precision) {
+ const n = Math.abs(num).toFixed().length;
+ return num.toFixed(Math.max(0, precision - n));
+ }
+
const humanFriendlySize = (fileSize) => {
if (fileSize === 0) {
return '';
}
- const units = ['bytes', 'kB', 'MB', 'GB', 'TB'];
- let quotient = Math.floor(Math.log10(fileSize) / 3);
- quotient = quotient < units.length ? quotient : units.length - 1;
- fileSize /= (1000 ** quotient);
- return `${+fileSize.toFixed(2)} ${units[quotient]}`;
+ const units = ['bytes', 'KiB', 'MiB', 'GiB', 'TiB'];
+ let quotient = Math.floor(Math.log2(fileSize) / 10);
+ quotient = Math.min(quotient, units.length - 1);
+ fileSize /= (1024 ** quotient);
+ const fileSizeStr = humanFriendlyNumStr(fileSize, 3);
+ return `${fileSizeStr} ${units[quotient]}`;
};
const humanFriendlyTitle = (title) => {
diff --git a/test/server.cpp b/test/server.cpp
index ce111c933..44fc99311 100644
--- a/test/server.cpp
+++ b/test/server.cpp
@@ -63,7 +63,7 @@ const ResourceCollection resources200Compressible{
{ DYNAMIC_CONTENT, "/ROOT%23%3F/skin/index.css" },
{ STATIC_CONTENT, "/ROOT%23%3F/skin/index.css?cacheid=1e78e7cf" },
{ DYNAMIC_CONTENT, "/ROOT%23%3F/skin/index.js" },
- { STATIC_CONTENT, "/ROOT%23%3F/skin/index.js?cacheid=436e0a63" },
+ { STATIC_CONTENT, "/ROOT%23%3F/skin/index.js?cacheid=f43eb0b9" },
{ DYNAMIC_CONTENT, "/ROOT%23%3F/skin/iso6391To3.js" },
{ STATIC_CONTENT, "/ROOT%23%3F/skin/iso6391To3.js?cacheid=ecde2bb3" },
{ DYNAMIC_CONTENT, "/ROOT%23%3F/skin/isotope.pkgd.min.js" },
@@ -292,7 +292,7 @@ R"EXPECTEDRESULT( href="/ROOT%23%3F/skin/kiwix.css?cacheid=2158fad9"
-
+
