Skip to content

Commit

Permalink
fix(memory) use bibyte everywhere and avoid the MB or GB reportings
Browse files Browse the repository at this point in the history
Signed-off-by: David Edler <[email protected]>
  • Loading branch information
edlerd committed Apr 29, 2024
1 parent 8b0ee16 commit df2a65a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/components/forms/MemoryLimitSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const MemoryLimitSelector: FC<Props> = ({ memoryLimit, setMemoryLimit }) => {
return "";
}
if (memoryLimit.unit === "%") {
return humanFileSize(maxMemory, true);
return humanFileSize(maxMemory);
}
const formattedValue = getFormattedMaxValue(memoryLimit.unit) ?? 0;
if (formattedValue < 1) {
Expand Down
8 changes: 3 additions & 5 deletions src/util/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,16 @@ export const handleTextResponse = async (
return response.text();
};

export const humanFileSize = (bytes: number, toBibyte = false): string => {
export const humanFileSize = (bytes: number): string => {
if (Math.abs(bytes) < 1000) {
return `${bytes} B`;
}

const units = toBibyte
? ["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"]
: ["kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
const units = ["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
let u = -1;

do {
bytes /= toBibyte ? 1024 : 1000;
bytes /= 1024;
++u;
} while (
Math.round(Math.abs(bytes) * 10) / 10 >= 1000 &&
Expand Down

0 comments on commit df2a65a

Please sign in to comment.