small improvements

This commit is contained in:
sergeych committed 2025-03-08 02:09:35 +03:00
1 parent 38751b5df6
commit 6ea003700f
2 files changed
+17 -1

No files matched your search

@@ -1,6 +1,7 @@
package net.sergeych.bintools
import kotlinx.serialization.Serializable
import net.sergeych.mp_tools.encodeToBase64Compact
import kotlin.math.min
import kotlin.random.Random
@@ -64,6 +65,11 @@ class ByteChunk(val data: UByteArray): Comparable<ByteChunk> {
*/
val dump by lazy { data.toDump() }
/**
* Lazy encode to base64 with url alphabet, without trailing fill '=' characters.
*/
val base64 by lazy { data.asByteArray().encodeToBase64Compact() }
/**
* Concatenate two chunks and return new one
*/
@@ -75,6 +81,13 @@ class ByteChunk(val data: UByteArray): Comparable<ByteChunk> {
}
}
/**
* Create the representation of this array as ByteChunk; it does not copy the data.
*/
fun ByteArray.asChunk() = ByteChunk(this.asUByteArray())
/**
* Create the representation of this array as ByteChunk; it does not copy the data.
*/
@Suppress("unused")
fun UByteArray.asChunk() = ByteChunk(this)