https://github.com/saket/byte-size
Units for representing SI and IEC bytes and bits, inspired by kotlin.time.Duration and jakewharton/byteunits.
https://github.com/saket/byte-size
Last synced: about 1 month ago
JSON representation
Units for representing SI and IEC bytes and bits, inspired by kotlin.time.Duration and jakewharton/byteunits.
- Host: GitHub
- URL: https://github.com/saket/byte-size
- Owner: saket
- License: apache-2.0
- Created: 2023-12-25T03:44:15.000Z (over 1 year ago)
- Default Branch: trunk
- Last Pushed: 2024-09-18T17:42:31.000Z (8 months ago)
- Last Synced: 2024-10-14T20:47:56.518Z (7 months ago)
- Language: Kotlin
- Homepage:
- Size: 262 KB
- Stars: 159
- Watchers: 5
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-list - saket/byte-size - Units for representing SI and IEC bytes and bits, inspired by kotlin.time.Duration and jakewharton/byteunits. (Kotlin)
README
# byte-size
```groovy
implementation "me.saket.bytesize:bytesize:2.0.0-beta04"
``````kotlin
val cacheSize = 512.megabytes
println(cacheSize.toString()) // "512 MB"
println(cacheSize.inWholeBytes) // "512000000"
println(cacheSize + 88_000.kilobytes) // "600 MB"
println(cacheSize * 2) // "1.02 GB"
println(cacheSize < 1.gigabytes) // "true"
``````kotlin
val perception = 2.gibibytes
val usable = 2.gigabytes
println("${perception - usable} lost on a 2GB drive") // "140.65 MiB lost on a 2GB drive"
```