
Pure DEFLATE, GZIP and ZLIB compression/decompression with blocking and streaming APIs, configurable levels, preset-dictionary support, and high-performance parity with standard implementations.
Pure Kotlin Multiplatform DEFLATE, GZIP, and ZLIB compression.
KFlate is a Kotlin Multiplatform port of the npm fflate library. It provides compression and decompression with configurable levels, dictionary support, and both blocking and streaming APIs across KMP targets.
| KFlate Web Compressor (Powered by WASM) |
kotlinx-io) interfaces.KFlate delivers performance comparable to standard implementations across all platforms:
For detailed benchmark results of each iteration, see the performance folder.
Add KFlate to your commonMain dependencies:
kotlin {
sourceSets {
commonMain.dependencies {
implementation("com.rafambn:KFlate:1.0.0")
}
}
}With KFlate, you select a format config and call the same API to compress/decompress:
import com.rafambn.kflate.KFlate
import com.rafambn.kflate.RAW
import com.rafambn.kflate.Raw
val input = "hello".encodeToByteArray()
val deflated = KFlate.compress(input, RAW())
val inflated = KFlate.decompress(deflated, Raw())import com.rafambn.kflate.KFlate
import com.rafambn.kflate.GZIP
import com.rafambn.kflate.Gzip
val input = "hello".encodeToByteArray()
val options = GZIP(
filename = "hello.txt",
comment = "example",
extraFields = mapOf("AB" to byteArrayOf(1, 2)),
includeHeaderCrc = true
)
val gz = KFlate.compress(input, options)
val roundTrip = KFlate.decompress(gz, Gzip())import com.rafambn.kflate.KFlate
import com.rafambn.kflate.ZLIB
import com.rafambn.kflate.Zlib
val input = "hello".encodeToByteArray()
val z = KFlate.compress(input, ZLIB())
val out = KFlate.decompress(z, Zlib())
val dict = "common".encodeToByteArray()
val zWithDict = KFlate.compress(input, ZLIB(dictionary = dict))level: Compression level 0–9 (default: 6)
bufferSize: Internal hash table size (optional, auto-sized per level)dictionary: Preset dictionary up to 32 KB (DEFLATE/ZLIB only)filename: Original filenamecomment: File commentextraFields: Custom header fieldsmtime: Modification timeincludeHeaderCrc: Include CRC16 of headerdictionary: Preset dictionary for DEFLATE/ZLIB (required if compression used one)Pure Kotlin Multiplatform DEFLATE, GZIP, and ZLIB compression.
KFlate is a Kotlin Multiplatform port of the npm fflate library. It provides compression and decompression with configurable levels, dictionary support, and both blocking and streaming APIs across KMP targets.
| KFlate Web Compressor (Powered by WASM) |
kotlinx-io) interfaces.KFlate delivers performance comparable to standard implementations across all platforms:
For detailed benchmark results of each iteration, see the performance folder.
Add KFlate to your commonMain dependencies:
kotlin {
sourceSets {
commonMain.dependencies {
implementation("com.rafambn:KFlate:1.0.0")
}
}
}With KFlate, you select a format config and call the same API to compress/decompress:
import com.rafambn.kflate.KFlate
import com.rafambn.kflate.RAW
import com.rafambn.kflate.Raw
val input = "hello".encodeToByteArray()
val deflated = KFlate.compress(input, RAW())
val inflated = KFlate.decompress(deflated, Raw())import com.rafambn.kflate.KFlate
import com.rafambn.kflate.GZIP
import com.rafambn.kflate.Gzip
val input = "hello".encodeToByteArray()
val options = GZIP(
filename = "hello.txt",
comment = "example",
extraFields = mapOf("AB" to byteArrayOf(1, 2)),
includeHeaderCrc = true
)
val gz = KFlate.compress(input, options)
val roundTrip = KFlate.decompress(gz, Gzip())import com.rafambn.kflate.KFlate
import com.rafambn.kflate.ZLIB
import com.rafambn.kflate.Zlib
val input = "hello".encodeToByteArray()
val z = KFlate.compress(input, ZLIB())
val out = KFlate.decompress(z, Zlib())
val dict = "common".encodeToByteArray()
val zWithDict = KFlate.compress(input, ZLIB(dictionary = dict))level: Compression level 0–9 (default: 6)
bufferSize: Internal hash table size (optional, auto-sized per level)dictionary: Preset dictionary up to 32 KB (DEFLATE/ZLIB only)filename: Original filenamecomment: File commentextraFields: Custom header fieldsmtime: Modification timeincludeHeaderCrc: Include CRC16 of headerdictionary: Preset dictionary for DEFLATE/ZLIB (required if compression used one)