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, ordefault_sizeblockmode::BlockMode=block_linked:block_linkedorblock_independentcontentchecksum::Bool=false: iftrue, frame is terminated with a 32-bit checksum of decompressed dataframetype::FrameType=normal_frame: ignored. LZ4 always writes a normal frame; this field is only filled in when reading a frame.skippable_framedoes not make a skippable frame.contentsize::Integer=0: size of uncompressed content (0 for unknown)blockchecksum::Bool=false: iftrue, each block is followed by a checksum of the block's compressed datacompressionlevel::Integer=0: compression level. Levels from2to12use LZ4 HC, which is slower and gives a better ratio as the level goes up; values above12act as12. Lower levels use the fast compressor:0(the default) and1are the same, and negative values are faster still, with a worse ratio the more negative they are.autoflush::Bool=false: always flush iftrue
CodecLz4.LZ4FrameCompressorStream — Type
LZ4FrameCompressorStream(stream::IO; kwargs...)Create an LZ4 frame compression stream that writes compressed data to, or reads uncompressed data from, stream. Keywords are passed to LZ4FrameCompressor or TranscodingStream.
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.
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.
Block format
Single LZ4 blocks, compatible with other LZ4 block implementations.
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.
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.
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.
Block-stream codecs (not recommended)
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.
Do not use the block-stream codecs for new data. Their format is specific to CodecLz4: no other LZ4 tool can read it, and each block's size is stored in the byte order of the machine that wrote it. They are only kept for existing data. Use LZ4FrameCompressor and LZ4FrameDecompressor instead, which use the standard LZ4 frame format.
Keywords
acceleration::Integer=0: acceleration factorblock_size::Integer=1024: The size in bytes to encrypt into each block.
CodecLz4.LZ4FastCompressorStream — Type
LZ4FastCompressorStream(stream::IO; kwargs...)Create a block-stream compression stream using LZ4FastCompressor. Keywords are passed to LZ4FastCompressor or TranscodingStream.
Do not use the block-stream codecs for new data. Their format is specific to CodecLz4: no other LZ4 tool can read it, and each block's size is stored in the byte order of the machine that wrote it. They are only kept for existing data. Use LZ4FrameCompressor and LZ4FrameDecompressor instead, which use the standard LZ4 frame format.
CodecLz4.LZ4HCCompressor — Type
LZ4HCCompressor(; kwargs...)Create a block-stream compression codec using LZ4 HC.
Do not use the block-stream codecs for new data. Their format is specific to CodecLz4: no other LZ4 tool can read it, and each block's size is stored in the byte order of the machine that wrote it. They are only kept for existing data. Use LZ4FrameCompressor and LZ4FrameDecompressor instead, which use the standard LZ4 frame format.
Keywords
compressionlevel::Integer=9: compression levelblock_size::Integer=1024: The size in bytes to encrypt into each block. (Max 4MB)
CodecLz4.LZ4HCCompressorStream — Type
LZ4HCCompressorStream(stream::IO; kwargs...)Create a block-stream compression stream using LZ4HCCompressor. Keywords are passed to LZ4HCCompressor or TranscodingStream.
Do not use the block-stream codecs for new data. Their format is specific to CodecLz4: no other LZ4 tool can read it, and each block's size is stored in the byte order of the machine that wrote it. They are only kept for existing data. Use LZ4FrameCompressor and LZ4FrameDecompressor instead, which use the standard LZ4 frame format.
CodecLz4.LZ4SafeDecompressor — Type
LZ4SafeDecompressor(; kwargs...)Create a block-stream decompression codec, for data written by LZ4FastCompressor or LZ4HCCompressor.
Do not use the block-stream codecs for new data. Their format is specific to CodecLz4: no other LZ4 tool can read it, and each block's size is stored in the byte order of the machine that wrote it. They are only kept for existing data. Use LZ4FrameCompressor and LZ4FrameDecompressor instead, which use the standard LZ4 frame format.
Keywords
block_size::Integer=1024: The size in bytes of unecrypted data contained in each block. Must match or exceed the compressionblock_sizeor decompression will fail.
CodecLz4.LZ4SafeDecompressorStream — Type
LZ4SafeDecompressorStream(stream::IO; kwargs...)Create a block-stream decompression stream using LZ4SafeDecompressor. Keywords are passed to LZ4SafeDecompressor or TranscodingStream.
Do not use the block-stream codecs for new data. Their format is specific to CodecLz4: no other LZ4 tool can read it, and each block's size is stored in the byte order of the machine that wrote it. They are only kept for existing data. Use LZ4FrameCompressor and LZ4FrameDecompressor instead, which use the standard LZ4 frame format.