diff --git a/library/core/README.md b/library/core/README.md index 1166131..1b04fee 100644 --- a/library/core/README.md +++ b/library/core/README.md @@ -24,7 +24,10 @@ fun main() { val outN = LineBreakOutFeed(interval = 64, resetOnFlush = false, out) Base64.Default.newEncoderFeed(outN).use { feed -> - // Encode UTF-8 bytes to base64 + // Encode UTF-8 bytes then pipe through base64 feed. + // + // Syntax "decode" is weird b/c extension comes from + // module :core, and UTF-8 is a byte encoding, so... "Hello World 1!".decodeToByteArray(UTF8).forEach(feed::consume) feed.flush() // Finalize first encoding to reuse the Feed outN.output('.') // Add a separator or something. @@ -35,9 +38,12 @@ fun main() { println(encoded) // SGVsbG8gV29ybGQgMSE=.SGVsbG8gV29ybGQgMiE= //// Decoder.Feed example //// - val decoded = StringBuilder() - UTF8.newEncoderFeed(decoded::append).use { feedUTF8 -> + // Helper function for resetting & back-filling StringBuilder's + // backing array (only sets to 0 on Kotlin/Js, does not back-fill) + sb.wipe() + + UTF8.newEncoderFeed(sb::append).use { feedUTF8 -> // As the base64 decoder outputs decoded bytes, pipe them through // the UTF8 "encoder" feed (i.e. UTF-8 byte to text transform), @@ -51,14 +57,14 @@ fun main() { } // << `Feed.use` extension function will call Feed.doFinal automatically } // << `Feed.use` extension function will call Feed.doFinal automatically - println(decoded.toString()) // Hello World 1!Hello World 2! + println(sb.toString()) // Hello World 1!Hello World 2! //// Decoder decodeBuffered/decodeBufferedAsync examples /// // Write UTF-8 encoded bytes to a FileStream (kmp-file:file) val file = "/path/to/file.txt".toFile() file.openWrite(excl = null).use { stream -> - decoded.decodeBuffered( + sb.decodeBuffered( decoder = UTF8, throwOnOverflow = false, action = stream::write, @@ -70,7 +76,7 @@ fun main() { AsyncFs.Default.with { file.openAppendAsync(excl = OpenExcl.MustExist) .useAsync { stream -> - decoded.decodeBufferedAsync( + sb.decodeBufferedAsync( decoder = UTF8.ThrowOnInvalid, throwOnOverflow = false, maxBufSize = 1024, diff --git a/library/core/api/core.api b/library/core/api/core.api index 503811a..3019553 100644 --- a/library/core/api/core.api +++ b/library/core/api/core.api @@ -1,8 +1,6 @@ public abstract class io/matthewnelson/encoding/core/Decoder { public static final field Companion Lio/matthewnelson/encoding/core/Decoder$Companion; public synthetic fun (Lio/matthewnelson/encoding/core/EncoderDecoder$Config;Lkotlin/jvm/internal/DefaultConstructorMarker;)V - public static final fun decodeBuffered (Ljava/lang/CharSequence;ILio/matthewnelson/encoding/core/Decoder;Lkotlin/jvm/functions/Function3;)J - public static final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;Lkotlin/jvm/functions/Function3;)J public static final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZIIILkotlin/jvm/functions/Function3;)J public static final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZIILkotlin/jvm/functions/Function3;)J public static final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZII[BLkotlin/jvm/functions/Function3;)J @@ -15,8 +13,6 @@ public abstract class io/matthewnelson/encoding/core/Decoder { public static final fun decodeBuffered ([CLio/matthewnelson/encoding/core/Decoder;ZILkotlin/jvm/functions/Function3;)J public static final fun decodeBuffered ([CLio/matthewnelson/encoding/core/Decoder;ZLkotlin/jvm/functions/Function3;)J public static final fun decodeBuffered ([CLio/matthewnelson/encoding/core/Decoder;Z[BLkotlin/jvm/functions/Function3;)J - public static final fun decodeBufferedAsync (Ljava/lang/CharSequence;ILio/matthewnelson/encoding/core/Decoder;Lkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public static final fun decodeBufferedAsync (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;Lkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun decodeBufferedAsync (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZIIILkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun decodeBufferedAsync (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZIILkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun decodeBufferedAsync (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZII[BLkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -45,8 +41,6 @@ public abstract class io/matthewnelson/encoding/core/Decoder { } public final class io/matthewnelson/encoding/core/Decoder$Companion { - public final fun decodeBuffered (Ljava/lang/CharSequence;ILio/matthewnelson/encoding/core/Decoder;Lkotlin/jvm/functions/Function3;)J - public final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;Lkotlin/jvm/functions/Function3;)J public final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZIIILkotlin/jvm/functions/Function3;)J public final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZIILkotlin/jvm/functions/Function3;)J public final fun decodeBuffered (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZII[BLkotlin/jvm/functions/Function3;)J @@ -59,8 +53,6 @@ public final class io/matthewnelson/encoding/core/Decoder$Companion { public final fun decodeBuffered ([CLio/matthewnelson/encoding/core/Decoder;ZILkotlin/jvm/functions/Function3;)J public final fun decodeBuffered ([CLio/matthewnelson/encoding/core/Decoder;ZLkotlin/jvm/functions/Function3;)J public final fun decodeBuffered ([CLio/matthewnelson/encoding/core/Decoder;Z[BLkotlin/jvm/functions/Function3;)J - public final fun decodeBufferedAsync (Ljava/lang/CharSequence;ILio/matthewnelson/encoding/core/Decoder;Lkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public final fun decodeBufferedAsync (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;Lkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun decodeBufferedAsync (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZIIILkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun decodeBufferedAsync (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZIILkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun decodeBufferedAsync (Ljava/lang/CharSequence;Lio/matthewnelson/encoding/core/Decoder;ZII[BLkotlin/jvm/functions/Function4;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; diff --git a/library/core/api/core.klib.api b/library/core/api/core.klib.api index ba462a8..2953649 100644 --- a/library/core/api/core.klib.api +++ b/library/core/api/core.klib.api @@ -235,7 +235,6 @@ sealed class <#A: io.matthewnelson.encoding.core/EncoderDecoder.Config> io.matth final fun (kotlin/CharSequence).decodeBuffered(io.matthewnelson.encoding.core/Decoder<*>, kotlin/Boolean, kotlin/Int, kotlin/Function3): kotlin/Long // io.matthewnelson.encoding.core/Decoder.Companion.decodeBuffered|decodeBuffered@kotlin.CharSequence(io.matthewnelson.encoding.core.Decoder<*>;kotlin.Boolean;kotlin.Int;kotlin.Function3){}[0] final fun (kotlin/CharSequence).decodeBuffered(io.matthewnelson.encoding.core/Decoder<*>, kotlin/Boolean, kotlin/Int, kotlin/Int, kotlin/ByteArray, kotlin/Function3): kotlin/Long // io.matthewnelson.encoding.core/Decoder.Companion.decodeBuffered|decodeBuffered@kotlin.CharSequence(io.matthewnelson.encoding.core.Decoder<*>;kotlin.Boolean;kotlin.Int;kotlin.Int;kotlin.ByteArray;kotlin.Function3){}[0] final fun (kotlin/CharSequence).decodeBuffered(io.matthewnelson.encoding.core/Decoder<*>, kotlin/Boolean, kotlin/Int, kotlin/Int, kotlin/Int, kotlin/Function3): kotlin/Long // io.matthewnelson.encoding.core/Decoder.Companion.decodeBuffered|decodeBuffered@kotlin.CharSequence(io.matthewnelson.encoding.core.Decoder<*>;kotlin.Boolean;kotlin.Int;kotlin.Int;kotlin.Int;kotlin.Function3){}[0] - final fun (kotlin/CharSequence).decodeBuffered(kotlin/Int, io.matthewnelson.encoding.core/Decoder<*>, kotlin/Function3): kotlin/Long // io.matthewnelson.encoding.core/Decoder.Companion.decodeBuffered|decodeBuffered@kotlin.CharSequence(kotlin.Int;io.matthewnelson.encoding.core.Decoder<*>;kotlin.Function3){}[0] final fun (kotlin/CharSequence).decodeToByteArray(io.matthewnelson.encoding.core/Decoder<*>): kotlin/ByteArray // io.matthewnelson.encoding.core/Decoder.Companion.decodeToByteArray|decodeToByteArray@kotlin.CharSequence(io.matthewnelson.encoding.core.Decoder<*>){}[0] final fun (kotlin/CharSequence).decodeToByteArray(io.matthewnelson.encoding.core/Decoder<*>, kotlin/Int, kotlin/Int): kotlin/ByteArray // io.matthewnelson.encoding.core/Decoder.Companion.decodeToByteArray|decodeToByteArray@kotlin.CharSequence(io.matthewnelson.encoding.core.Decoder<*>;kotlin.Int;kotlin.Int){}[0] final fun (kotlin/CharSequence).decodeToByteArrayOrNull(io.matthewnelson.encoding.core/Decoder<*>): kotlin/ByteArray? // io.matthewnelson.encoding.core/Decoder.Companion.decodeToByteArrayOrNull|decodeToByteArrayOrNull@kotlin.CharSequence(io.matthewnelson.encoding.core.Decoder<*>){}[0] @@ -244,7 +243,6 @@ sealed class <#A: io.matthewnelson.encoding.core/EncoderDecoder.Config> io.matth final inline fun (kotlin/CharArray).decodeBuffered(io.matthewnelson.encoding.core/Decoder<*>, kotlin/Boolean, noinline kotlin/Function3): kotlin/Long // io.matthewnelson.encoding.core/Decoder.Companion.decodeBuffered|decodeBuffered@kotlin.CharArray(io.matthewnelson.encoding.core.Decoder<*>;kotlin.Boolean;kotlin.Function3){}[0] final inline fun (kotlin/CharSequence).decodeBuffered(io.matthewnelson.encoding.core/Decoder<*>, kotlin/Boolean, kotlin/Int, kotlin/Int, noinline kotlin/Function3): kotlin/Long // io.matthewnelson.encoding.core/Decoder.Companion.decodeBuffered|decodeBuffered@kotlin.CharSequence(io.matthewnelson.encoding.core.Decoder<*>;kotlin.Boolean;kotlin.Int;kotlin.Int;kotlin.Function3){}[0] final inline fun (kotlin/CharSequence).decodeBuffered(io.matthewnelson.encoding.core/Decoder<*>, kotlin/Boolean, noinline kotlin/Function3): kotlin/Long // io.matthewnelson.encoding.core/Decoder.Companion.decodeBuffered|decodeBuffered@kotlin.CharSequence(io.matthewnelson.encoding.core.Decoder<*>;kotlin.Boolean;kotlin.Function3){}[0] - final inline fun (kotlin/CharSequence).decodeBuffered(io.matthewnelson.encoding.core/Decoder<*>, noinline kotlin/Function3): kotlin/Long // io.matthewnelson.encoding.core/Decoder.Companion.decodeBuffered|decodeBuffered@kotlin.CharSequence(io.matthewnelson.encoding.core.Decoder<*>;kotlin.Function3){}[0] final suspend fun (kotlin/CharArray).decodeBufferedAsync(io.matthewnelson.encoding.core/Decoder<*>, kotlin/Boolean, kotlin/ByteArray, kotlin.coroutines/SuspendFunction3): kotlin/Long // io.matthewnelson.encoding.core/Decoder.Companion.decodeBufferedAsync|decodeBufferedAsync@kotlin.CharArray(io.matthewnelson.encoding.core.Decoder<*>;kotlin.Boolean;kotlin.ByteArray;kotlin.coroutines.SuspendFunction3){}[0] final suspend fun (kotlin/CharArray).decodeBufferedAsync(io.matthewnelson.encoding.core/Decoder<*>, kotlin/Boolean, kotlin/Int, kotlin.coroutines/SuspendFunction3): kotlin/Long // io.matthewnelson.encoding.core/Decoder.Companion.decodeBufferedAsync|decodeBufferedAsync@kotlin.CharArray(io.matthewnelson.encoding.core.Decoder<*>;kotlin.Boolean;kotlin.Int;kotlin.coroutines.SuspendFunction3){}[0] final suspend fun (kotlin/CharArray).decodeBufferedAsync(io.matthewnelson.encoding.core/Decoder<*>, kotlin/Boolean, kotlin/Int, kotlin/Int, kotlin/ByteArray, kotlin.coroutines/SuspendFunction3): kotlin/Long // io.matthewnelson.encoding.core/Decoder.Companion.decodeBufferedAsync|decodeBufferedAsync@kotlin.CharArray(io.matthewnelson.encoding.core.Decoder<*>;kotlin.Boolean;kotlin.Int;kotlin.Int;kotlin.ByteArray;kotlin.coroutines.SuspendFunction3){}[0] @@ -253,12 +251,10 @@ sealed class <#A: io.matthewnelson.encoding.core/EncoderDecoder.Config> io.matth final suspend fun (kotlin/CharSequence).decodeBufferedAsync(io.matthewnelson.encoding.core/Decoder<*>, kotlin/Boolean, kotlin/Int, kotlin.coroutines/SuspendFunction3): kotlin/Long // io.matthewnelson.encoding.core/Decoder.Companion.decodeBufferedAsync|decodeBufferedAsync@kotlin.CharSequence(io.matthewnelson.encoding.core.Decoder<*>;kotlin.Boolean;kotlin.Int;kotlin.coroutines.SuspendFunction3){}[0] final suspend fun (kotlin/CharSequence).decodeBufferedAsync(io.matthewnelson.encoding.core/Decoder<*>, kotlin/Boolean, kotlin/Int, kotlin/Int, kotlin/ByteArray, kotlin.coroutines/SuspendFunction3): kotlin/Long // io.matthewnelson.encoding.core/Decoder.Companion.decodeBufferedAsync|decodeBufferedAsync@kotlin.CharSequence(io.matthewnelson.encoding.core.Decoder<*>;kotlin.Boolean;kotlin.Int;kotlin.Int;kotlin.ByteArray;kotlin.coroutines.SuspendFunction3){}[0] final suspend fun (kotlin/CharSequence).decodeBufferedAsync(io.matthewnelson.encoding.core/Decoder<*>, kotlin/Boolean, kotlin/Int, kotlin/Int, kotlin/Int, kotlin.coroutines/SuspendFunction3): kotlin/Long // io.matthewnelson.encoding.core/Decoder.Companion.decodeBufferedAsync|decodeBufferedAsync@kotlin.CharSequence(io.matthewnelson.encoding.core.Decoder<*>;kotlin.Boolean;kotlin.Int;kotlin.Int;kotlin.Int;kotlin.coroutines.SuspendFunction3){}[0] - final suspend fun (kotlin/CharSequence).decodeBufferedAsync(kotlin/Int, io.matthewnelson.encoding.core/Decoder<*>, kotlin.coroutines/SuspendFunction3): kotlin/Long // io.matthewnelson.encoding.core/Decoder.Companion.decodeBufferedAsync|decodeBufferedAsync@kotlin.CharSequence(kotlin.Int;io.matthewnelson.encoding.core.Decoder<*>;kotlin.coroutines.SuspendFunction3){}[0] final suspend inline fun (kotlin/CharArray).decodeBufferedAsync(io.matthewnelson.encoding.core/Decoder<*>, kotlin/Boolean, kotlin/Int, kotlin/Int, noinline kotlin.coroutines/SuspendFunction3): kotlin/Long // io.matthewnelson.encoding.core/Decoder.Companion.decodeBufferedAsync|decodeBufferedAsync@kotlin.CharArray(io.matthewnelson.encoding.core.Decoder<*>;kotlin.Boolean;kotlin.Int;kotlin.Int;kotlin.coroutines.SuspendFunction3){}[0] final suspend inline fun (kotlin/CharArray).decodeBufferedAsync(io.matthewnelson.encoding.core/Decoder<*>, kotlin/Boolean, noinline kotlin.coroutines/SuspendFunction3): kotlin/Long // io.matthewnelson.encoding.core/Decoder.Companion.decodeBufferedAsync|decodeBufferedAsync@kotlin.CharArray(io.matthewnelson.encoding.core.Decoder<*>;kotlin.Boolean;kotlin.coroutines.SuspendFunction3){}[0] final suspend inline fun (kotlin/CharSequence).decodeBufferedAsync(io.matthewnelson.encoding.core/Decoder<*>, kotlin/Boolean, kotlin/Int, kotlin/Int, noinline kotlin.coroutines/SuspendFunction3): kotlin/Long // io.matthewnelson.encoding.core/Decoder.Companion.decodeBufferedAsync|decodeBufferedAsync@kotlin.CharSequence(io.matthewnelson.encoding.core.Decoder<*>;kotlin.Boolean;kotlin.Int;kotlin.Int;kotlin.coroutines.SuspendFunction3){}[0] final suspend inline fun (kotlin/CharSequence).decodeBufferedAsync(io.matthewnelson.encoding.core/Decoder<*>, kotlin/Boolean, noinline kotlin.coroutines/SuspendFunction3): kotlin/Long // io.matthewnelson.encoding.core/Decoder.Companion.decodeBufferedAsync|decodeBufferedAsync@kotlin.CharSequence(io.matthewnelson.encoding.core.Decoder<*>;kotlin.Boolean;kotlin.coroutines.SuspendFunction3){}[0] - final suspend inline fun (kotlin/CharSequence).decodeBufferedAsync(io.matthewnelson.encoding.core/Decoder<*>, noinline kotlin.coroutines/SuspendFunction3): kotlin/Long // io.matthewnelson.encoding.core/Decoder.Companion.decodeBufferedAsync|decodeBufferedAsync@kotlin.CharSequence(io.matthewnelson.encoding.core.Decoder<*>;kotlin.coroutines.SuspendFunction3){}[0] } } diff --git a/library/core/src/commonMain/kotlin/io/matthewnelson/encoding/core/Decoder.kt b/library/core/src/commonMain/kotlin/io/matthewnelson/encoding/core/Decoder.kt index fa1ac41..529c4ba 100644 --- a/library/core/src/commonMain/kotlin/io/matthewnelson/encoding/core/Decoder.kt +++ b/library/core/src/commonMain/kotlin/io/matthewnelson/encoding/core/Decoder.kt @@ -2404,68 +2404,6 @@ public sealed class Decoder(public val config: C) { _action = { _buf, _offset, _len -> action(_buf, _offset, _len) }, ) - /** - * TODO: Remove. See https://github.com/05nelsonm/encoding/issues/225 - * @suppress - * */ - @JvmStatic - @Throws(EncodingException::class) - @Deprecated( - message = "Will be removed upon 2.6.0 release", - replaceWith = ReplaceWith("decodeBuffered(decoder, false, action)") - ) - public inline fun CharSequence.decodeBuffered( - decoder: Decoder<*>, - noinline action: (buf: ByteArray, offset: Int, len: Int) -> Unit, - ): Long = decodeBuffered(decoder, false, DEFAULT_BUFFER_SIZE, action) - - /** - * TODO: Remove. See https://github.com/05nelsonm/encoding/issues/225 - * @suppress - * */ - @JvmStatic - @Throws(EncodingException::class) - @Deprecated( - message = "Will be removed upon 2.6.0 release", - replaceWith = ReplaceWith("decodeBuffered(decoder, false, maxBufSize, action)") - ) - public fun CharSequence.decodeBuffered( - maxBufSize: Int, - decoder: Decoder<*>, - action: (buf: ByteArray, offset: Int, len: Int) -> Unit, - ): Long = decodeBuffered(decoder, false, maxBufSize, action) - - /** - * TODO: Remove. See https://github.com/05nelsonm/encoding/issues/225 - * @suppress - * */ - @JvmStatic - @Throws(CancellationException::class, EncodingException::class) - @Deprecated( - message = "Will be removed upon 2.6.0 release", - replaceWith = ReplaceWith("decodeBufferedAsync(decoder, false, action)") - ) - public suspend inline fun CharSequence.decodeBufferedAsync( - decoder: Decoder<*>, - noinline action: suspend (buf: ByteArray, offset: Int, len: Int) -> Unit, - ): Long = decodeBufferedAsync(decoder, false, DEFAULT_BUFFER_SIZE, action) - - /** - * TODO: Remove. See https://github.com/05nelsonm/encoding/issues/225 - * @suppress - * */ - @JvmStatic - @Throws(CancellationException::class, EncodingException::class) - @Deprecated( - message = "Will be removed upon 2.6.0 release", - replaceWith = ReplaceWith("decodeBufferedAsync(decoder, false, maxBufSize, action)") - ) - public suspend fun CharSequence.decodeBufferedAsync( - maxBufSize: Int, - decoder: Decoder<*>, - action: suspend (buf: ByteArray, offset: Int, len: Int) -> Unit, - ): Long = decodeBufferedAsync(decoder, false, maxBufSize, action) - /** * DEPRECATED since `2.3.0` * @throws [EncodingException] If decoding failed, such as the [decoder] rejecting