Zstandard.jl
A pure Julia implementation of the Zstandard (RFC 8878) compression algorithm. No C dependencies required.
Features
Compression at levels -7 to 22 with libzstd 1.5.7's strategies and parameter tables (fast, dfast, greedy/lazy/lazy2 with the row-based match finder, btlazy2, btopt, btultra, btultra2), block pre- and post-splitting, and repeat-offset aware parsing; ratios match or beat libzstd's at nearly every level (3-byte match finder for levels 18-22 included)
Huffman literals (direct or FSE-compressed weights, 1 or 4 streams, table reuse across blocks) and FSE sequence coding with predefined/RLE/compressed/repeat table selection
Decompression of all standard frames, including concatenated and skippable frames (decoded in parallel with
nthreads), raw and formatted dictionaries (several at once withZstandardDictionarySet, chosen per frame by dictionary ID)Streaming compression and decompression (
ZstandardCompressorStream,ZstandardDecompressorStream, implementingIO): pledged sizes, size hints, long-distance matching and multithreading on streams, mid-frameflush, a window limit for untrusted input, and progress counters (stream_progress)Reusable contexts (
ZstandardCompressionContext,ZstandardDecompressionContext) withcompress!/decompress!into your own buffersDictionaries: compression with raw or formatted dictionaries, prepared dictionaries for many small inputs, training (
train_dictionary: fastCover or exact COVER, with parameter search on several threads)Reference prefixes (
prefix=, aszstd --patch-from), long-distance matching (long=true), multithreaded compression (nthreads),rsyncableoutputlibzstd's advanced parameters (
window_log,strategy, ...), frame header options (content_size,dict_id, magicless frames) and a target compressed block sizeThe seekable format (
compress_seekable,seek_table,decompress_range), compatible with libzstd'scontrib/seekable_formatSequence-level API (experimental, as in libzstd):
generate_sequencesandcompress_sequences(asZSTD_generateSequences/ZSTD_compressSequences)Frame inspection (
frame_header,frame_content_size,frame_compressed_size,decompressed_size, skippable frames), size bounds (compress_bound,decompress_bound) and memory estimates (estimate_compression_memory,estimate_decompression_memory)Julia 1.10 (LTS) and later
TranscodingStreams.jl codecs
ZstandardCompressor/ZstandardDecompressor(package extension, loaded withusing TranscodingStreams)Malformed input is rejected with a
ZstandardError
Installation
using Pkg
Pkg.add(url="https://github.com/JuliaIO/Zstandard.jl")Quick Start
using Zstandard
# Compress
compressed = compress("Hello, world!")
compressed = compress(read("input.bin"))
# Decompress
data = decompress(compressed)
# Streaming decompression
open("file.zst") do io
stream = ZstandardDecompressorStream(io)
decompressed = read(stream)
end
# Optional content checksum
compressed = compress(data, checksum=true)See Also
CodecZstd.jl – wraps the C libzstd library via TranscodingStreams.jl, providing a mature and battle-tested streaming interface.
ChunkCodecsLibZstd.jl – wraps the C libzstd library via ChunkCodecs.jl, providing chunk-based encoding and decoding.
ZstdInflate.jl – a pure Julia Zstandard decompressor (no compression), with in-memory and streaming decoding and parallel decoding of concatenated frames.
The C-backed packages wrap libzstd, which has years of production use and fuzzing behind it; prefer them where that matters most. Zstandard.jl is a complete pure Julia implementation (compression and decompression) for environments where C dependencies are unavailable or undesirable; its compression ratios match libzstd's and its decompression is about as fast or faster (see the README's performance section).