https://github.com/linkdata/bytecount
Human readable byte count using KB, MB, GB etc
https://github.com/linkdata/bytecount
formatter go golang human-readable human-readable-numbers
Last synced: 7 months ago
JSON representation
Human readable byte count using KB, MB, GB etc
- Host: GitHub
- URL: https://github.com/linkdata/bytecount
- Owner: linkdata
- License: mit
- Created: 2024-11-22T06:36:04.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-08-21T08:21:01.000Z (7 months ago)
- Last Synced: 2025-08-21T10:34:32.555Z (7 months ago)
- Topics: formatter, go, golang, human-readable, human-readable-numbers
- Language: Go
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/linkdata/bytecount/actions/workflows/go.yml)
[](https://htmlpreview.github.io/?https://github.com/linkdata/bytecount/blob/coverage/main/report.html)
[](https://goreportcard.com/report/github.com/linkdata/bytecount)
[](https://godoc.org/github.com/linkdata/bytecount)
# bytecount
Go pretty printer for byte counts.
Only depends on the standard library.
## Usage
`go get github.com/linkdata/bytecount`
When printing byte counts using the `fmt` package, pass the values using `bytecount.N(n)`.
You may pass width and precision if you wish. The default is to keep the output to
a maximum of six characters while still showing as much precision as possible.
The highest byte count printable is 268435440QB (Quetta-bytes, 10³⁰),
exceeding this will print `+InfQB`.
If the formatting verb is `d` (e.g. `"%d"`), the divisor is 1000 rather than 1024.
If the formatting verb is `b` (e.g. `"%b"`), the value is multiplied by 8 and the
unit suffix is changed from `B` (bytes) to `b` (bits).
If the `"#"` flag is given, no unit suffix is written.
If the `" "` flag is given, a space is written between the digits and the suffix.
## Example
```go
import (
"fmt"
"github.com/linkdata/bytecount"
)
func main() {
fmt.Print(bytecount.N(53667551))
// Output:
// 51.2MB
}
```