Tiny, fluent Kotlin DSL for working with byte counts using binary (IEC) and decimal units.
- Inline
StorageSizevalue type with arithmetic and comparisons. - Binary (
KiB,MiB, …) and decimal (KB,MB, …) extensions onInt/Long. - Converters for byte counts and
Pathsizes (toStorageSize()).
- Add Maven Central in your settings.gradle.kts:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
}
}- Depend on the Maven Central artifact:
dependencies {
implementation("io.github.czoeller:kbytes:1.0.0-SNAPSHOT")
}For snapshots, add the Central Portal snapshots repository:
repositories {
maven {
name = "Central Portal Snapshots"
url = uri("https://central.sonatype.com/repository/maven-snapshots/")
content {
includeModule("io.github.czoeller", "kbytes")
}
}
mavenCentral()
}Replace 1.0.0-SNAPSHOT with the version you want.
val size = 3.GB + 512.MB // arithmetic
println(size.bestDecimalUnit()) // Sized(value=3.512, unit=GB)
val fileSize = somePath.toStorageSize()
println(fileSize.inBytes())