humanize

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package humanize renders byte counts as human-readable strings and sums a directory tree's apparent (logical) size, for boid's workspace-home size reporting (`boid workspace show`, `boid gc`'s workspace_homes listing, and the confirmation prompt on `boid workspace remove`).

FormatBytes is what those three still use. ApparentSize is not — sizing moved onto the docker engine since a workspace home is a volume the daemon cannot walk directly; see ApparentSize's own doc comment for its current status.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApparentSize

func ApparentSize(root string) (int64, error)

ApparentSize has NO production caller any more — sizing a live workspace home moved onto the docker engine's GET /system/df, since the daemon cannot walk a volume's contents from outside a container. It is kept for `boid workspace import-home`, which still sizes legacy pre-migration <runtimesRoot>/homes/<slug> directories on disk.

ApparentSize returns the total *apparent* (logical) size, in bytes, of every regular file found by recursively walking root — directory entries themselves do not contribute to the total, only file content sizes do. Symlinks are not followed (filepath.Walk uses Lstat internally), so a symlink's own directory-entry size is counted but nothing on the far side of it is descended into — this avoids both symlink loops and a home directory's size silently including content that lives outside it.

This is a plain sum of FileInfo.Size() and is *not* a `du`-equivalent block-based measurement: it deliberately matches `du --apparent-size`, not plain `du`. Two known, accepted trade-offs follow: a sparse file's logical size is counted even though it occupies far fewer disk blocks, and a hardlinked file is counted once per name found rather than once per inode. Apparent size is judged good enough for boid's "is this workspace home suspiciously large" visibility use case.

Any error encountered while walking aborts the walk immediately and is returned verbatim; callers must treat a non-nil error as "size unknown" rather than trusting the also-returned partial total.

func FormatBytes

func FormatBytes(n int64) string

FormatBytes renders n as a human-readable SI byte size: a plain integer count below 1000 ("500 B", "0 B"), or "%.2f <unit>" (two decimal places) scaled to the largest unit that keeps the leading digit non-zero (KB, MB, GB, TB, PB — boid workspace homes are not expected to reach EB). Negative values (should not occur — callers only ever pass a summed directory size) are treated as 0 B rather than producing a nonsensical "-1 B".

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL