CodecLz4.jl

LZ4 compression and decompression codecs for TranscodingStreams.jl, using liblz4.

Frame format

The standard LZ4 frame format, compatible with the lz4 command line tool.

CodecLz4.LZ4FrameCompressor — Type
LZ4FrameCompressor(; kwargs...)

Create an LZ4 frame compression codec.

The output is the standard LZ4 frame format, readable by the lz4 command line tool and LZ4FrameDecompressor.

Keywords

  • blocksizeid::BlockSizeID=default_size: max64KB, max256KB, max1MB, max4MB, or default_size
  • blockmode::BlockMode=block_linked: block_linked or block_independent
  • contentchecksum::Bool=false: if true, frame is terminated with a 32-bit checksum of decompressed data
  • frametype::FrameType=normal_frame: ignored. LZ4 always writes a normal frame; this field is only filled in when reading a frame. skippable_frame does not make a skippable frame.
  • contentsize::Integer=0: size of uncompressed content (0 for unknown)
  • blockchecksum::Bool=false: if true, each block is followed by a checksum of the block's compressed data
  • compressionlevel::Integer=0: compression level. Levels from 2 to 12 use LZ4 HC, which is slower and gives a better ratio as the level goes up; values above 12 act as 12. Lower levels use the fast compressor: 0 (the default) and 1 are the same, and negative values are faster still, with a worse ratio the more negative they are.
  • autoflush::Bool=false: always flush if true
source
CodecLz4.LZ4FrameDecompressor — Type
LZ4FrameDecompressor()

Create an LZ4 frame decompression codec.

Reads the standard LZ4 frame format, including data written by the lz4 command line tool and LZ4FrameCompressor. Concatenated frames are decompressed one after another, and skippable frames are skipped. Input that is empty, or ends partway through a frame, is an error.

source
CodecLz4.LZ4FrameDecompressorStream — Type
LZ4FrameDecompressorStream(stream::IO; kwargs...)

Create an LZ4 frame decompression stream that reads compressed data from, or writes decompressed data to, stream. Keywords are passed to TranscodingStream.

source

Block format

Single LZ4 blocks, compatible with other LZ4 block implementations.

Note

The block format is not the frame format. These functions cannot read .lz4 files or the output of LZ4FrameCompressor, and their output cannot be read by LZ4FrameDecompressor or the lz4 command line tool.

CodecLz4.lz4_compress — Function
lz4_compress(input::Union{Vector{UInt8},Base.CodeUnits{UInt8}}, acceleration::Integer=0)

Compresses input using LZ4compressfast. Returns a Vector{UInt8} of the compressed data.

The output is a single raw LZ4 block, not an LZ4 frame. It cannot be read by LZ4FrameDecompressor or the lz4 command line tool. Use lz4_decompress and keep track of the decompressed size yourself.

source
CodecLz4.lz4_hc_compress — Function
lz4_hc_compress(input::Union{Vector{UInt8},Base.CodeUnits{UInt8}}, compressionlevel::Integer=9)

Compresses input using LZ4compressHC. Returns a Vector{UInt8} of the compressed data.

The output is a single raw LZ4 block, not an LZ4 frame. It cannot be read by LZ4FrameDecompressor or the lz4 command line tool. Use lz4_decompress and keep track of the decompressed size yourself.

source
CodecLz4.lz4_decompress — Function
lz4_decompress(input::Union{Vector{UInt8},Base.CodeUnits{UInt8}}, expected_size::Integer=length(input) * 2)

Decompresses input using LZ4decompresssafe. expected_size must be equal to or larger than the expected decompressed size of the input or decompression will fail. Returns a Vector{UInt8} of the decompressed data.

input must be a single raw LZ4 block, such as the output of lz4_compress or lz4_hc_compress. LZ4 frames, such as the output of the lz4 command line tool or LZ4FrameCompressor, must be decompressed with LZ4FrameDecompressor instead.

source

Block-stream codecs (not recommended)

Warning

Do not use these codecs for new data. They write a format specific to CodecLz4: a sequence of LZ4 blocks, each prefixed with its compressed size in the byte order of the machine that wrote it. No other LZ4 tool can read it. Use the Frame format codecs instead. These codecs are only kept to read existing data.

CodecLz4.LZ4FastCompressor — Type
LZ4FastCompressor(; kwargs...)

Create a block-stream compression codec using fast LZ4 compression. Decompress the output with LZ4SafeDecompressor.

Keywords

  • acceleration::Integer=0: acceleration factor
  • block_size::Integer=1024: The size in bytes to encrypt into each block.
source
CodecLz4.LZ4FastCompressorStream — Type
LZ4FastCompressorStream(stream::IO; kwargs...)

Create a block-stream compression stream using LZ4FastCompressor. Keywords are passed to LZ4FastCompressor or TranscodingStream.

source
CodecLz4.LZ4HCCompressor — Type
LZ4HCCompressor(; kwargs...)

Create a block-stream compression codec using LZ4 HC.

Keywords

  • compressionlevel::Integer=9: compression level
  • block_size::Integer=1024: The size in bytes to encrypt into each block. (Max 4MB)
source
CodecLz4.LZ4HCCompressorStream — Type
LZ4HCCompressorStream(stream::IO; kwargs...)

Create a block-stream compression stream using LZ4HCCompressor. Keywords are passed to LZ4HCCompressor or TranscodingStream.

source
CodecLz4.LZ4SafeDecompressor — Type
LZ4SafeDecompressor(; kwargs...)

Create a block-stream decompression codec, for data written by LZ4FastCompressor or LZ4HCCompressor.

Keywords

  • block_size::Integer=1024: The size in bytes of unecrypted data contained in each block. Must match or exceed the compression block_size or decompression will fail.
source
CodecLz4.LZ4SafeDecompressorStream — Type
LZ4SafeDecompressorStream(stream::IO; kwargs...)

Create a block-stream decompression stream using LZ4SafeDecompressor. Keywords are passed to LZ4SafeDecompressor or TranscodingStream.

source