Reference
LibDeflate.Compressor — Type
Compressor(compresslevel::UInt8=0x06)Create an object which can compress using the DEFLATE algorithm. compresslevel can be from level 1 (fast) to 12 (slow), and defaults to 6. Level 0 means no compression.
Creating this object allocates, so when compressing multiple DEFLATE blocks, keep the same compressor in memory rather than making one for each block. If the C library fails to allocate this object, an OutOfMemory error is thrown.
Compressor is not thread safe, and therefore should not be used by different tasks concurrently. Concurrent use may cause undefined behaviour.
See also: compress!, unsafe_compress!
Examples:
julia> compressor = Compressor();
julia> data = b"Hello, world!";
julia> out = zeros(UInt8, deflate_compress_bound(compressor, UInt(sizeof(data))));
julia> n = compress!(compressor, out, data);
julia> roundtrip = zeros(UInt8, sizeof(data));
julia> decompress!(Decompressor(), roundtrip, view(out, 1:n), UInt(sizeof(data)));
julia> roundtrip == data
trueLibDeflate.Decompressor — Type
Decompressor()Create an object which can decompress using the DEFLATE algorithm.
Creating this object allocates, so when decompressing multiple DEFLATE blocks, keep the same decompressor in memory rather than making one for each block. If the C library fails to allocate this object, an OutOfMemory error is thrown.
Decompressor is not thread safe, and therefore should not be used by different tasks concurrently. Concurrent use may cause undefined behaviour.
See also: decompress!, unsafe_decompress!
Examples:
julia> decompressor = Decompressor();
julia> compressed =
b"\x01\x0d\0\xf2\xff\x48\x65\x6c\x6c\x6f\x2c\x20\x77\x6f\x72\x6c\x64\x21";
julia> out = zeros(UInt8, 13);
julia> decompress!(decompressor, out, compressed);
julia> String(out)
"Hello, world!"LibDeflate.GzipDecompressAllResult — Type
GzipDecompressAllResultResult of successfully decompressing one or more complete gzip members, i.e. a gzip file composed of multiple, concatenated gzip data.
GzipDecompressAllResult is currently a NamedTuple, but may be changed to a named struct in a future release. The type name and properties are part of the public API; users should refer to this type as GzipDecompressAllResult instead of the NamedTuple subtype.
It has the following properties:
read::UInt: total input bytes occupied by the completed memberswritten::UInt: total decompressed bytes written by the completed membersmembers::UInt: number of completed members
Examples:
julia> combined = vcat(
b"\x1f\x8b\x08\0\0\0\0\0\xff\0\x01\x05\0\xfa",
b"\xff\x48\x65\x6c\x6c\x6f\x82\x89\xd1\xf7\x05\0\0\0",
b"\x1f\x8b\x08\0\0\0\0\0\xff\0\x01\x05\0\xfa",
b"\xff\x57\x6f\x72\x6c\x64\x47\x3e\xb6\xfb\x05\0\0\0",
); # gzip "Hello", then gzip "World"
julia> out = zeros(UInt8, 10);
julia> scratch = GzipDecompressAllScratch();
julia> result = gzip_decompress_all!(decompressor, out, combined, scratch);
julia> result.members === UInt(2)
true
julia> String(out)
"HelloWorld"LibDeflate.GzipDecompressAllScratch — Type
GzipDecompressAllScratch()
GzipDecompressAllScratch(extra_fields, member_results)Storage used by gzip_decompress_all! and unsafe_gzip_decompress_all!.
It has the following properties:
extra_fields::Vector{GzipExtraField}: extra fields accumulated from every completed member.member_results::Vector{GzipDecompressResult}: one result for every completed member.
When a GzipDecompressAllScratch is passed to a function, both vectors are emptied before validation. On success, the scratch contains exactly the GzipExtraFields and GzipDecompressResults from all members. On error, it contains entries only from members completed before the failing member; the failing member contributes to neither vector.
LibDeflate.GzipDecompressResult — Type
GzipDecompressResultResult of LibDeflate's gzip decompression.
It has the following properties:
written::UIntnumber of decompressed bytes writtenread::UIntnumber of bytes read from inputheader::GzipHeadermetadata
Examples:
julia> compressed = vcat(
b"\x1f\x8b\x08\0\0\0\0\0\xff\0\x01\x0d\0\xf2\xff\x48\x65\x6c",
b"\x6c\x6f\x2c\x20\x77\x6f\x72\x6c\x64\x21\xe6\xc6\xe6\xeb\x0d\0\0\0",
); # gzip "Hello, world!"
julia> out = zeros(UInt8, 13);
julia> fields = GzipExtraField[];
julia> result = gzip_decompress!(decompressor, out, compressed, fields);
julia> result.written === UInt(13)
true
julia> String(out)
"Hello, world!"LibDeflate.GzipExtraField — Type
GzipExtraFieldData structure for gzip extra data. Public properties:
tag::NTuple{2, UInt8}two-byte tagdata::UnitRange{UInt}one-based location of subfield data in the original input. The range is empty when the subfield data has length zero.
Examples:
julia> header_bytes = b"\x1f\x8b\x08\x04\0\0\0\0\0\xff"; # FEXTRA flag set
julia> extra_bytes = b"\x06\0\x41\x42\x02\0\x01\x02"; # XLEN, tag, len, data
julia> bytes = vcat(header_bytes, extra_bytes);
julia> fields = GzipExtraField[];
julia> parse_gzip_header(bytes, fields);
julia> fields[1].tag
(0x41, 0x42)
julia> bytes[fields[1].data] == b"\x01\x02"
trueLibDeflate.GzipHeader — Type
GzipHeaderStruct representing a gzip header. It has the following properties:
mtime::Union{Nothing, NonZeroUInt32}: modification time of the file, as expressed by a UNIX timestamp mod 2^32. A zero timestamp means that the time is unavailable, and is represented bynothing; a nonzero timestamp is stored in aNonZeroUInt32.filename::Union{Nothing, UnitRange{UInt}}: index of the filename in the header.nothingmeans that theFNAMEflag is absent, while an empty range means that the flag is present but the filename is empty.comment::Union{Nothing, UnitRange{UInt}}: index of the comment in the header.nothingmeans that theFCOMMENTflag is absent, while an empty range means that the flag is present but the comment is empty.extra::Union{Nothing, UnitRange{UInt}}: the indices of the gzip extra fields in the passed-inVector{GzipExtraField}(orGzipDecompressAllScratch). Note that these scratch types are mutated when passed to a function, which invalidates this range.nothingmeans that theFEXTRAflag is absent, while an empty range means that the flag is present withXLEN == 0.flags::UInt8,extra_flags::UInt8,os::UInt8: the raw bytes from the stream.
The filename and comment ranges refer to raw bytes. Their encoding is not validated; RFC 1952 specifies ISO 8859-1 (Latin-1) for these fields.
Examples:
julia> header_bytes = b"\x1f\x8b\x08\x08\0\0\0\0\0\xff";
julia> bytes = vcat(header_bytes, b"hi", b"\0"); # gzip header, filename "hi"
julia> fields = GzipExtraField[];
julia> header = parse_gzip_header(bytes, fields).header;
julia> String(bytes[header.filename])
"hi"LibDeflate.NonZeroUInt32 — Type
NonZeroUInt32Container that stores an UInt32 value, which cannot be zero. Obtain the inner value with the .x property:
Examples
julia> x = NonZeroUInt32(UInt32(3)); x.x
0x00000003
julia> NonZeroUInt32(UInt32(0))
ERROR: ArgumentError: Cannot construct a NonZeroUInt32 from zero
[...]LibDeflate.ReadableMemory — Type
ReadableMemoryStruct that wraps a pointer and a length. This struct is not garbage-collector aware, so must be used with GC.@preserve. This type can be constructed from DenseArray{UInt8}, String, SubString{String} and some SubArrays. It may also be directly constructed from a Ptr and an Integer. To make custom types available as input for LibDeflate, add a constructor taking your custom type. This type implements pointer(::ReadableMemory)::Ptr{Nothing} and sizeof(::ReadableMemory)::Int.
See also: WriteableMemory
Examples:
julia> v = [0x01, 0x02, 0x03, 0x04];
julia> GC.@preserve v begin
r = ReadableMemory(v)
@assert sizeof(r) === 4
ptr = Ptr{UInt32}(pointer(r))
htol(unsafe_load(ptr)) |> show
end
0x04030201See also: WriteableMemory
LibDeflate.WriteableMemory — Type
WriteableMemoryStruct that wraps a pointer and a length. This struct is not garbage-collector aware, so must be used with GC.@preserve. This type can be constructed from Vector{UInt8}, Memory{UInt8}, and some subtypes of SubArray. It may also be directly constructed from a Ptr and an Integer. To make custom types available as output for LibDeflate, add a constructor taking the custom type. This type implements pointer(::WriteableMemory)::Ptr{Nothing} and sizeof(::WriteableMemory)::Int.
See also: ReadableMemory
Examples:
julia> v = fill(0x00, 4);
julia> GC.@preserve v begin
w = WriteableMemory(v)
@assert sizeof(w) === 4
ptr = Ptr{UInt32}(pointer(w))
unsafe_store!(ptr, 0x01020304)
unsafe_load(ptr) |> show
end
0x01020304LibDeflate.adler32 — Function
adler32(data, start::UInt32=UInt32(1))::UInt32Calculate the Adler-32 checksum of data with seed start.
ReadableMemory(data) is constructed safely by preserving data from garbage collection for the duration of the call. Custom input types can opt in by implementing that constructor.
See also: unsafe_adler32
Examples:
julia> adler32(b"hello world")
0x1a0b045d
julia> adler32(b" world", adler32(b"hello")) == adler32(b"hello world")
trueLibDeflate.compress! — Method
compress!(::Compressor, output, input)::Union{LibDeflateError, UInt}Compress input as a DEFLATE payload into the beginning of output, returning the number of bytes written or LibDeflateErrors.insufficient_output_space if the output is too small. The output is never resized.
On error, return a LibDeflateError, and leave the content of output in an arbitrary state.
ReadableMemory(input) and WriteableMemory(output) are constructed safely by preserving both arguments from garbage collection for the duration of the call. Custom input and output types can opt in by implementing those constructors. This function does not check whether the input and output memory regions overlap (alias); the caller must ensure that they do not.
See also: unsafe_compress!
Examples:
julia> data = b"Hello, world!";
julia> out = zeros(UInt8, deflate_compress_bound(compressor, UInt(sizeof(data))));
julia> n = compress!(compressor, out, data);
julia> roundtrip = zeros(UInt8, sizeof(data));
julia> decompress!(decompressor, roundtrip, view(out, 1:n), UInt(sizeof(data)));
julia> roundtrip == data
trueLibDeflate.crc32 — Function
crc32(data, start::UInt32=UInt32(0))::UInt32Calculate the CRC-32 checksum of data with seed start. Note that CRC-32 is a different and slower algorithm than the crc32c provided in the Julia standard library.
ReadableMemory(data) is constructed safely by preserving data from garbage collection for the duration of the call. Custom input types can opt in by implementing that constructor.
See also: unsafe_crc32
Examples:
julia> crc32(b"hello world")
0x0d4a1185
julia> crc32(b" world", crc32(b"hello")) == crc32(b"hello world")
trueLibDeflate.decompress! — Method
decompress!(
::Decompressor, output, input, [n_out::UInt]
)::Union{LibDeflateError, @NamedTuple{read::UInt, written::UInt}}Decompress a DEFLATE stream, reading from the beginning of input and writing decompressed data to the beginning of output. Reading stops at the end of the DEFLATE stream, so trailing input is left unread. On success, return the number of bytes read and written.
On error, return a LibDeflateError, and leave the content of output in an arbitrary state.
The function returns LibDeflateErrors.insufficient_output_space if the decompressed data does not fit.
If the exact decompressed size is known, pass it as n_out to use the faster known-size path. An incorrect size returns LibDeflateErrors.decompressed_size_too_small or LibDeflateErrors.decompressed_size_too_large.
ReadableMemory(input) and WriteableMemory(output) are constructed safely by preserving both arguments from garbage collection for the duration of the call. Custom input and output types can opt in by implementing those constructors. This function does not check whether the input and output memory regions overlap (alias); the caller must ensure that they do not.
See also: unsafe_decompress!
Examples:
julia> compressed =
b"\x01\x0d\0\xf2\xff\x48\x65\x6c\x6c\x6f\x2c\x20\x77\x6f\x72\x6c\x64\x21";
julia> out = zeros(UInt8, 13);
julia> decompress!(decompressor, out, compressed);
julia> String(out)
"Hello, world!"LibDeflate.deflate_compress_bound — Method
deflate_compress_bound(
compressor::Compressor,
input_size::UInt
mi)::Union{LibDeflateError, UInt}Return a worst-case upper bound on the number of bytes produced by compress! when compressing input_size bytes with compressor. This is generally slightly larger than input_size.
The bound may overestimate the required space, but an output buffer of this size is guaranteed to be sufficient. This calculation is constant-time with respect to input_size. Returns LibDeflateErrors.overflow if the bound cannot be represented as a UInt.
Examples:
julia> bound = deflate_compress_bound(compressor, UInt(1000));
julia> bound >= 1000
trueLibDeflate.gzip_compress! — Method
gzip_compress!(
compressor::Compressor,
output,
input;
comment=nothing,
filename=nothing,
extra=nothing,
mtime::Union{NonZeroUInt32, Nothing} = nothing,
header_crc::Bool=false
)::Union{LibDeflateError, UInt}Compress input as gzip data into the fixed-size buffer output, returning the number of bytes written or LibDeflateErrors.insufficient_output_space if it does not fit. The output is never resized.
On error, return a LibDeflateError, and leave the content of output in an arbitrary state.
Use gzip_compress_bound to determine an output size that is guaranteed to be sufficient.
Optional comment, filename, and extra metadata are omitted when set to nothing. comment and filename must not contain a zero byte. extra must represent valid gzip extra data and must not exceed typemax(UInt16) bytes. comment and filename are otherwise treated as uninterpreted bytes: their encoding is not validated. Currently the OS byte is set to 255, XFL set to 2 (compression level 12), 4 (compression level 1), or 0 (any other level), according to RFC 1952 v4.2, and the FTEXT flag unset. This behaviour is subject to change.
mtime is the modification time in seconds since the Unix epoch represented by a NonZeroUInt32, or nothing if not available.
WriteableMemory(output) and ReadableMemory wrappers for input and every non-nothing metadata argument are constructed safely by preserving those arguments from garbage collection for the duration of the call. Custom input, output, and metadata types can opt in by implementing the corresponding constructors. This function does not check whether the output memory region overlaps (aliases) the input or a metadata region; the caller must ensure that it does not.
See also: unsafe_gzip_compress!
Examples:
julia> data = b"Hello, world!";
julia> out = zeros(UInt8, gzip_compress_bound(compressor, UInt(sizeof(data))));
julia> n = gzip_compress!(compressor, out, data);
julia> roundtrip = zeros(UInt8, sizeof(data));
julia> fields = GzipExtraField[];
julia> gzip_decompress!(
decompressor, roundtrip, view(out, 1:n), UInt(sizeof(data)), fields,
);
julia> roundtrip == data
trueLibDeflate.gzip_compress_bound — Method
gzip_compress_bound(
compressor::Compressor,
input_size::UInt;
comment_len::Union{Nothing, UInt} = nothing,
filename_len::Union{Nothing, UInt} = nothing,
extra_len::Union{Nothing, UInt16} = nothing,
header_crc::Bool = false,
)::Union{LibDeflateError, UInt}Return a worst-case upper bound on the number of bytes produced by gzip_compress! with the given input and metadata sizes. A metadata length of nothing means that the corresponding optional field will not be present, while 0 represents a present but empty field.
Returns a LibDeflateErrors.overflow if the result would overflow UInt.
The bound may overestimate the required space, but an output buffer of this size is guaranteed to be sufficient. This calculation is constant-time with respect to all supplied sizes.
Examples:
julia> bound = gzip_compress_bound(compressor, UInt(100));
julia> bound_with_name = gzip_compress_bound(compressor, UInt(100); filename_len=UInt(8));
julia> bound_with_name > bound
trueLibDeflate.gzip_decompress! — Method
gzip_decompress!(
::Decompressor, output, input,
extra_fields::Vector{GzipExtraField}
)::Union{GzipDecompressResult, LibDeflateError}
gzip_decompress!(
::Decompressor, output, input, n_out::UInt,
extra_fields::Vector{GzipExtraField}
)::Union{GzipDecompressResult, LibDeflateError}Decompress the first gzip member in input into the fixed-size buffer output. Return LibDeflateErrors.insufficient_output_space if the decompressed data does not fit.
If the exact decompressed size is known, pass it as n_out to use the faster known-size decompression path. An incorrect size returns LibDeflateErrors.decompressed_size_too_small or LibDeflateErrors.decompressed_size_too_large.
On success, the returned result reports both the decompressed length and the total number of input bytes consumed by that member. Following gzip members or trailing data are left unread.
On error, return a LibDeflateError, and leave the content of output in an arbitrary state.
The function empties extra_fields before validation and appends the member's parsed extra fields to it. The returned header's extra range contains the indices of those fields in extra_fields.
ReadableMemory(input) and WriteableMemory(output) are constructed safely by preserving both arguments from garbage collection for the duration of the call. Custom input and output types can opt in by implementing those constructors. This function does not check whether the input and output memory regions overlap (alias); the caller must ensure that they do not.
See also: unsafe_gzip_decompress!
Examples:
julia> compressed = vcat(
b"\x1f\x8b\x08\0\0\0\0\0\xff\0\x01\x0d\0\xf2\xff\x48\x65\x6c",
b"\x6c\x6f\x2c\x20\x77\x6f\x72\x6c\x64\x21\xe6\xc6\xe6\xeb\x0d\0\0\0",
); # gzip "Hello, world!"
julia> out = zeros(UInt8, 13);
julia> fields = GzipExtraField[];
julia> gzip_decompress!(decompressor, out, compressed, fields);
julia> String(out)
"Hello, world!"LibDeflate.gzip_decompress_all! — Method
gzip_decompress_all!(
::Decompressor, output, input, scratch::GzipDecompressAllScratch
)::Union{
GzipDecompressAllResult,
Tuple{GzipDecompressAllResult, LibDeflateError},
}Decompress every member of a gzip file in input into the fixed-size buffer output. The input must contain at least one complete member and no trailing data.
On success, return GzipDecompressAllResult with statistics of the decompression result. If an error is encountered, return a tuple containing the same statistics for all members completed before the error, followed by the LibDeflateError.
On error, return a tuple of result and a LibDeflateError. The first result.written bytes of output are well-defined and valid, but any subsequent bytes are in an arbitrary undefined state.
Empty both vectors in scratch before validation. On return, scratch.extra_fields contains fields from every completed member and scratch.member_results contains one result per completed member. A failing member contributes to neither vector.
ReadableMemory(input) and WriteableMemory(output) are constructed safely by preserving both arguments from garbage collection for the duration of the call. Custom input and output types can opt in by implementing those constructors. This function does not check whether the input and output memory regions overlap (alias); the caller must ensure that they do not.
See also: gzip_decompress!, unsafe_gzip_decompress_all!
Examples:
julia> combined = vcat(
b"\x1f\x8b\x08\0\0\0\0\0\xff\0\x01\x05\0\xfa",
b"\xff\x48\x65\x6c\x6c\x6f\x82\x89\xd1\xf7\x05\0\0\0",
b"\x1f\x8b\x08\0\0\0\0\0\xff\0\x01\x05\0\xfa",
b"\xff\x57\x6f\x72\x6c\x64\x47\x3e\xb6\xfb\x05\0\0\0",
); # gzip "Hello", then gzip "World"
julia> out = zeros(UInt8, 10);
julia> scratch = GzipDecompressAllScratch();
julia> result = gzip_decompress_all!(decompressor, out, combined, scratch);
julia> result.members === UInt(2)
true
julia> String(out)
"HelloWorld"LibDeflate.is_valid_extra_data — Method
is_valid_extra_data(data)::BoolCheck whether data represents valid gzip metadata for the "extra" field. Gzip extra data cannot exceed typemax(UInt16) bytes.
ReadableMemory(data) is constructed safely by preserving data from garbage collection for the duration of the call. Custom input types can opt in by implementing that constructor.
See also: unsafe_is_valid_extra_data
Examples:
julia> is_valid_extra_data(b"\x41\x42\x02\0\x01\x02")
true
julia> is_valid_extra_data(b"\x41\x42\x02\0\x01") # too short for declared length
falseLibDeflate.parse_gzip_header — Method
parse_gzip_header(
input,
extra_fields::Vector{GzipExtraField}
)::Union{
LibDeflateError, @NamedTuple{read::UInt, header::GzipHeader}
}Parse the input data, returning the number of bytes read and a GzipHeader, or a LibDeflateError. The parser empties extra_fields before validation, then appends every parsed gzip extra field to it. The returned header's extra range contains the indices of those fields in extra_fields.
ReadableMemory(input) is constructed safely by preserving input from garbage collection for the duration of the call. Custom input types can opt in by implementing that constructor.
See also: unsafe_parse_gzip_header
Examples:
julia> header_bytes = b"\x1f\x8b\x08\x08\0\0\0\0\0\xff";
julia> bytes = vcat(header_bytes, b"hi", b"\0"); # gzip header, filename "hi"
julia> fields = GzipExtraField[];
julia> result = parse_gzip_header(bytes, fields);
julia> result.read === UInt(13)
true
julia> String(bytes[result.header.filename])
"hi"LibDeflate.unsafe_adler32 — Function
unsafe_adler32(in::ReadableMemory, start::UInt32=UInt32(1))::UInt32Low-level variant of adler32 that operates directly on ReadableMemory and has the same checksum behavior. The caller must keep the allocation referenced by in alive, typically by wrapping both construction of the memory wrapper and this call in GC.@preserve.
See also: adler32
LibDeflate.unsafe_compress! — Method
unsafe_compress!(
::Compressor, out::WriteableMemory, in::ReadableMemory
)::Union{UInt, LibDeflateError}Low-level variant of compress! that operates directly on WriteableMemory and ReadableMemory. It has the same compression behavior, return value, and errors as compress!.
The caller must keep the allocations referenced by out and in alive, typically by wrapping both construction of the memory wrappers and this call in GC.@preserve. The memory regions referenced by out and in must not overlap (alias).
See also: compress!
LibDeflate.unsafe_crc32 — Function
unsafe_crc32(in::ReadableMemory, start::UInt32=UInt32(0))::UInt32Low-level variant of crc32 that operates directly on ReadableMemory and has the same checksum behavior. The caller must keep the allocation referenced by in alive, typically by wrapping both construction of the memory wrapper and this call in GC.@preserve.
See also: crc32
LibDeflate.unsafe_decompress! — Method
unsafe_decompress!(
::Decompressor, output::WriteableMemory, input::ReadableMemory,
[n_out::UInt]
)::Union{@NamedTuple{read::UInt, written::UInt}, LibDeflateError}Low-level variant of decompress! that operates directly on WriteableMemory and ReadableMemory. It has the same decompression behavior, return values, and errors as decompress!.
The caller must keep the allocations referenced by output and input alive, typically by wrapping both construction of the memory wrappers and this call in GC.@preserve. The memory regions referenced by output and input must not overlap (alias).
See also: decompress!
LibDeflate.unsafe_gzip_compress! — Method
unsafe_gzip_compress!(
compressor::Compressor,
out::WriteableMemory,
in::ReadableMemory;
comment::Union{Nothing, ReadableMemory} = nothing,
filename::Union{Nothing, ReadableMemory} = nothing,
extra::Union{Nothing, ReadableMemory} = nothing,
mtime::Union{NonZeroUInt32, Nothing} = nothing,
header_crc::Bool=false,
)::Union{LibDeflateError, UInt}Low-level variant of gzip_compress! that operates directly on WriteableMemory and ReadableMemory. It has the same compression behavior, metadata rules, return value, and errors as gzip_compress!.
The caller must keep the allocations referenced by out, in, and every non-nothing metadata argument alive, typically by wrapping both construction of the memory wrappers and this call in GC.@preserve. The memory region referenced by out must not overlap the regions referenced by in or any metadata argument.
See also: gzip_compress!
LibDeflate.unsafe_gzip_decompress! — Method
unsafe_gzip_decompress!(
::Decompressor, output::WriteableMemory, input::ReadableMemory,
extra_fields::Vector{GzipExtraField}
)::Union{LibDeflateError, GzipDecompressResult}
unsafe_gzip_decompress!(
::Decompressor, output::WriteableMemory, input::ReadableMemory, n_out::UInt,
extra_fields::Vector{GzipExtraField}
)::Union{LibDeflateError, GzipDecompressResult}Low-level variant of gzip_decompress! that operates directly on WriteableMemory and ReadableMemory. It has the same decompression behavior, return value, and errors as gzip_decompress!.
The caller must keep the allocations referenced by output and input alive, typically by wrapping both construction of the memory wrappers and this call in GC.@preserve. The memory regions referenced by output and input must not overlap (alias).
See also: gzip_decompress!
LibDeflate.unsafe_gzip_decompress_all! — Method
unsafe_gzip_decompress_all!(
::Decompressor, output::WriteableMemory, input::ReadableMemory,
scratch::GzipDecompressAllScratch
)::Union{
GzipDecompressAllResult,
Tuple{GzipDecompressAllResult, LibDeflateError},
}Low-level variant of gzip_decompress_all! that operates directly on WriteableMemory and ReadableMemory. It has the same decompression behavior, return value, errors, and effects on scratch as gzip_decompress_all!.
The caller must keep the allocations referenced by output and input alive, typically by wrapping both construction of the memory wrappers and this call in GC.@preserve. The memory regions referenced by output and input must not overlap (alias).
See also: gzip_decompress_all!
LibDeflate.unsafe_is_valid_extra_data — Method
unsafe_is_valid_extra_data(data::ReadableMemory)::BoolLow-level variant of is_valid_extra_data that operates directly on ReadableMemory and has the same validation behavior. The caller must keep the allocation referenced by data alive, typically by wrapping both construction of the memory wrapper and this call in GC.@preserve.
See also: is_valid_extra_data
LibDeflate.unsafe_parse_gzip_header — Method
unsafe_parse_gzip_header(
input::ReadableMemory, extra_fields::Vector{GzipExtraField}
)Low-level variant of parse_gzip_header that operates directly on ReadableMemory. It has the same parsing behavior, return value, and errors as parse_gzip_header.
The caller must keep the allocation referenced by input alive, typically by wrapping both construction of the memory wrapper and this call in GC.@preserve.
See also: parse_gzip_header
LibDeflate.unsafe_zlib_compress! — Method
unsafe_zlib_compress!(
::Compressor, output::WriteableMemory, input::ReadableMemory
)::Union{LibDeflateError, UInt}Low-level variant of zlib_compress! that operates directly on WriteableMemory and ReadableMemory. It has the same compression behavior, return value, and errors as zlib_compress!.
The caller must keep the allocations referenced by output and input alive, typically by wrapping both construction of the memory wrappers and this call in GC.@preserve. The memory regions referenced by output and input must not overlap (alias).
See also: zlib_compress!
LibDeflate.unsafe_zlib_decompress! — Method
unsafe_zlib_decompress!(
::Decompressor, output::WriteableMemory, input::ReadableMemory,
[n_out::UInt]
)::Union{LibDeflateError, UInt}Low-level variant of zlib_decompress! that operates directly on WriteableMemory and ReadableMemory. It has the same decompression behavior, return value, and errors as zlib_decompress!.
The caller must keep the allocations referenced by output and input alive, typically by wrapping both construction of the memory wrappers and this call in GC.@preserve. The memory regions referenced by output and input must not overlap (alias).
See also: zlib_decompress!
LibDeflate.zlib_compress! — Method
zlib_compress!(::Compressor, output, input)::Union{LibDeflateError, UInt}Compress input as a zlib stream into output, returning the number of bytes written. The output is never resized. On error, return a LibDeflateError, and leave the content of output in an arbitrary state.
ReadableMemory(input) and WriteableMemory(output) are constructed safely by preserving both arguments from garbage collection for the duration of the call. Custom input and output types can opt in by implementing those constructors. This function does not check whether the input and output memory regions overlap (alias); the caller must ensure that they do not.
See also: unsafe_zlib_compress!
Examples:
julia> data = b"Hello, world!";
julia> out = zeros(UInt8, zlib_compress_bound(compressor, UInt(sizeof(data))));
julia> n = zlib_compress!(compressor, out, data);
julia> roundtrip = zeros(UInt8, sizeof(data));
julia> zlib_decompress!(
decompressor, roundtrip, view(out, 1:n), UInt(sizeof(data)),
);
julia> roundtrip == data
trueLibDeflate.zlib_compress_bound — Method
zlib_compress_bound(compressor::Compressor, input_size::UInt)::Union{LibDeflateError, UInt}Return a worst-case upper bound on the number of bytes produced by zlib_compress! when compressing input_size bytes with compressor.
The bound may overestimate the required space, but an output buffer of this size is guaranteed to be sufficient. This calculation does not inspect any input data and is constant-time with respect to input_size. Returns LibDeflateErrors.overflow if the bound cannot be represented as a UInt.
Examples:
julia> bound = zlib_compress_bound(compressor, UInt(1000));
julia> bound >= 1000
trueLibDeflate.zlib_decompress! — Method
zlib_decompress!(
::Decompressor, output, input, [n_out::UInt]
)::Union{LibDeflateError, UInt}Decompress input as a zlib stream into output. If the exact decompressed size is known, pass it as n_out to use the faster known-size path. Return the number of bytes written or a LibDeflateError.
The complete input must contain exactly one zlib stream. Bytes after that stream, including a second concatenated zlib stream, return LibDeflateErrors.zlib_trailing_data.
On error, return a LibDeflateError, and leave the content of output in an arbitrary state.
ReadableMemory(input) and WriteableMemory(output) are constructed safely by preserving both arguments from garbage collection for the duration of the call. Custom input and output types can opt in by implementing those constructors. This function does not check whether the input and output memory regions overlap (alias); the caller must ensure that they do not.
See also: unsafe_zlib_decompress!
Examples:
julia> compressed = vcat(
b"\x78\x5e\x01\x0d\0\xf2\xff\x48\x65\x6c\x6c\x6f",
b"\x2c\x20\x77\x6f\x72\x6c\x64\x21\x20\x5e\x04\x8a",
); # zlib "Hello, world!"
julia> out = zeros(UInt8, 13);
julia> zlib_decompress!(decompressor, out, compressed);
julia> String(out)
"Hello, world!"LibDeflate.LibDeflateErrors — Module
Module LibDeflateErrorsDummy module to contain the variants of the LibDeflateError enum as a namespace.
LibDeflate.LibDeflateErrors.LibDeflateError — Type
LibDeflateErrorA UInt8 enum representing that LibDeflate encountered an error. Error names and their documented meanings are stable across non-breaking releases. Their underlying numerical values are not. Code checking for a specific error should compare it to a named value, e.g. err == LibDeflateErrors.insufficient_output_space.
For input containing multiple independent faults, which applicable error is returned is unspecified. Successful operations will not return a LibDeflateError. Operations that previously returned errors are allowed to succeed in future minor releases.
Error meanings:
overflow: An input would cause an integer to overflow. For example, this can happen if the compression bound cannot be represented as aUInt.input_too_short: mandatory gzip or zlib wrapper bytes are missing.not_deflate: a gzip or zlib compression-method field does not specify DEFLATE, the only compression algorithm currently supported.insufficient_output_space: a compression result or unknown-size decompression result does not fit the output buffer.decompressed_size_too_smallanddecompressed_size_too_large: the actual decompressed size is respectively smaller or larger than the supplied exact size.deflate_bad_payload: the DEFLATE payload is invalid, truncated, or unsupported.gzip_bad_magic_bytes: the gzip identification bytes are invalid.gzip_reserved_flags_set: at least one reserved gzip flag is set.gzip_extra_too_long: encoder-provided gzip extra data exceedstypemax(UInt16).gzip_bad_extra_length: gzip extra subfields do not fit their enclosing block.gzip_filename_not_null_terminatedandgzip_comment_not_null_terminated: the corresponding decoded header field has no terminating zero byte.gzip_filename_contains_nullandgzip_comment_contains_null: the corresponding encoder-provided metadata contains a zero byte.gzip_bad_header_crc16,gzip_bad_crc32, andgzip_bad_isize: the corresponding gzip integrity field does not match the decoded member.zlib_bad_window_size: the zlib window-size field is invalid.zlib_dictionary_required: the stream requires a preset dictionary, which this API does not support.zlib_trailing_data: bytes remain after the single complete zlib stream.zlib_bad_header_checksumandzlib_bad_adler32: the corresponding zlib checksum is invalid.
Examples:
julia> c = vcat(
b"\x01\x0d\0\xf2\xff\x48\x65\x6c\x6c",
b"\x6f\x2c\x20\x77\x6f\x72\x6c\x64\x21",
);
julia> out = zeros(UInt8, 2); # too small to hold the decompressed data
julia> err = decompress!(decompressor, out, c);
julia> err isa LibDeflateError
true
julia> err == LibDeflateErrors.insufficient_output_space
true