file-size icon indicating copy to clipboard operation
file-size copied to clipboard

Parse string

Open nillpoe opened this issue 1 month ago • 4 comments

reverse

https://github.com/saket/byte-size/blob/3abe56bb60fc91e31c4443b7c4c381e4fa7773b7/library/src/commonMain/kotlin/me/saket/bytesize/BinaryByteSize.kt#L79-L91

nillpoe avatar Nov 04 '25 18:11 nillpoe

I'm sorry, but byte-size is focused on doing one thing well: representing and formatting byte sizes. Adding parsing would expand the scope significantly and invite many edge case requests.

What's your use case?

saket avatar Nov 04 '25 19:11 saket

in configurations, something like:

avatars:
    size-limit: 1MB

nillpoe avatar Nov 04 '25 20:11 nillpoe

we can refer to Duration.kt.

https://github.com/JetBrains/kotlin/blob/dd0262b0a119245bb666a48919211cd3da77f45c/libraries/stdlib/src/kotlin/time/Duration.kt#L1023-L1246

nillpoe avatar Nov 04 '25 20:11 nillpoe

Your example would fail to parse, though. And would yield 1,000,000 bytes instead of 1,048,576 bytes which I'm not sure this person would expect or not.

Parsing is a delicate thing. Some people want it to be strict, others lenient (such as allowing no space), and others still want it to parse to what they meant not what they necessarily said (such as in the case of MB vs. MiB).

JakeWharton avatar Nov 04 '25 22:11 JakeWharton