Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix erroneous filesize units #4266

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions ui/v2.5/src/utils/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,28 @@ import { IntlShape } from "react-intl";
// Typescript currently does not implement the intl Unit interface
type Unit =
| "byte"
| "kilobyte"
| "megabyte"
| "gigabyte"
| "terabyte"
| "petabyte";
| "kibibyte"
| "mebibyte"
| "gibibyte"
| "tebibyte"
| "pebibyte";
const Units: Unit[] = [
"byte",
"kilobyte",
"megabyte",
"gigabyte",
"terabyte",
"petabyte",
"kibibyte",
"mebibyte",
"gibibyte",
"tebibyte",
"pebibyte",
];
const shortUnits = ["B", "KB", "MB", "GB", "TB", "PB"];
const shortUnits = ["B", "KiB", "MiB", "GiB", "TiB", "PiB"];

const fileSize = (bytes: number = 0) => {
if (Number.isNaN(parseFloat(String(bytes))) || !Number.isFinite(bytes))
return { size: 0, unit: Units[0] };

let unit = 0;
let count = bytes;
// calculating base 2 units
while (count >= 1024 && unit + 1 < Units.length) {
count /= 1024;
unit++;
Expand Down