SuspendingStreamingCompressor

Suspending streaming compressor for async-only platforms. Browser JavaScript requires this variant since CompressionStream is async.

Usage:

val compressor = SuspendingStreamingCompressor.create()
try {
while (hasMoreData) {
val chunk = receiveChunk()
compressor.compress(chunk).forEach { send(it) }
}
compressor.finish().forEach { send(it) }
} finally {
compressor.close()
}

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
abstract val bufferFactory: BufferFactory

Functions

Link copied to clipboard
expect abstract fun close()
Link copied to clipboard
abstract suspend fun compress(input: ReadBuffer): List<ReadBuffer>

Compresses input data, returning output chunks. May return empty list if data is buffered.

Link copied to clipboard
abstract suspend fun finish(): List<ReadBuffer>

Finishes compression, returning any remaining data.

Link copied to clipboard
abstract suspend fun flush(): List<ReadBuffer>

Flushes buffered data using Z_SYNC_FLUSH, producing complete deflate blocks. Unlike finish, the stream remains open for more data.

Link copied to clipboard
abstract fun reset()

Resets the compressor for reuse.

Link copied to clipboard
inline suspend fun <R> SuspendingStreamingCompressor.use(block: (compress: suspend (ReadBuffer) -> List<ReadBuffer>) -> R): R

Convenience function that handles compress, finish, and close automatically. Returns all output chunks (from both compress and finish calls).