Package-level declarations

Types

Link copied to clipboard
sealed interface BufferAllocator

Strategy for allocating buffers during compression/decompression. Allows control over memory allocation to optimize for different use cases.

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.

Properties

Link copied to clipboard

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

actual val supportsRawDeflate: Boolean = true
actual val supportsRawDeflate: Boolean = true
Link copied to clipboard

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

actual val supportsStatefulFlush: Boolean = false

Whether the sync StreamingCompressor maintains dictionary across flush() calls.

actual val supportsStatefulFlush: Boolean = true
actual val supportsStatefulFlush: Boolean = true
Link copied to clipboard

Whether this platform supports the synchronous compress and decompress functions.

JS supports synchronous compression only in Node.js via native zlib module. Browser only has async CompressionStream API - use SuspendingStreamingCompressor instead.

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

JS implementation using native Node.js zlib. Browser throws UnsupportedOperationException - use streaming API instead.

actual fun compress(buffer: 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, zone: AllocationZone = AllocationZone.Direct): PlatformBuffer

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

Link copied to clipboard
suspend fun compressWithSyncFlush(buffer: ReadBuffer, level: CompressionLevel = CompressionLevel.Default, zone: AllocationZone = AllocationZone.Direct): 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, allocator: BufferAllocator = BufferAllocator.Default): SuspendingStreamingDecompressor

Creates a suspending streaming decompressor.

expect fun SuspendingStreamingCompressor.Companion.create(algorithm: CompressionAlgorithm = CompressionAlgorithm.Deflate, level: CompressionLevel = CompressionLevel.Default, allocator: BufferAllocator = BufferAllocator.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, allocator: BufferAllocator = BufferAllocator.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, allocator: BufferAllocator = BufferAllocator.Default, outputBufferSize: Int = 32768, windowBits: Int = 0): StreamingCompressor

Creates a streaming compressor.

actual fun SuspendingStreamingDecompressor.Companion.create(algorithm: CompressionAlgorithm, allocator: BufferAllocator): SuspendingStreamingDecompressor

JS suspending streaming decompressor factory. Node.js: uses Transform stream API for stateful decompression. Browser: uses native DecompressionStream API.

actual fun SuspendingStreamingCompressor.Companion.create(algorithm: CompressionAlgorithm, level: CompressionLevel, allocator: BufferAllocator): SuspendingStreamingCompressor

JS suspending streaming compressor factory. Node.js: uses Transform stream API for stateful compression with flush support. Browser: uses native CompressionStream API (no flush support).

actual fun StreamingDecompressor.Companion.create(algorithm: CompressionAlgorithm, allocator: BufferAllocator, outputBufferSize: Int, expectedSize: Int): StreamingDecompressor

JS streaming decompressor factory. Node.js: uses native zlib sync APIs. Browser: throws UnsupportedOperationException (use SuspendingStreamingDecompressor instead).

actual fun StreamingCompressor.Companion.create(algorithm: CompressionAlgorithm, level: CompressionLevel, allocator: BufferAllocator, outputBufferSize: Int, windowBits: Int): StreamingCompressor

JS streaming compressor factory. Node.js: uses native zlib sync APIs. Browser: throws UnsupportedOperationException (use SuspendingStreamingCompressor instead).

actual fun SuspendingStreamingDecompressor.Companion.create(algorithm: CompressionAlgorithm, allocator: BufferAllocator): SuspendingStreamingDecompressor
actual fun SuspendingStreamingCompressor.Companion.create(algorithm: CompressionAlgorithm, level: CompressionLevel, allocator: BufferAllocator): SuspendingStreamingCompressor
actual fun StreamingDecompressor.Companion.create(algorithm: CompressionAlgorithm, allocator: BufferAllocator, 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, allocator: BufferAllocator, outputBufferSize: Int, windowBits: Int): 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
actual fun decompress(buffer: ReadBuffer, algorithm: CompressionAlgorithm): CompressionResult
actual fun decompress(buffer: ReadBuffer, algorithm: CompressionAlgorithm): CompressionResult
Link copied to clipboard
fun StreamProcessorBuilder.decompress(algorithm: CompressionAlgorithm = CompressionAlgorithm.Gzip, allocator: BufferAllocator = BufferAllocator.FromPool(pool)): StreamProcessorBuilder

Adds decompression to the StreamProcessor pipeline.

Link copied to clipboard
suspend fun decompressAsync(buffer: ReadBuffer, algorithm: CompressionAlgorithm = CompressionAlgorithm.Gzip, zone: AllocationZone = AllocationZone.Direct, expectedOutputSize: Int = 0): PlatformBuffer

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

Link copied to clipboard
suspend fun decompressWithSyncFlush(buffer: ReadBuffer, zone: AllocationZone = AllocationZone.Direct): 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.