aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-07-24 01:21:07 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-07-24 01:22:33 -0700
commit8e84f361ac94303fc318335aa73f1258edc2c14b (patch)
tree10152519c2438d2317d6e21d8870a56140a07871
parentc921e4a3f1e8eb4f5f584407cfdcebd4ea66cbfa (diff)
downloadbun-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.zig7
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";