kbytes

Tiny, fluent DSL handling byte quantities with binary (KiB/MiB…) and decimal (KB/MB…) units, inline StorageSize type with arithmetic, comparisons, and Path size converters.

JVM
iOS
macOS
Linux
Windows
Wasm
JS
GitHub stars0
Authorsczoeller
Dependents0
LicenseMIT License
Creation date2 months ago

Last activity25 days ago
Latest release1.2.1 (25 days ago)

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())
JVM
iOS
macOS
Linux
Windows
Wasm
JS
GitHub stars0
Authorsczoeller
Dependents0
LicenseMIT License
Creation date2 months ago

Last activity25 days ago
Latest release1.2.1 (25 days ago)

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())