Skip to content

Enhance FromHumanSize to parse float64 string#8

Merged
calavera merged 1 commit intodocker:masterfrom
WeiZhang555:from-human-size
Jan 25, 2016
Merged

Enhance FromHumanSize to parse float64 string#8
calavera merged 1 commit intodocker:masterfrom
WeiZhang555:from-human-size

Conversation

@WeiZhang555
Copy link
Contributor

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

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

Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be 32.5?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FromHumanSize will always return int64 instead of float64, it will truncate float64 into int64. That's because in my opinion, 32.5 B isn't meaningful, user don't need to care bit, unit as Byte is already good enough.

I was thinking to produce error for 32.5 B and only support 32.5 KB or MB etc, but it will make regexp complicated, so I didn't do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And there's some other situations, for example, 32.5634663 kB which is 32563.4663 B which is not meaningful, and it's hard to detect this format.
But I really need FromHumanSize to support parsing float64, because you know HumanSize will print 32.56 kB, I need this FromHumanSize to reverse the result.

So I think if we can't stop unmeaning input, we can still give meaningful output as some programming languages do.

@calavera
Copy link
Contributor

LGTM

@WeiZhang555
Copy link
Contributor Author

@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 😄

@calavera
Copy link
Contributor

Merging, thanks!

calavera added a commit that referenced this pull request Jan 25, 2016
Enhance FromHumanSize to parse float64 string
@calavera calavera merged commit 5d2041e into docker:master Jan 25, 2016
@WeiZhang555 WeiZhang555 deleted the from-human-size branch January 26, 2016 05:31
thaJeztah added a commit to thaJeztah/runc that referenced this pull request Mar 28, 2019
relevant changes:

  - docker/go-units#8 Enhance FromHumanSize to parse float64 string
  - docker/go-units#20 Add `HumanSizeWithPrecision` function

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
thaJeztah added a commit to thaJeztah/runc that referenced this pull request Mar 28, 2019
relevant changes:

  - docker/go-units#8 Enhance FromHumanSize to parse float64 string
  - docker/go-units#20 Add `HumanSizeWithPrecision` function

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
thaJeztah added a commit to thaJeztah/runc that referenced this pull request Apr 12, 2019
relevant changes:

  - docker/go-units#8 Enhance FromHumanSize to parse float64 string
  - docker/go-units#20 Add `HumanSizeWithPrecision` function

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
thaJeztah added a commit to thaJeztah/runc that referenced this pull request Apr 12, 2019
relevant changes:

  - docker/go-units#8 Enhance FromHumanSize to parse float64 string
  - docker/go-units#20 Add `HumanSizeWithPrecision` function

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
thaJeztah added a commit to thaJeztah/runc that referenced this pull request Apr 12, 2019
relevant changes:

  - docker/go-units#8 Enhance FromHumanSize to parse float64 string
  - docker/go-units#20 Add `HumanSizeWithPrecision` function

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
thaJeztah added a commit to thaJeztah/runc that referenced this pull request Apr 25, 2019
relevant changes:

  - docker/go-units#8 Enhance FromHumanSize to parse float64 string
  - docker/go-units#20 Add `HumanSizeWithPrecision` function

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
thaJeztah added a commit to thaJeztah/runc that referenced this pull request Jul 14, 2019
relevant changes:

  - docker/go-units#8 Enhance FromHumanSize to parse float64 string
  - docker/go-units#20 Add `HumanSizeWithPrecision` function

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
thaJeztah added a commit to thaJeztah/runc that referenced this pull request Aug 26, 2019
relevant changes:

  - docker/go-units#8 Enhance FromHumanSize to parse float64 string
  - docker/go-units#20 Add `HumanSizeWithPrecision` function

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
thaJeztah added a commit to thaJeztah/runc that referenced this pull request Sep 5, 2019
relevant changes:

  - docker/go-units#8 Enhance FromHumanSize to parse float64 string
  - docker/go-units#20 Add `HumanSizeWithPrecision` function

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
stefanberger pushed a commit to stefanberger/runc that referenced this pull request Dec 31, 2019
relevant changes:

  - docker/go-units#8 Enhance FromHumanSize to parse float64 string
  - docker/go-units#20 Add `HumanSizeWithPrecision` function

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
adrianreber pushed a commit to adrianreber/runc that referenced this pull request Feb 10, 2020
relevant changes:

  - docker/go-units#8 Enhance FromHumanSize to parse float64 string
  - docker/go-units#20 Add `HumanSizeWithPrecision` function

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants