mirror of https://github.com/kiwix/libkiwix.git
Book sizes are shown in binary (MiB, etc) units
Switched display of ZIM sizes from decimal (MB) to binary (MiB) units. Also made the size value to be formatted in a more human friendly way (fractional part is shown only to provide at least three significant digits).
This commit is contained in:
parent
beab8d7041
commit
97832c8436
|
@ -78,15 +78,21 @@
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function humanFriendlyNumStr(num, precision) {
|
||||||
|
const n = Math.abs(num).toFixed().length;
|
||||||
|
return num.toFixed(Math.max(0, precision - n));
|
||||||
|
}
|
||||||
|
|
||||||
const humanFriendlySize = (fileSize) => {
|
const humanFriendlySize = (fileSize) => {
|
||||||
if (fileSize === 0) {
|
if (fileSize === 0) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
const units = ['bytes', 'kB', 'MB', 'GB', 'TB'];
|
const units = ['bytes', 'KiB', 'MiB', 'GiB', 'TiB'];
|
||||||
let quotient = Math.floor(Math.log10(fileSize) / 3);
|
let quotient = Math.floor(Math.log2(fileSize) / 10);
|
||||||
quotient = quotient < units.length ? quotient : units.length - 1;
|
quotient = Math.min(quotient, units.length - 1);
|
||||||
fileSize /= (1000 ** quotient);
|
fileSize /= (1024 ** quotient);
|
||||||
return `${+fileSize.toFixed(2)} ${units[quotient]}`;
|
const fileSizeStr = humanFriendlyNumStr(fileSize, 3);
|
||||||
|
return `${fileSizeStr} ${units[quotient]}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const humanFriendlyTitle = (title) => {
|
const humanFriendlyTitle = (title) => {
|
||||||
|
|
|
@ -63,7 +63,7 @@ const ResourceCollection resources200Compressible{
|
||||||
{ DYNAMIC_CONTENT, "/ROOT%23%3F/skin/index.css" },
|
{ DYNAMIC_CONTENT, "/ROOT%23%3F/skin/index.css" },
|
||||||
{ STATIC_CONTENT, "/ROOT%23%3F/skin/index.css?cacheid=1e78e7cf" },
|
{ STATIC_CONTENT, "/ROOT%23%3F/skin/index.css?cacheid=1e78e7cf" },
|
||||||
{ DYNAMIC_CONTENT, "/ROOT%23%3F/skin/index.js" },
|
{ 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" },
|
{ DYNAMIC_CONTENT, "/ROOT%23%3F/skin/iso6391To3.js" },
|
||||||
{ STATIC_CONTENT, "/ROOT%23%3F/skin/iso6391To3.js?cacheid=ecde2bb3" },
|
{ STATIC_CONTENT, "/ROOT%23%3F/skin/iso6391To3.js?cacheid=ecde2bb3" },
|
||||||
{ DYNAMIC_CONTENT, "/ROOT%23%3F/skin/isotope.pkgd.min.js" },
|
{ 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"
|
||||||
<script type="text/javascript" src="/ROOT%23%3F/skin/languages.js?cacheid=ee7d95b5" defer></script>
|
<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/isotope.pkgd.min.js?cacheid=2e48d392" defer></script>
|
||||||
<script src="/ROOT%23%3F/skin/iso6391To3.js?cacheid=ecde2bb3"></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/feed.svg?cacheid=055b333f"
|
||||||
<img src="/ROOT%23%3F/skin/langSelector.svg?cacheid=00b59961"
|
<img src="/ROOT%23%3F/skin/langSelector.svg?cacheid=00b59961"
|
||||||
)EXPECTEDRESULT"
|
)EXPECTEDRESULT"
|
||||||
|
|
Loading…
Reference in New Issue