Skip to content

Commit

Permalink
Merge pull request #1096 from harsha-mangena/i1095-consistancy-issue
Browse files Browse the repository at this point in the history
[fixes]ZIM size being advertized inconsistently between MB and MiB
  • Loading branch information
veloman-yunkan authored Jun 24, 2024
2 parents beab8d7 + 97832c8 commit 964131c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
16 changes: 11 additions & 5 deletions static/skin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions test/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down Expand Up @@ -292,7 +292,7 @@ R"EXPECTEDRESULT( href="/ROOT%23%3F/skin/kiwix.css?cacheid=2158fad9"
<script type="text/javascript" src="/ROOT%23%3F/skin/languages.js?cacheid=ee7d95b5" defer></script>
<script src="/ROOT%23%3F/skin/isotope.pkgd.min.js?cacheid=2e48d392" defer></script>
<script src="/ROOT%23%3F/skin/iso6391To3.js?cacheid=ecde2bb3"></script>
<script type="text/javascript" src="/ROOT%23%3F/skin/index.js?cacheid=436e0a63" defer></script>
<script type="text/javascript" src="/ROOT%23%3F/skin/index.js?cacheid=f43eb0b9" defer></script>
<img src="/ROOT%23%3F/skin/feed.svg?cacheid=055b333f"
<img src="/ROOT%23%3F/skin/langSelector.svg?cacheid=00b59961"
)EXPECTEDRESULT"
Expand Down

0 comments on commit 964131c

Please sign in to comment.