New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FromHumanSize accepts MiB but returns MB #31
Comments
cfergeau
added a commit
to cfergeau/go-units
that referenced
this issue
Dec 15, 2020
go-units API is missing a method which would parse "32kB" as 32000 bytes, and "32kiB" as 32768 bytes. FromHumanSize() parses both as 32000 bytes, while RAMInBytes() parses both as 32768 bytes. This commit introduces a FromSize method a more litteral parsing of the unit is needed. Modifiers without a unit ('32k') will be assumed to be using a decimal unit, so they'll equivalent to 32 kB/32000 bytes. This fixes docker#31
cfergeau
added a commit
to cfergeau/go-units
that referenced
this issue
Dec 15, 2020
go-units API is missing a method which would parse "32kB" as 32000 bytes, and "32kiB" as 32768 bytes. FromHumanSize() parses both as 32000 bytes, while RAMInBytes() parses both as 32768 bytes. This commit introduces a FromSize method a more litteral parsing of the unit is needed. Modifiers without a unit ('32k') will be assumed to be using a decimal unit, so they'll equivalent to 32 kB/32000 bytes. This fixes docker#31
Yes, this is the way it works. I think we can fix this and accept e.g. KB as "human size" (1000) and KiB as "computer size" (1024), defaulting to "human size" for "FromHumanSize" and to "computer size" for "RAMInBytes". Problem is, this will make things slightly incompatible with the current behavior. |
jadams
pushed a commit
to jadams/kali-vm
that referenced
this issue
Sep 30, 2022
It's not exactly a nitpick. debos uses github.com/docker/go-units to parse the size, and docker/go-units is fundamentally broken, as it parses both GiB anb GB as GB. It's a known issue that's been there forever, and will probably never be fixed because backward compat (that's my guess). Cf. <docker/go-units#31>, or better <docker/go-units#27 (comment)>. So let's make sure that we talk about GB, because that's what happens in practice.
jadams
pushed a commit
to jadams/kali-vm
that referenced
this issue
Sep 30, 2022
It's not exactly a nitpick. debos uses github.com/docker/go-units to parse the size, and docker/go-units is fundamentally broken, as it parses both GiB anb GB as GB. It's a known issue that's been there forever, and will probably never be fixed because backward compat (that's my guess). Cf. <docker/go-units#31>, or better <docker/go-units#27 (comment)>. So let's make sure that we talk about GB, because that's what happens in practice.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One might expect that FromHumanSize("1MiB") would either
Currently it does not raise error and returns units.MB (1000 * 1000 * 1000)
The text was updated successfully, but these errors were encountered: