diff options
| author | 2022-07-24 01:21:07 -0700 | |
|---|---|---|
| committer | 2022-07-24 01:22:33 -0700 | |
| commit | 8e84f361ac94303fc318335aa73f1258edc2c14b (patch) | |
| tree | 10152519c2438d2317d6e21d8870a56140a07871 | |
| parent | c921e4a3f1e8eb4f5f584407cfdcebd4ea66cbfa (diff) | |
| download | bun-8e84f361ac94303fc318335aa73f1258edc2c14b.tar.gz bun-8e84f361ac94303fc318335aa73f1258edc2c14b.tar.zst bun-8e84f361ac94303fc318335aa73f1258edc2c14b.zip | |
Print < 512 bytes as "N bytes" instead of "0.0"
Diffstat (limited to '')
| -rw-r--r-- | src/global.zig | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/global.zig b/src/global.zig index 483c73514..9d68753ea 100644 --- a/src/global.zig +++ b/src/global.zig @@ -33,13 +33,18 @@ pub const fmt = struct { pub const SizeFormatter = struct { value: usize = 0, - pub fn format(self: SizeFormatter, comptime _: []const u8, _: fmt.FormatOptions, writer: anytype) !void { + pub fn format(self: SizeFormatter, comptime _: []const u8, opts: fmt.FormatOptions, writer: anytype) !void { const math = std.math; const value = self.value; if (value == 0) { return writer.writeAll("0 KB"); } + if (value < 512) { + try fmt.formatInt(self.value, 10, .lower, opts, writer); + return writer.writeAll(" bytes"); + } + const mags_si = " KMGTPEZY"; const mags_iec = " KMGTPEZY"; |
