docker / go-units

Parse and print size and time units in human-readable format
https://godoc.org/github.com/docker/go-units
Apache License 2.0
218 stars 38 forks source link

Enhance FromHumanSize to parse float64 string #8

Closed WeiZhang555 closed 8 years ago

WeiZhang555 commented 8 years ago

Currently FromHumanSize can only interpret format of '32kB', this commit enhance it to interpret float64 string with blank such as '32.3 kB'.

Signed-off-by: Zhang Wei zhangwei555@huawei.com

I need this function for doing docker stats integration test, because docker stats use HumanSize to format byte into human readable string, now I need to revert the string to byte number. But FromHumanSize can't interpret 23.3 kB, so this commit add float64 support.

I also add the blank support but it doesn't matter if you don't like it.

I think you may have special considerations for only supporting int64, but I'm not sure what's it. I can make relevant change based on your ideas. Ping @calavera

calavera commented 8 years ago

LGTM

WeiZhang555 commented 8 years ago

@calavera Can we have another one's eye on this? So that we can move forward, my integration tests still count on it. Thank you :smile:

calavera commented 8 years ago

Merging, thanks!