small improvements

This commit is contained in:
Sergey Chernov 2025-03-08 02:04:18 +03:00
parent 38751b5df6
commit 6ea003700f
2 changed files with 17 additions and 1 deletions

View File

@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
plugins { plugins {
kotlin("multiplatform") version "2.0.21" kotlin("multiplatform") version "2.0.21"
kotlin("plugin.serialization") version "2.0.21" kotlin("plugin.serialization") version "2.0.21"
@ -6,7 +8,7 @@ plugins {
} }
group = "net.sergeych" group = "net.sergeych"
version = "0.1.11" version = "0.1.12-SNAPSHOT"
repositories { repositories {
mavenCentral() mavenCentral()
@ -31,6 +33,7 @@ kotlin {
linuxArm64() linuxArm64()
mingwX64() mingwX64()
@OptIn(ExperimentalWasmDsl::class)
wasmJs { wasmJs {
browser() browser()
binaries.executable() binaries.executable()

View File

@ -1,6 +1,7 @@
package net.sergeych.bintools package net.sergeych.bintools
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import net.sergeych.mp_tools.encodeToBase64Compact
import kotlin.math.min import kotlin.math.min
import kotlin.random.Random import kotlin.random.Random
@ -64,6 +65,11 @@ class ByteChunk(val data: UByteArray): Comparable<ByteChunk> {
*/ */
val dump by lazy { data.toDump() } 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 * 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()) fun ByteArray.asChunk() = ByteChunk(this.asUByteArray())
/**
* Create the representation of this array as ByteChunk; it does not copy the data.
*/
@Suppress("unused") @Suppress("unused")
fun UByteArray.asChunk() = ByteChunk(this) fun UByteArray.asChunk() = ByteChunk(this)