Skip to content

czoeller/kbytes

Repository files navigation

kbytes

Tiny, fluent Kotlin DSL for working with byte counts using binary (IEC) and decimal units.

Features

  • Inline StorageSize value type with arithmetic and comparisons.
  • Binary (KiB, MiB, …) and decimal (KB, MB, …) extensions on Int/Long.
  • Converters for byte counts and Path sizes (toStorageSize()).

Gradle setup

  1. Add Maven Central in your settings.gradle.kts:
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        mavenCentral()
    }
}
  1. 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.

Usage

val size = 3.GB + 512.MB          // arithmetic
println(size.bestDecimalUnit())   // Sized(value=3.512, unit=GB)

val fileSize = somePath.toStorageSize()
println(fileSize.inBytes())

About

Tiny, fluent Kotlin DSL for working with byte counts using binary (IEC) and decimal units.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages