Skip to content

Conversation

@cfergeau
Copy link

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 #31

Currently, the regexp will match any number of (.\d+) occurrences
because of its use of (.\d+)*. This commit changes this to (.\d+)? as
a valid decimal number will have at most one decimal part.
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
@kolyshkin
Copy link
Contributor

This functionality would be very nice to have indeed.

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.

FromHumanSize accepts MiB but returns MB

2 participants