
pool/sid/main/g/golang-github-c2h5oh-datasize/golang-github-c2h5oh-datasize-dev_0.0~git20200825.48ed595-1_all.deb
golang-github-c2h5oh-datasize-dev| Filename | pool/sid/main/g/golang-github-c2h5oh-datasize/golang-github-c2h5oh-datasize-dev_0.0~git20200825.48ed595-1_all.deb |
| Version | 0.0~git20200825.48ed595-1 |
| Age in days | 709 |
| Release date | 2024 11. 28. |
| Size | 4.35 KB |
| id | 105 |
| Name | golang-github-c2h5oh-datasize-dev |
| Package | |
| Appname | |
| Essential | |
| Vendor | |
| License | |
| Distribution | sid |
| Suite | main |
| Source | golang-github-c2h5oh-datasize |
| Architecture | binary-i386 |
| MultiArch | |
| Maintainer | Debian Go Packaging Team |
| InstalledSize | 19 |
| PreDepends | |
| Breaks | |
| Enhances | |
| Section | devel |
| Priority | optional |
| Description | Golang helpers for data sizes (kilobytes, petabytes), human readable sizes, parsing |
| LongDescription | datasize Build Status (https://travis-ci.org/c2h5oh/datasize) Golanghelpers for data sizes Constants Just like time package providestime.Second, time.Day constants datasize provides: • datasize.B 1byte• datasize.KB 1 kilobyte• datasize.MB 1 megabyte• datasize.GB1 gigabyte• datasize.TB 1 terabyte• datasize.PB 1 petabyte•datasize.EB 1 exabyteHelpers Just like time package providesduration.Nanoseconds() uint64, duration.Hours() float64 helpersdatasize has. • ByteSize.Bytes() uint64• ByteSize.Kilobytes()float64• ByteSize.Megabytes() float64• ByteSize.Gigabytes()float64• ByteSize.Terabytes() float64• ByteSize.Petebytes()float64• ByteSize.Exabytes() float64 Warning: see limitations atthe end of this document about a possible precission loss Parsingstrings datasize.ByteSize implements TextUnmarshaler interface andwill automatically parse human readable strings into correct valueswhere it is used: • "10 MB" -> 10* datasize.MB• "10240 g" -> 10 *datasize.TB• "2000" -> 2000 * datasize.B• "1tB" -> datasize.TB•"5 peta" -> 5 * datasize.PB• "28 kilobytes" -> 28 * datasize.KB•"1 gigabyte" -> 1 * datasize.GB You can also do it manually:.go var v datasize.ByteSize err := v.UnmarshalText([]byte("100 mb")).Printing Bytesize.String() uses largest unit allowing an integervalue: • (102400 * datasize.MB).String() -> "100GB"• (datasize.MB +datasize.KB).String() -> "1025KB" Use %d format string to get value inbytes without a unit. JSON and other encoding Both TextMarshaler andTextUnmarshaler interfaces are implemented - JSON will just work. Otherencoders will work provided they use those interfaces. Human readableByteSize.HumanReadable() or ByteSize.HR() returns a string with 1-3digits, followed by 1 decimal place, a space and unit big enough toget 1-3 digits • (102400 * datasize.MB).String() -> "100.0 GB"•(datasize.MB + 512 * datasize.KB).String() -> "1.5 MB"Limitations•The underlying data type for data.ByteSize is uint64, so valuesoutside of 0 to 2^64-1 range will overflow• size helper functions(like ByteSize.Kilobytes()) return float64, which can't representall possible values of uint64 accurately: • if the returned valueis supposed to have no fraction (ie (10 * datasize.MB).Kilobytes())accuracy loss happens when value is more than 2^53 larger than unit:.Kilobytes() over 8 petabytes, .Megabytes() over 8 exabytes• ifthe returned value is supposed to have a fraction (ie (datasize.PB +datasize.B).Megabytes()) in addition to the above note accuracy loss mayoccur in fractional part too - larger integer part leaves fewer bytes tostore fractional part, the smaller the remainder vs unit the move bytesare required to store the fractional part• Parsing a string with Mb,Tb, etc units will return a syntax error, because capital followed bylower case is commonly used for bits, not bytes• Parsing a string withvalue exceeding 2^64-1 bytes will return 2^64-1 and an out of range error |
| AutoBuiltPackage | |
| Filename | pool/sid/main/g/golang-github-c2h5oh-datasize/golang-github-c2h5oh-datasize-dev_0.0~git20200825.48ed595-1_all.deb |
| MD5sum | 0579b61f027846c90a9386f549330fd3 |
| SHA1 | ee5f60932e29f527108bb0f9fd705140da0f6bd9 |
| SHA256 | e78f1887634a346642fdccb2e6d180a02b84055a924ef2b033c28bedd01f8bbb |
| SHA512 | 195994e9e0eb62e2219b68028c00439e151f7fca1204203862ea9d3c2351df6ecb4db3770bbc0f6876e80dfeb6615480999b3a2ea221bbb50d1a6f82a3d5b006 |
| Size | 4452 |
| Auto-Built-Package | |
| Homepage | https://github.com/c2h5oh/datasize |
| Provides | |
| Existing | |
| fileMtime | 2024-11-28 12:35:02 |
| created | 2021-03-20 02:24:33 |
| updated | 2024-11-28 11:35:02 |

| ./ | |
| ./usr/ | |
| ./usr/share/ | |
| ./usr/share/doc/ | |
| ./usr/share/doc/golang-github-c2h5oh-datasize-dev/ | |
| ./usr/share/doc/golang-github-c2h5oh-datasize-dev/changelog.Debian.gz | 200 |
| ./usr/share/doc/golang-github-c2h5oh-datasize-dev/copyright | 411 |
| ./usr/share/gocode/ | |
| ./usr/share/gocode/src/ | |
| ./usr/share/gocode/src/github.com/ | |
| ./usr/share/gocode/src/github.com/c2h5oh/ | |
| ./usr/share/gocode/src/github.com/c2h5oh/datasize/ | |
| ./usr/share/gocode/src/github.com/c2h5oh/datasize/datasize.go | 4044 |
| ./usr/share/gocode/src/github.com/c2h5oh/datasize/datasize_test.go | 1410 |
| ./ | |
| ./usr/ | |
| ./usr/share/ | |
| ./usr/share/doc/ | |
| ./usr/share/doc/golang-github-c2h5oh-datasize-dev/ | |
| ./usr/share/doc/golang-github-c2h5oh-datasize-dev/changelog.Debian.gz | 200 |
| ./usr/share/doc/golang-github-c2h5oh-datasize-dev/copyright | 411 |
| ./usr/share/gocode/ | |
| ./usr/share/gocode/src/ | |
| ./usr/share/gocode/src/github.com/ | |
| ./usr/share/gocode/src/github.com/c2h5oh/ | |
| ./usr/share/gocode/src/github.com/c2h5oh/datasize/ | |
| ./usr/share/gocode/src/github.com/c2h5oh/datasize/datasize.go | 4044 |
| ./usr/share/gocode/src/github.com/c2h5oh/datasize/datasize_test.go | 1410 |
Golang helpers for data sizes
Just like time package provides time.Second, time.Day constants datasize provides:
datasize.B 1 bytedatasize.KB 1 kilobytedatasize.MB 1 megabytedatasize.GB 1 gigabytedatasize.TB 1 terabytedatasize.PB 1 petabytedatasize.EB 1 exabyteJust like time package provides duration.Nanoseconds() uint64 , duration.Hours() float64 helpers datasize has.
ByteSize.Bytes() uint64ByteSize.Kilobytes() float64ByteSize.Megabytes() float64ByteSize.Gigabytes() float64ByteSize.Terabytes() float64ByteSize.Petabytes() float64ByteSize.Exabytes() float64Warning: see limitations at the end of this document about a possible precision loss
datasize.ByteSize implements TextUnmarshaler interface and will automatically parse human readable strings into correct values where it is used:
"10 MB" -> 10* datasize.MB"10240 g" -> 10 * datasize.TB"2000" -> 2000 * datasize.B"1tB" -> datasize.TB"5 peta" -> 5 * datasize.PB"28 kilobytes" -> 28 * datasize.KB"1 gigabyte" -> 1 * datasize.GBYou can also do it manually:
var v datasize.ByteSize
err := v.UnmarshalText([]byte("100 mb"))
Bytesize.String() uses largest unit allowing an integer value:
(102400 * datasize.MB).String() -> "100GB"(datasize.MB + datasize.KB).String() -> "1025KB"Use %d format string to get value in bytes without a unit.
Both TextMarshaler and TextUnmarshaler interfaces are implemented - JSON will just work. Other encoders will work provided they use those interfaces.
ByteSize.HumanReadable() or ByteSize.HR() returns a string with 1-3 digits, followed by 1 decimal place, a space and unit big enough to get 1-3 digits
(102400 * datasize.MB).String() -> "100.0 GB"(datasize.MB + 512 * datasize.KB).String() -> "1.5 MB"data.ByteSize is uint64, so values outside of 0 to 2^64-1 range will overflowByteSize.Kilobytes()) return float64, which can't represent all possible values of uint64 accurately:
(10 * datasize.MB).Kilobytes()) accuracy loss happens when value is more than 2^53 larger than unit: .Kilobytes() over 8 petabytes, .Megabytes() over 8 exabytes(datasize.PB + datasize.B).Megabytes()) in addition to the above note accuracy loss may occur in fractional part too - larger integer part leaves fewer bytes to store fractional part, the smaller the remainder vs unit the move bytes are required to store the fractional partMb, Tb, etc units will return a syntax error, because capital followed by lower case is commonly used for bits, not bytes| Version | Download/Install count | Last hit |
|---|