🎁 In case anyone finds it useful, here's a ✨ Human Readable Data Size formatting function ✨ that uses only Kotlin Multiplatform Common API's.
Just drop it into your common source set & go 😄
Other implementations I found stackoverflow either use string formatting or other functions not found in 'common Kotlin'; this gets it done with what's available.
Welcome any suggestions for improvement!
👍🏼 1
👍 7
e
ephemient
01/03/2022, 12:47 PM
Copy code
abs(Long.MIN_VALUE) < 0
blob scream 1
d
darkmoon_uk
01/03/2022, 1:27 PM
Just made it throw an error for now in that unlikely edge case; but nice pickup!
e
eygraber
01/03/2022, 4:55 PM
require(byteCount>Long.MIN_VALUE) { "Out of range" }
How would it be possible to be less than
MIN_VALUE
in the first place?
e
ephemient
01/03/2022, 5:28 PM
could be equal
ephemient
01/03/2022, 5:30 PM
I imagine it's only likely to come up if you were using it as a sentinel value, but it's definitely annoying to handle