Package-level declarations

Types

Link copied to clipboard
sealed interface CompressionAlgorithm

Compression algorithm types.

Link copied to clipboard
class CompressionException(message: String, cause: Throwable? = null) : Exception

Exception thrown when compression/decompression fails.

Link copied to clipboard
sealed interface CompressionLevel

Compression level.

Link copied to clipboard
sealed interface CompressionResult

Result of compression/decompression operations.

Link copied to clipboard

Deflate format constants.

Link copied to clipboard

Stateful streaming compressor that processes data incrementally. Useful for compressing data that arrives in chunks (e.g., from network).

Link copied to clipboard

Stateful streaming decompressor that processes data incrementally.

Link copied to clipboard

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

Link copied to clipboard

Suspending streaming decompressor for async-only platforms.

Link copied to clipboard
value class WindowBits

Log2 size of zlib's LZ77 sliding window. Pair with a CompressionAlgorithm to select the format (raw vs zlib vs gzip); this type only carries the size.

Properties

Link copied to clipboard

Whether the current platform's StreamingCompressor.create honors a non-default WindowBits argument.

Whether the current platform's StreamingCompressor.create honors a non-default WindowBits argument.

actual val supportsCustomWindowBits: Boolean = false

Whether the current platform's StreamingCompressor.create honors a non-default WindowBits argument.

Whether the current platform's StreamingCompressor.create honors a non-default WindowBits argument.

Link copied to clipboard

Whether the current platform supports raw deflate (no zlib/gzip headers).

Whether the current platform supports raw deflate (no zlib/gzip headers).

actual val supportsRawDeflate: Boolean = true

Whether the current platform supports raw deflate (no zlib/gzip headers).

actual val supportsRawDeflate: Boolean = true

Whether the current platform supports raw deflate (no zlib/gzip headers).

Link copied to clipboard

Whether the sync StreamingCompressor maintains compression state across flush() calls.

Whether the sync StreamingCompressor maintains compression state across flush() calls.

actual val supportsStatefulFlush: Boolean = true

Whether the sync StreamingCompressor maintains compression state across flush() calls.

actual val supportsStatefulFlush: Boolean = true

Whether the sync StreamingCompressor maintains compression state across flush() calls.

Link copied to clipboard

Whether this platform supports the synchronous compress and decompress functions.

Shared JS/wasmJs compression implementation. Dispatches to Node.js sync APIs or returns browser-unsupported errors.

actual val supportsSyncCompression: Boolean = true

JVM/Android supports synchronous compression via java.util.zip.

actual val supportsSyncCompression: Boolean = true

Linux supports synchronous compression via system zlib.

Functions

Link copied to clipboard
expect fun compress(buffer: ReadBuffer, algorithm: CompressionAlgorithm = CompressionAlgorithm.Deflate, level: CompressionLevel = CompressionLevel.Default): CompressionResult

Compresses data from a ReadBuffer using the specified algorithm. Reads from current position to limit.

actual fun compress(buffer: ReadBuffer, algorithm: CompressionAlgorithm, level: CompressionLevel): CompressionResult

Compresses data from a ReadBuffer using the specified algorithm. Reads from current position to limit.

actual fun compress(buffer: ERROR CLASS: Symbol not found for ReadBuffer, algorithm: CompressionAlgorithm, level: CompressionLevel): CompressionResult

JVM/Android implementation delegating to streaming compression.

actual fun compress(buffer: ReadBuffer, algorithm: CompressionAlgorithm, level: CompressionLevel): CompressionResult

Linux implementation using system zlib with direct buffer access.

Link copied to clipboard
suspend fun compressAsync(buffer: ReadBuffer, algorithm: CompressionAlgorithm = CompressionAlgorithm.Gzip, level: CompressionLevel = CompressionLevel.Default, factory: BufferFactory = BufferFactory.Default): PlatformBuffer

Compresses data using the specified algorithm. Works on all platforms.

Link copied to clipboard
suspend fun compressWithSyncFlush(buffer: ReadBuffer, level: CompressionLevel = CompressionLevel.Default, factory: BufferFactory = BufferFactory.Default): ReadBuffer

Compresses data using Z_SYNC_FLUSH and strips the sync marker.

Link copied to clipboard
expect fun SuspendingStreamingDecompressor.Companion.create(algorithm: CompressionAlgorithm = CompressionAlgorithm.Deflate, bufferFactory: BufferFactory = BufferFactory.Default): SuspendingStreamingDecompressor

Creates a suspending streaming decompressor.

expect fun SuspendingStreamingCompressor.Companion.create(algorithm: CompressionAlgorithm = CompressionAlgorithm.Deflate, level: CompressionLevel = CompressionLevel.Default, bufferFactory: BufferFactory = BufferFactory.Default): SuspendingStreamingCompressor

Creates a suspending streaming compressor. Required for browser JavaScript which only supports async CompressionStream.

expect fun StreamingDecompressor.Companion.create(algorithm: CompressionAlgorithm = CompressionAlgorithm.Deflate, bufferFactory: BufferFactory = BufferFactory.Default, outputBufferSize: Int = 32768, expectedSize: Int = 0): StreamingDecompressor

Creates a streaming decompressor.

expect fun StreamingCompressor.Companion.create(algorithm: CompressionAlgorithm = CompressionAlgorithm.Deflate, level: CompressionLevel = CompressionLevel.Default, bufferFactory: BufferFactory = BufferFactory.Default, outputBufferSize: Int = 32768, windowBits: WindowBits = WindowBits.Default): StreamingCompressor

Creates a streaming compressor.

Creates a suspending streaming decompressor.

Creates a suspending streaming compressor. Required for browser JavaScript which only supports async CompressionStream.

actual fun StreamingDecompressor.Companion.create(algorithm: CompressionAlgorithm, bufferFactory: BufferFactory, outputBufferSize: Int, expectedSize: Int): StreamingDecompressor

Creates a streaming decompressor.

actual fun StreamingCompressor.Companion.create(algorithm: CompressionAlgorithm, level: CompressionLevel, bufferFactory: BufferFactory, outputBufferSize: Int, windowBits: WindowBits): StreamingCompressor

Creates a streaming compressor.

actual fun SuspendingStreamingDecompressor.Companion.create(algorithm: CompressionAlgorithm, bufferFactory: ERROR CLASS: Symbol not found for BufferFactory): SuspendingStreamingDecompressor
actual fun SuspendingStreamingCompressor.Companion.create(algorithm: CompressionAlgorithm, level: CompressionLevel, bufferFactory: ERROR CLASS: Symbol not found for BufferFactory): SuspendingStreamingCompressor
actual fun StreamingDecompressor.Companion.create(algorithm: CompressionAlgorithm, bufferFactory: ERROR CLASS: Symbol not found for BufferFactory, outputBufferSize: Int, expectedSize: Int): StreamingDecompressor
actual fun StreamingCompressor.Companion.create(algorithm: CompressionAlgorithm, level: CompressionLevel, bufferFactory: ERROR CLASS: Symbol not found for BufferFactory, outputBufferSize: Int, windowBits: WindowBits): StreamingCompressor
actual fun SuspendingStreamingDecompressor.Companion.create(algorithm: CompressionAlgorithm, bufferFactory: BufferFactory): SuspendingStreamingDecompressor

Creates a suspending streaming decompressor.

actual fun SuspendingStreamingCompressor.Companion.create(algorithm: CompressionAlgorithm, level: CompressionLevel, bufferFactory: BufferFactory): SuspendingStreamingCompressor

Creates a suspending streaming compressor. Required for browser JavaScript which only supports async CompressionStream.

actual fun StreamingDecompressor.Companion.create(algorithm: CompressionAlgorithm, bufferFactory: BufferFactory, outputBufferSize: Int, expectedSize: Int): StreamingDecompressor

Linux streaming decompressor factory using z_stream for true incremental decompression.

actual fun StreamingCompressor.Companion.create(algorithm: CompressionAlgorithm, level: CompressionLevel, bufferFactory: BufferFactory, outputBufferSize: Int, windowBits: WindowBits): StreamingCompressor

Linux streaming compressor factory using z_stream for true incremental compression.

Link copied to clipboard
expect fun decompress(buffer: ReadBuffer, algorithm: CompressionAlgorithm = CompressionAlgorithm.Deflate): CompressionResult

Decompresses data from a ReadBuffer using the specified algorithm. Reads from current position to limit.

actual fun decompress(buffer: ReadBuffer, algorithm: CompressionAlgorithm): CompressionResult

Decompresses data from a ReadBuffer using the specified algorithm. Reads from current position to limit.

actual fun decompress(buffer: ERROR CLASS: Symbol not found for ReadBuffer, algorithm: CompressionAlgorithm): CompressionResult
actual fun decompress(buffer: ReadBuffer, algorithm: CompressionAlgorithm): CompressionResult

Decompresses data from a ReadBuffer using the specified algorithm. Reads from current position to limit.

Link copied to clipboard
fun StreamProcessorBuilder.decompress(algorithm: CompressionAlgorithm = CompressionAlgorithm.Gzip, bufferFactory: BufferFactory = pool): StreamProcessorBuilder

Adds decompression to the StreamProcessor pipeline.

Link copied to clipboard
suspend fun decompressAsync(buffer: ReadBuffer, algorithm: CompressionAlgorithm = CompressionAlgorithm.Gzip, factory: BufferFactory = BufferFactory.Default, expectedOutputSize: Int = 0): PlatformBuffer

Decompresses data using the specified algorithm. Works on all platforms.

Link copied to clipboard
suspend fun decompressWithSyncFlush(buffer: ReadBuffer, factory: BufferFactory = BufferFactory.Default): ReadBuffer

Decompresses data that was compressed with compressWithSyncFlush.

Link copied to clipboard
fun CompressionResult.getOrNull(): PlatformBuffer?

Extension function to get buffer from CompressionResult, returning null on failure.

Link copied to clipboard
fun CompressionResult.getOrThrow(): PlatformBuffer

Extension function to get buffer from CompressionResult, throwing on failure.

Link copied to clipboard
fun ReadBuffer.stripSyncFlushMarker(): ReadBuffer

Strips the Z_SYNC_FLUSH marker (00 00 FF FF) from the end of compressed data.

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).

inline suspend fun <R> SuspendingStreamingDecompressor.use(block: (decompress: suspend (ReadBuffer) -> List<ReadBuffer>) -> R): R
inline fun <R> StreamingDecompressor.use(noinline onOutput: (ReadBuffer) -> Unit, block: (decompress: (ReadBuffer) -> Unit) -> R): R

Convenience function that handles decompress, finish, and close automatically.

inline fun <R> StreamingCompressor.use(noinline onOutput: (ReadBuffer) -> Unit, block: (compress: (ReadBuffer) -> Unit) -> R): R

Convenience function that handles compress, finish, and close automatically. All output chunks (from both compress and finish) go to the same callback.

Link copied to clipboard
inline suspend fun <R> StreamingCompressor.useSuspending(noinline onOutput: (ReadBuffer) -> Unit, block: suspend (compress: (ReadBuffer) -> Unit) -> R): R

Suspending version of use for use with suspending I/O. Uses the efficient synchronous compressor but allows suspend calls in the block.

inline suspend fun <R> StreamingDecompressor.useSuspending(noinline onOutput: (ReadBuffer) -> Unit, block: suspend (decompress: (ReadBuffer) -> Unit) -> R): R

Suspending version of use for use with suspending I/O.