diff --git a/runtime/runtime-core/api/runtime-core.api b/runtime/runtime-core/api/runtime-core.api index 0e8f85de3a..e488735251 100644 --- a/runtime/runtime-core/api/runtime-core.api +++ b/runtime/runtime-core/api/runtime-core.api @@ -1097,6 +1097,7 @@ public abstract interface class aws/smithy/kotlin/runtime/io/SdkSource : java/io public final class aws/smithy/kotlin/runtime/io/SdkSourceKt { public static final fun readFully (Laws/smithy/kotlin/runtime/io/SdkSource;Laws/smithy/kotlin/runtime/io/SdkBuffer;J)V + public static final fun readRemaining (Laws/smithy/kotlin/runtime/io/SdkSource;Laws/smithy/kotlin/runtime/io/SdkBuffer;)J public static final fun readToByteArray (Laws/smithy/kotlin/runtime/io/SdkSource;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun toSdkByteReadChannel (Laws/smithy/kotlin/runtime/io/SdkSource;Lkotlinx/coroutines/CoroutineScope;)Laws/smithy/kotlin/runtime/io/SdkByteReadChannel; public static synthetic fun toSdkByteReadChannel$default (Laws/smithy/kotlin/runtime/io/SdkSource;Lkotlinx/coroutines/CoroutineScope;ILjava/lang/Object;)Laws/smithy/kotlin/runtime/io/SdkByteReadChannel; diff --git a/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/io/SdkSource.kt b/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/io/SdkSource.kt index aefb75dc08..4aa8e9fc4c 100644 --- a/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/io/SdkSource.kt +++ b/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/io/SdkSource.kt @@ -110,3 +110,23 @@ public fun SdkSource.readFully(sink: SdkBuffer, byteCount: Long) { totalBytesRead += rc } } + +/** + * **Caution** Reads the entire contents of the source into [sink]. + * This function will read until the source is exhausted and no bytes remain + * + * @param sink the buffer that data read from the source will be appended to + */ +@InternalApi +public fun SdkSource.readRemaining(sink: SdkBuffer): Long { + var totalReadBytes: Long = 0 + var readBytes: Long + + do { + // ensure any errors are propagated by attempting to read at least once + readBytes = read(sink, Long.MAX_VALUE) + totalReadBytes += readBytes + } while (readBytes != -1L) + + return totalReadBytes + 1L // Account for last -1 read +}