Giter Site home page Giter Site logo

go-units's Introduction

GoDoc

Introduction

go-units is a library to transform human friendly measurements into machine friendly values.

Usage

See the docs in godoc for examples and documentation.

Copyright and license

Copyright ยฉ 2015 Docker, Inc.

go-units is licensed under the Apache License, Version 2.0. See LICENSE for the full text of the license.

go-units's People

Contributors

allencloud avatar blatyo avatar boaz0 avatar brahmaroutu avatar calavera avatar crosbymichael avatar dnephin avatar duglin avatar estesp avatar fabianofranz avatar fcarriedo avatar florinasavoaie avatar hukeping avatar inatatsu avatar jessfraz avatar jubarbot-cisco avatar kezhuw avatar kolyshkin avatar lk4d4 avatar onlyjob avatar ottok avatar snitm avatar thajeztah avatar tiborvass avatar unclejack avatar vdemeester avatar vieux avatar weizhang555 avatar wernight avatar yongtang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-units's Issues

FromHumanSize accepts MiB but returns MB

One might expect that FromHumanSize("1MiB") would either

  • return error
  • return units.MiB (1024 * 1024 * 1024)

Currently it does not raise error and returns units.MB (1000 * 1000 * 1000)

Inconsistent decimal places

go-units removes trailing zeros in its output. This makes the output in Docker's progress indicators not line up.

Current:

cba48ac2c991: Downloading    23 MB/37.18 MB
f19be92d17a1: Downloading  24.3 MB/64.6 MB

Better:

cba48ac2c991: Downloading  23.0 MB/37.18 MB
f19be92d17a1: Downloading  24.3 MB/64.60 MB

One decimal place should be enough when dealing with sizes:

cba48ac2c991: Downloading  23.0 MB/37.2 MB
f19be92d17a1: Downloading  24.3 MB/64.6 MB

HumanSizeWithPrecision uses scientific notation in some invalid cases

Let's keep it short, such a test will fail:

assertEquals(t, "1GB", HumanSizeWithPrecision(999.6*MB, 3))

With the following message:

Expected '1GB' but got '1e+03MB'

The case holds in the following scenarios:

  • any 999.5 <= x < 1000 for any unit including bytes, kB, MB, GB, etc. (with precision 1, 2, or 3)
  • any 99.5 <= x < 1000 for any unit including bytes, kB, MB, GB, etc. (with precision 1 or 2)
  • any 9.5 <= x < 1000 for any unit including bytes, kB, MB, GB, etc. (with precision 1)

However, it works fine with precision 4 or higher.

Tag 0.3.3

Hi there, thanks for the helpful lib! Could we get a tag v0.3.3 pushed to include the fix from #27?

Thanks!

HumanSize strings cannot be round-tripped

If I do:

size, err := units.FromHumanSize(units.HumanSize(1024.0 * 1024.0 * 1024.0))

I will get as an error:

invalid size: '1.074GB'

Presumably, FromHumanSize should be able to parse the strings that HumanSize outputs. I believe that this is because FromHumanSize doesn't handle decimal points.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.