Skip to content
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

Add FromSize method #37

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Add FromSize method #37

wants to merge 2 commits into from

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