https://github.com/zpatrick/go-bytesize
Utility package for working with common memory and cpu units in Go
https://github.com/zpatrick/go-bytesize
byte bytes bytesize go golang
Last synced: 9 days ago
JSON representation
Utility package for working with common memory and cpu units in Go
- Host: GitHub
- URL: https://github.com/zpatrick/go-bytesize
- Owner: zpatrick
- License: mit
- Created: 2017-02-13T22:56:51.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-14T18:20:54.000Z (almost 9 years ago)
- Last Synced: 2026-01-12T05:27:55.439Z (15 days ago)
- Topics: byte, bytes, bytesize, go, golang
- Language: Go
- Homepage:
- Size: 11.7 KB
- Stars: 30
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go Bytesize
[](https://github.com/zpatrick/go-bytesize/blob/master/LICENSE)
[](https://goreportcard.com/report/github.com/zpatrick/go-bytesize)
[](https://godoc.org/github.com/zpatrick/go-bytesize)
## Overview
Go Bytesize is a utility package for working with common multiples of bytes in Go, such as: Bytes (B), Kilobytes (KB), Megabytes (MB), Gigabytes (GB), Terabytes (TB), Petabytes (PB), Exabytes (EB), Kibibytes (Kib), Mebibytes (MiB), Gibibytes (GiB), Tebibytes (TiB), Pebibytes (PiB), and Exbibytes (EiB).
## Example
```
package main
import (
"fmt"
"github.com/zpatrick/go-bytesize"
)
func main() {
b := bytesize.Bytesize(10000)
fmt.Printf("%g bytes is: %g KB and %g MB\n", b, b.Kilobytes(), b.Megabytes())
b = bytesize.TB * 2
fmt.Printf("2 Terabytes is %g Gibibytes\n", b.Gibibytes())
b = bytesize.Bytesize(1000000)
fmt.Printf("%g bytes is %s\n", b, b.Format("mb"))
}
```
Output:
```
10000 bytes is: 10 KB and 0.01 MB
2 Terabytes is 1862.645149230957 Gibibytes
1e+06 bytes is 1MB
```
## License
This work is published under the MIT license.
Please see the `LICENSE` file for details.