Skip to content

Instantly share code, notes, and snippets.

View orispok's full-sized avatar

Ori Spokoini orispok

View GitHub Profile
@chris-hatton
chris-hatton / DataSizeFormatter.kt
Last active May 11, 2025 15:09
Human Readable Data Size Formatter for Kotlin Multiplatform (uses Common API only)
package datasizeformatter
import kotlin.math.abs
import kotlin.math.pow
import kotlin.math.roundToLong
/**
* Format a human-readable representation of data size, in binary base form.
* e.g. 1024 -> 1 KiB
* @param byteCount The number of bytes to represent in human-readable form. `Long.MIN_VALUE` is unsupported.