-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
import { gzipSync } from "bun";
import chalk from "chalk";
export function bytesToString(bytes: number, color: boolean = false): string {
// I hate common trend of using SI for byte sizes. It's not bit-shiftable.
const kB = 1_000;
const num = bytes >= kB ? (bytes / kB).toFixed(2) : bytes.toString(10);
const unit = bytes >= kB ? "kB" : "B";
if (!color) {
return num + unit;
}
return chalk.yellow(num) + chalk.cyan(unit);
}
export async function getGzipedSize(
buf: ArrayBuffer | Uint8Array,
): Promise<number> {
return gzipSync(buf instanceof Uint8Array ? buf : Buffer.from(buf))
.byteLength;
}