omar / ByteSize

ByteSize is a utility class that makes byte size representation in code easier by removing ambiguity of the value being represented. ByteSize is to bytes what System.TimeSpan is to time.
MIT License
558 stars 50 forks source link

Recommended way to parse legacy strings #72

Closed chadjefferies closed 1 year ago

chadjefferies commented 1 year ago

Hello and thank you for providing such a helpful library.

I am wondering if there is a recommended way of parsing legacy strings?

I don't have control over the string values but the expectation is that they should all result in the binary system's value of bytes.

So, for example, my application needs to parse strings that are formatted as such as ByteSize.Parse("4GB") but as the binary representation, so that the resulting ByteSize.Bytes field is equal to 4294967296 and not 4000000000.

There are some hacky things I can do to manipulate the string before passing it into ByteSize, but was wondering if I was missing a library feature that would enable this functionality (other than downgrading to 1.0).

Thanks!

omar commented 1 year ago

Hey @chadjefferies, I'm glad to know you're finding this library useful!

As it stands, there's no built in function to parse the strings using the 1.0 behavior. Your best bet is to manipulate the string before passing it in as you mentioned.