@@ -6,11 +6,6 @@ package aws.smithy.kotlin.runtime.compression
66
77import aws.sdk.kotlin.crt.Closeable
88import aws.smithy.kotlin.runtime.io.SdkBuffer
9- import aws.smithy.kotlin.runtime.io.SdkByteChannel
10- import aws.smithy.kotlin.runtime.io.readFully
11- import aws.smithy.kotlin.runtime.io.readToByteArray
12- import aws.smithy.kotlin.runtime.io.use
13- import aws.smithy.kotlin.runtime.io.write
149import kotlinx.cinterop.*
1510import platform.zlib.*
1611
@@ -27,11 +22,11 @@ internal class GzipCompressor : Closeable {
2722 }
2823
2924 private val stream = nativeHeap.alloc< z_stream> ()
30- private val outputBuffer = SdkByteChannel ()
25+ private val outputBuffer = SdkBuffer ()
3126 internal var isClosed = false
3227
3328 internal val availableForRead: Int
34- get() = outputBuffer.availableForRead
29+ get() = outputBuffer.size.toInt()
3530
3631 init {
3732 // Initialize deflate with gzip encoding
@@ -52,7 +47,7 @@ internal class GzipCompressor : Closeable {
5247 /* *
5348 * Update the compressor with [input] bytes
5449 */
55- suspend fun update (input : ByteArray ) = memScoped {
50+ fun update (input : ByteArray ) = memScoped {
5651 check(! isClosed) { " Compressor is closed" }
5752
5853 val inputPin = input.pin()
@@ -82,22 +77,19 @@ internal class GzipCompressor : Closeable {
8277 /* *
8378 * Consume [count] gzip-compressed bytes.
8479 */
85- suspend fun consume (count : Int ): ByteArray {
80+ fun consume (count : Int ): ByteArray {
8681 check(! isClosed) { " Compressor is closed" }
8782 require(count in 0 .. availableForRead) {
8883 " Count must be between 0 and $availableForRead , got $count "
8984 }
9085
91- return SdkBuffer ().use {
92- outputBuffer.readFully(it, count.toLong())
93- it.readToByteArray()
94- }
86+ return outputBuffer.readByteArray(count.toLong())
9587 }
9688
9789 /* *
9890 * Flush the compressor and return the terminal sequence of bytes that represent the end of the gzip compression.
9991 */
100- suspend fun flush (): ByteArray {
92+ fun flush (): ByteArray {
10193 check(! isClosed) { " Compressor is closed" }
10294
10395 memScoped {
@@ -120,10 +112,7 @@ internal class GzipCompressor : Closeable {
120112 outputPin.unpin()
121113 } while (deflateResult != Z_STREAM_END )
122114
123- return SdkBuffer ().use {
124- outputBuffer.readFully(it, outputLength)
125- it.readByteArray()
126- }
115+ return outputBuffer.readByteArray(outputLength)
127116 }
128117 }
129118
0 commit comments