Development version 0.1.0-dev.
Zlib is a standalone Ada/Alire crate for zlib-wrapped Deflate,
implicit multi-member gzip inflate, gzip output, explicit raw Deflate inflate/output,
native stored-file 7z archive output/extraction, and wrapper-strict deterministic compression. It is not Git-specific, not
HttpClient-specific, and has no dependency on version, HttpClient, system
zlib, generated Python fixtures, or C runtime compression libraries.
The crate provides a small root package:
with Zlib;Public child packages are not part of the consumer contract. Consumers should
use only the declarations in src/zlib.ads unless they are deliberately
working on the crate internals.
Add the crate to an Alire project with:
alr with zlib
alr buildWhen working from this repository, the fast validation path is:
alr build
tools/bin/check_allCompress and inflate a zlib-wrapped stream:
with Ada.Text_IO;
with Zlib;
procedure Example is
Status : Zlib.Status_Code;
Plain : constant Zlib.Byte_Array :=
[16#68#, 16#65#, 16#6C#, 16#6C#, 16#6F#];
Packed : constant Zlib.Byte_Array :=
Zlib.Deflate (Plain, Status => Status);
Back : constant Zlib.Byte_Array :=
Zlib.Inflate (Packed, Status);
begin
if Status /= Zlib.Ok or else Back /= Plain then
Ada.Text_IO.Put_Line ("zlib roundtrip failed: " & Zlib.Status_Image (Status));
end if;
end Example;Use explicit wrapper APIs when the input or output is not a zlib stream:
Gz : constant Zlib.Byte_Array := Zlib.GZip (Plain, Status => Status);
Gz_Back : constant Zlib.Byte_Array :=
Zlib.Inflate_With_Header (Gz, Zlib.GZip, Status);
Raw : constant Zlib.Byte_Array := Zlib.Deflate_Raw (Plain, Status => Status);
Raw_Back : constant Zlib.Byte_Array := Zlib.Inflate_Raw (Raw, Status);Use file helpers for whole-file operations:
Zlib.Deflate_File ("input.bin", "input.bin.z", Status => Status);
Zlib.Inflate_File ("input.bin.z", "input.bin.out", Status => Status);
Zlib.GZip_File ("input.bin", "input.bin.gz", Status => Status);
Zlib.Deflate_Raw_File ("input.bin", "input.bin.deflate", Status => Status);
Zlib.Seven_Zip_Stored_File ("input.bin", "input.7z", "input.bin", Status);
Zlib.Extract_Seven_Zip_Stored_File ("input.7z", "input.out", "input.bin", Status);The compiled version of this quickstart is examples/quickstart.adb; the full first-use walkthrough is in docs/QUICKSTART.md.
Independent operations are reentrant. Tools may call zlib functions from
multiple Ada tasks when each task uses its own buffers, streaming filter
objects, and output paths. The library does not synchronize shared
caller-owned state, so shared Filter_Type/Compression_Filter_Type objects,
mutable buffers, and overlapping filesystem destinations must be protected by
the caller.
Generate consumer-facing GNATdoc output for the root public API with:
alr exec -- gnatdoc -P docs/public_docs.gpr --style gnat --generate public --backend html --warnings -O docs/html- one-shot zlib inflate for stored, fixed-Huffman, and dynamic-Huffman Deflate blocks
- explicit one-shot wrapper selection through
Inflate_With_HeaderforZlib_Header,GZip, andRaw_Deflate - convenience wrapper-discriminating inflate through
Inflate_Auto - one-shot zlib stored-block output through
Deflate_Stored - one-shot zlib fixed-Huffman output through
Deflate_Fixed - one-shot zlib dynamic-Huffman output through
Deflate_Dynamic - policy-based zlib output through
DeflatewithCompression_Mode - deterministic one-shot gzip output through
GZipwithCompression_Mode - deterministic multi-member gzip output through
GZip_MembersandGZip_File_Members - one-shot raw Deflate output through
Deflate_RawwithCompression_Mode - ZIP output through
ZIP,ZIP_File, andZIP_Filesfor Stored and Deflate entries, including explicit ZIP64 metadata fromZIP_Files - in-process BZip2, ZIP-LZMA, and Zstandard member-payload creation and unencrypted extraction for ZIP methods 12, 14, 20, and 93 through the ZIP compatibility bridge
- native stored, Deflate, BZip2, LZMA, LZMA2, and PPMd
.7zoutput/extraction, including general PPMd7 encode/decode, stock-7z non-solid multi-block streams with LZMA encoded headers, stock-7z no-stream empty-file entries, and stock-7z BCJ+PPMd filter chains, with common archive/file metadata and SFX prefixes skipped during supported native extraction, covered solid-substream, BCJ2 graph layouts with Copy or supported main pre-coders, and bounded linear filter-chain extraction layouts made from supported single-input coders and supported branch/Delta filters, including standard zero-based, reverse-linear, and reordered zero-based linear bind pairs, throughSeven_Zip_Stored,Seven_Zip_Deflate,Seven_Zip_BZip2,Seven_Zip_LZMA,Seven_Zip_LZMA2,Seven_Zip_Filtered,Seven_Zip_Method_Graph, the matching file helpers,Seven_Zip_Stored_Files,Seven_Zip_Deflate_Files,Seven_Zip_BZip2_Files,Seven_Zip_LZMA_Files,Seven_Zip_LZMA2_Files,Seven_Zip_PPMd_Files, andExtract_Seven_Zip; broader unsupported 7z methods fail closed - file helpers for one-shot inflate and all one-shot compression modes
- streaming zlib inflate through
Inflate_Init,Translate,Flush,Stream_End, andClose - streaming gzip inflate through
Header => GZip, accepting concatenated members by default - streaming raw Deflate inflate through
Header => Raw_Deflate - streaming zlib, gzip, and raw Deflate compression through
Deflate_Init,Compress,Compress_Flush,Compress_Stream_End, andCompress_Closefor stored-block, fixed-Huffman, dynamic-Huffman, and Auto output - zlib Adler-32 validation
- gzip CRC32 and ISIZE validation
- deterministic lifecycle/error behavior for streaming callers
- internal streaming engine shared by the one-shot and streaming APIs
- Ada-only AUnit tests with frozen byte-vector fixtures
Seven_Zip_Stored/Seven_Zip_Stored_File write a native .7z container with
the Copy coder for one file or a header-only directory entry. Single-entry 7z
metadata overloads emit supported modification FILETIME and raw Windows
attributes for file entries; the stored metadata overload and compressed
metadata overloads can also emit header-only directory entries. File and
file-list 7z helpers preserve source modification time and read-only state
where the platform exposes them. Single-entry file helpers accept ordinary-file
inputs or directory inputs; directories become header-only directory entries.
Seven_Zip_Deflate/Seven_Zip_Deflate_File write a single-entry .7z
container with a raw-Deflate packed payload or a header-only directory entry
using either a compression mode or compression level.
Seven_Zip_LZMA/Seven_Zip_LZMA_File
write native single-entry .7z archives with the LZMA coder.
Seven_Zip_BZip2/Seven_Zip_BZip2_File write native single-entry .7z
archives with the BZip2 coder. Seven_Zip_LZMA2 and Seven_Zip_LZMA2_File
write native single-entry .7z archives using valid LZMA2 chunks, including
compressed chunks for payloads that benefit from them.
Seven_Zip_PPMd/Seven_Zip_PPMd_File write native single-entry .7z
archives using deterministic verified PPMd streams accepted by this crate's
native extractor. The writer selects among modeled stock-compatible candidates,
repeated/periodic PPMd forms, and a verified native root-context fallback. The
file helper
accepts either the input basename or an explicit entry name, and directory
inputs become header-only directory entries.
They self-verify generated archives and do not call a local 7z executable.
Empty PPMd output uses a range-initialized empty stream.
Seven_Zip_Filtered writes a native single-entry non-encrypted compressed
filtered .7z archive such as BCJ+LZMA, BCJ+LZMA2, or Delta+Deflate. It
applies one supported 7z branch/Delta filter, compresses the filtered bytes
with Deflate, BZip2, LZMA, LZMA2, or PPMd, and emits the two-coder folder and
bind pair in process. RISC-V uses the compact 7z 24.x method ID and handles
32-bit JAL branches; stock RISC-V interop validation is part of
tools/bin/seven_zip_interop_check when the available 7z supports it.
Seven_Zip_Method_Graph writes a native single-entry non-encrypted .7z
method-graph container from already packed stream bytes and caller-supplied
coders, bind pairs, packed stream indices, sizes, and final unpacked CRC. It is
the low-level escape hatch for graph layouts; callers remain responsible for
producing packed bytes that match the graph.
Seven_Zip_Stored_Files writes a multi-entry solid Copy-coder archive from
parallel input-path and distinct entry-name lists. Ordinary files become packed
substreams and directory input paths become no-stream directory entries.
Seven_Zip_Deflate_Files writes the same file-list shape with independently
Deflate-packed entries using either a compression mode or compression level.
Seven_Zip_BZip2_Files writes the same file-list shape with independently
BZip2-packed entries.
Seven_Zip_LZMA_Files writes the same file-list shape with independently
LZMA-coded entries using the library default properties.
Seven_Zip_LZMA2_Files writes the same file-list shape with independently
LZMA2-coded entries using valid LZMA2 chunks. Seven_Zip_PPMd_Files writes
the same file-list shape with independently packed deterministic PPMd entries
using the same verified candidate selection. File-list writers preserve supported
per-entry source metadata for files and directories.
Extract_Seven_Zip_Stored and its file helpers verify and extract one named
entry from those Copy-coder, Deflate, BZip2, LZMA, or LZMA2 layouts, plus the
native PPMd extraction subset for empty streams with or without range headers,
repeated-symbol, simple root-symbol, periodic-prefix, stock-7z non-solid multi-block streams with LZMA encoded
headers, stock-7z no-stream empty-file entries, stock-7z BCJ+PPMd filter
chains, and BCJ2 graphs with Copy, PPMd, or supported main pre-coders. The PPMd model table is allocated from
the archive's declared PPMd memory and requested output size rather than a
fixed stream-independent context cap. The supported PPMd decode mode ladder is
used for payloads, encoded headers, BCJ+x86 chains, and BCJ2 graphs. Broader
PPMd entries fail closed with a non-Ok status. Extract_Seven_Zip is the neutral extractor name with the same
native-only supported method set. Duplicate matching names are rejected.
Extract_Seven_Zip_Metadata exposes supported entry kind, modification
FILETIME, and Windows attribute metadata for a selected verified entry.
Native LZMA extraction accepts stored
lc/lp/pb and dictionary metadata for supported property combinations. Native
LZMA2 extraction accepts compressed, uncompressed, reset/properties,
state-reset, and state-continuing chunks for supported lc/lp/pb properties in
the single-folder layout. Supported extraction also accepts covered solid
substreams, BCJ2 graph layouts with Copy or supported main pre-coders, and
bounded linear filter-chain layouts made from supported single-input coders and
supported branch/Delta filters, including standard zero-based, reverse-linear,
reordered zero-based, and legacy one-based linear bind pairs. File and
file-list extraction helpers create needed parent
directories and restore supported per-entry directories, modification times,
and read-only attributes after writing output paths.
Extract_Seven_Zip_Stored_Files extracts selected entries into an output
directory after requiring a non-empty destination and prevalidating distinct
requested names, and rejects unsafe absolute or traversing entry paths before
writing. It verifies all requested payloads before writing any output file.
Extract_Seven_Zip_Files has the same staging and path-safety behavior, and
unsupported 7z methods fail closed after native extraction returns
Unsupported_Method. ZIP BZip2
and Zstandard creation and unencrypted extraction for
classic and ZIP64 metadata use in-process payload handling backed by libbz2 and
libzstd. ZIP method 14 LZMA uses an in-tree range coder, literal coder, and
normal-match distance coding including pos-special, direct-bit, and align-bit
distances plus rep matches emitted by this library.
Unsupported broader 7z creation, extraction, and layouts outside the native
supported set fail closed with deterministic status codes. Use the native
password overloads for supported AES-encrypted 7z payloads and encrypted
headers.
The one-shot API is status-code based and binary-safe: input and output are
byte arrays, not strings. Inflate uses lightweight wrapper auto-detection for
complete zlib, gzip, and raw Deflate streams. Inflate_With_Header with
Header => Default has the same implicit behavior; concrete header values
(Zlib_Header, GZip, Raw_Deflate) keep strict wrapper boundaries.
Inflate_Auto remains an explicit alias for the same one-shot discrimination.
with Zlib;
procedure Example is
Status : Zlib.Status_Code;
Plain : constant Zlib.Byte_Array :=
[1 => 16#68#, 2 => 16#65#, 3 => 16#6C#, 4 => 16#6C#, 5 => 16#6F#];
ZData : constant Zlib.Byte_Array := Zlib.Deflate (Plain, Status => Status);
Back : constant Zlib.Byte_Array := Zlib.Inflate (ZData, Status);
begin
null;
end Example;The streaming API is exception-based. Status_Error indicates caller lifecycle
misuse. Zlib_Error indicates malformed, truncated, unsupported, or
validation-failed compressed data.
type Filter_Type is limited private;
type Header_Type is (Default, Zlib_Header, GZip, Raw_Deflate);
type Flush_Mode is (No_Flush, Sync_Flush, Full_Flush, Finish);
Zlib_Error : exception;
Status_Error : exception;
procedure Inflate_Init (Filter : in out Filter_Type; Header : Header_Type := Default);
function Is_Open (Filter : Filter_Type) return Boolean;
procedure Translate (...);
procedure Flush (...);
function Stream_End (Filter : Filter_Type) return Boolean;
procedure Close (Filter : in out Filter_Type; Ignore_Error : Boolean := False);For one-shot and streaming inflate, Default auto-detects zlib, gzip, or raw
Deflate input. Gzip input accepts concatenated members by default in both
one-shot and streaming gzip modes. For streaming compression, Default remains
the zlib wrapper default. Zlib_Header selects a zlib wrapper plus Adler-32
trailer. GZip selects gzip member syntax and validates CRC32/ISIZE.
Raw_Deflate accepts a Deflate payload without wrapper bytes or trailer
checksum. Deflate_Stored,
Deflate_Fixed, Deflate_Dynamic, Deflate, and their
file helpers emit zlib-wrapped output. GZip and GZip_File emit gzip-wrapped
output. Deflate_Raw, Deflate_Raw_File, and streaming Header => Raw_Deflate emit raw Deflate payload bytes only.
alr build
alr exec -- gnatls --version
alr exec -- gprbuild -P zlib.gpr
alr exec -- gnatprove -P zlib.gpr --level=4
alr test
cd tests && alr exec -- gprbuild -P tests.gpr
cd tests && ./bin/tests
alr exec -- gprbuild -P examples/examples.gpr
cd tools && alr build
cd check_zlib && alr build && ./bin/check_zlib && cd ..
./tools/bin/smoke_test
./tools/bin/seven_zip_interop_check
tools/bin/check_allValidation is tied to Alire GNAT 15. The crate manifests require
gnat_native = "^15", and the release guards check that
alr exec -- gnatls --version reports GNATLS 15.x. Do not run plain system
gnat*, gnatprove, or gprbuild for validation; those may resolve to an
older compiler outside Alire.
tools/bin/check_all runs the same checklist where the required tools are
available, including the check_zlib release documentation guard.
tools/bin/seven_zip_interop_check is an optional stock-7z lane for method,
filter, corpus, file-list directory, BCJ2, solid, encrypted, and multi-volume
coverage, including encrypted listing and wrong-password checks. It probes the
stock RISCV filter and runs RISC-V cases when available; it skips
successfully when 7z is not on PATH.
The crate metadata currently declares licenses = "MIT OR Apache-2.0 WITH LLVM-exception".
The repository LICENSE file contains the MIT license text, the full Apache
License 2.0 text, and the LLVM exception text matching that expression. Before
publishing a package, run tools/bin/check_all from the repository root and
ensure check_zlib passes and the run ends with zlib release checklist passed.
docs/AI_GUIDE.md— AI-agent discoverability, safe entry points, and maintenance rulesdocs/API_CHEATSHEET.md— compact task-to-public-API mappingdocs/QUICKSTART.md— first build, one-shot, gzip, raw, file, and validation examplesdocs/API.md— public root-package API summarydocs/USAGE.md— short usage examples for one-shot and streaming callersdocs/STREAMING.md— streaming inflate lifecycle and wrapper contractdocs/STREAMING_COMPRESSION.md— streaming compression lifecycle, flushes, wrappers, levels, dictionariesdocs/ERRORS.md— status/exception mapping and lifecycle failuresdocs/GZIP.md— gzip inflate/output wrapper policy, metadata, multi-member input, CRC32docs/GZIP_OUTPUT.md— gzip output shape, metadata emission, determinismdocs/COMPRESSION.md— compression modes, levels, output contract, dictionaries, checksumsdocs/RAW_DEFLATE.md— raw Deflate usage and wrapper comparisondocs/RAW_COMPRESSION.md— raw compression matrix and lifecycle notesdocs/CONSUMERS.md— integration notes forversion,HttpClient, and other Ada toolsdocs/TESTING.md— test organization, release checklist, fuzz smoke policydocs/FUZZING.md— deterministic fuzzing tools, seeds, pass/fail policydocs/BENCHMARKS.md— optional benchmark/profiling guidancedocs/ARCHITECTURE.md— internal package overviewdocs/MAINTENANCE.md— long-term maintenance rulesdocs/CONSTRAINTS.md— explicit scope constraintsdocs/ROADMAP.md— controlled maintenance path and future workdocs/SEVEN_ZIP_PLAN.md— ordered implementation plan toward full 7z encode/decodedocs/SPARK.md— SPARK-enabled units and GNATprove release command
Examples under examples/ compile against the public root package only. Checked examples include examples/quickstart.adb, examples/streaming_deflate_zlib.adb, examples/streaming_deflate_raw.adb, examples/gzip_with_metadata.adb, and examples/dictionary_roundtrip.adb. The standalone mains are:
checksums.adbcompress_with_level.adbdeflate_file_streaming.adbdeflate_raw_file.adbdeflate_raw_file_to_stream.adbdeflate_raw_file_streaming.adbdeflate_stored_file.adbdeflate_fixed_file.adbdeflate_dynamic_file.adbdictionary_roundtrip.adbgzip_file.adbgzip_file_streaming.adbgzip_multimember_inflate.adbgzip_with_metadata.adbinflate_file.adbinflate_file_streaming.adbinflate_raw.adbinflate_raw_file.adbinflate_raw_file_streaming.adbinflate_with_header.adbraw_roundtrip.adbraw_vs_zlib_vs_gzip.adbroundtrip_stored.adbroundtrip_fixed.adbroundtrip_dynamic.adbstreaming_deflate_zlib.adbstreaming_deflate_gzip.adbstreaming_deflate_raw.adbstreaming_inflate_zlib.adbstreaming_inflate_gzip.adbstreaming_roundtrip_zlib.adbstreaming_roundtrip_gzip.adbexample_raw_support.adb/example_raw_support.adssupport raw-example cleanup code
Tools under tools/ are small command-line utilities using only public Zlib, except the
deterministic fuzz drivers which use the internal deterministic Zlib.Fuzzing helper package:
zlib_inflate_file.adbzlib_deflate_stored_file.adbzlib_deflate_fixed_file.adbzlib_deflate_dynamic_file.adbzlib_compress_file.adbzlib_streaming_roundtrip.adbgzip_file.adbgzip_metadata_file.adbgzip_streaming_roundtrip.adbraw_deflate_file.adbraw_inflate_file.adbraw_roundtrip.adbraw_vs_zlib_vs_gzip.adbzlib_bench_inflate.adboptional inflate benchmarkzlib_bench_deflate.adboptional zlib/gzip/raw compression benchmarkzlib_bench_gzip.adboptional gzip-default compression benchmarkzlib_bench_raw.adboptional raw-default compression benchmarkzlib_bench_matrix.adboptional compact compression benchmark matrixseven_zip_interop_check.adboptional stock-7z interoperability checktools/fuzz/fuzz_inflate.adbtools/fuzz/fuzz_streaming_inflate.adbtools/fuzz/fuzz_compress_roundtrip.adbtools/fuzz/fuzz_compress_levels.adbtools/fuzz/fuzz_wrapper_mix.adbtools/fuzz/fuzz_dictionary.adbtools/fuzz/fuzz_gzip_metadata.adbtools/fuzz/fuzz_mutation.adbtools/fuzz/fuzz_flush.adbtools/fuzz/fuzz_lifecycle.adbtools/fuzz/fuzz_tiny_buffers.adbsmoke_test.adbcheck_all.adbcheck_zlib
This repository includes explicit AI-facing entry points so automated coding assistants can find the public API and avoid internal packages:
llms.txt— compact repository summary for language-model consumersAGENTS.md— repository maintenance rules for coding agentsdocs/AI_GUIDE.md— detailed AI integration and safe-change guidedocs/API_CHEATSHEET.md— task-to-API lookup table
The rule for generated examples, downstream integrations, and AI-authored code
is simple: import only with Zlib; unless the task is explicitly internal crate
maintenance. src/zlib.ads remains the source of truth for the public API.
This release is a maintenance-ready zlib/Deflate crate with conservative,
deterministic zlib, gzip, and raw Deflate output support. Deflate_Stored
remains the compatibility/no-compression zlib writer. Deflate_Fixed emits
fixed-Huffman zlib streams. Deflate_Dynamic emits deterministic
dynamic-Huffman zlib streams through the same block-local streaming compression
engine used by explicit streaming Dynamic. Deflate adds a zlib-wrapper policy layer, and
Deflate_Raw adds the corresponding raw Deflate payload policy. Explicit modes
select the requested block policy; Auto is deterministic and block-local for
streaming/raw output. Compression levels provide a broad effort policy while
preserving deterministic output.
The crate does not implement a performance rewrite, new HttpClient APIs, a new
version object model, or broad wrapper guessing on strict APIs. The
root-package zlib/gzip/raw Deflate surface is maintenance-ready, and the
general-purpose, pure-Ada 7z codec stack is substantially implemented — see
docs/SEVEN_ZIP_PLAN.md for the remaining validation and tuning boundary.
Verified native PPMd
.7z output is available through Seven_Zip_PPMd,
Seven_Zip_PPMd_File, and Seven_Zip_PPMd_Files without calling a local
7z executable. ZIP output is available through ZIP,
ZIP_File, and ZIP_Files; ZIP_Files can emit multi-entry ZIP archives and
explicit ZIP64 metadata. Convenience wrapper-discriminating inflate is available
through Inflate_Auto, and multi-member gzip output is available through
GZip_Members and GZip_File_Members. Gzip input accepts concatenated members
by default; strict single-member input is available through APIs that take
GZip_Member_Mode. Raw Deflate output is available through Deflate_Raw,
Deflate_Raw_File, and streaming Header => Raw_Deflate, Mode => Stored|Fixed|Dynamic|Auto; it is still only a payload for external containers
or protocols that supply framing and integrity checks.
Wrapper behavior is explicit for concrete modes, with inflate auto-detection on the default path:
- one-shot
Inflate,Inflate_With_Header (..., Header => Default, ...), and streamingInflate_Init (..., Header => Default)auto-detect zlib, gzip, or raw Deflate input, with concatenated gzip members accepted by default; Inflate_Autois an explicit alias for that one-shot behavior;- concrete headers
Zlib_Header,GZip, andRaw_Deflateremain wrapper-strict; passGZip_Mode => Single_Memberto reject concatenated gzip members in one-shot or streaming gzip input; - streaming inflate
Defaultauto-detects zlib, gzip, or raw Deflate input; - streaming compression keeps
DefaultasZlib_Header; - all
Deflate_*andDeflateoutputs are zlib-wrapped; GZipandGZip_Fileoutputs are gzip-wrapped; defaults use a deterministic minimal header;- optional gzip metadata is emitted only through explicit metadata overloads;
Raw_Deflateinput/output is Deflate payload only and has no checksum trailer;GZipvalidates CRC32 and ISIZE for each gzip member during inflate;Zlib_Headervalidates Adler-32.CryptoLib.Checksumssupplies internal Adler-32 and CRC32 calculation, andDeflate_Bound,GZip_Bound, andDeflate_Raw_Boundexpose conservative one-shot output-size bounds.
The release checklist builds the crate, tests, examples, and tools, then runs the AUnit suite and command-line smoke test. No runtime fixture generation or system zlib dependency is part of the normal release path.
The public root package now supports completed one-shot and streaming compression for zlib, gzip, and raw Deflate output.
Supported streaming compression combinations are:
Header => Default / Zlib_Header,Mode => StoredHeader => Default / Zlib_Header,Mode => FixedHeader => Default / Zlib_Header,Mode => DynamicHeader => Default / Zlib_Header,Mode => AutoHeader => GZip,Mode => StoredHeader => GZip,Mode => FixedHeader => GZip,Mode => DynamicHeader => GZip,Mode => AutoHeader => Raw_Deflate,Mode => StoredHeader => Raw_Deflate,Mode => FixedHeader => Raw_Deflate,Mode => DynamicHeader => Raw_Deflate,Mode => Auto
For streaming compression, Default is exactly Zlib_Header. Raw compression
emits Deflate blocks only: no zlib header, no Adler-32 footer, no gzip header,
no CRC32 trailer, and no ISIZE trailer. Auto is deterministic and block-local.
Compression levels are available as broad effort policy. One-shot Inflate,
Inflate_With_Header (..., Default, ...), and Inflate_Auto provide
lightweight wrapper-discriminating convenience; gzip input concatenates members
by default, while concrete header values remain wrapper-strict.
Multi-member gzip output and ZIP output are available through their explicit
APIs. Broader unsupported 7z extraction fails closed. Optional gzip metadata
output is available through explicit
metadata overloads only; default gzip output remains minimal.
See:
docs/STREAMING_COMPRESSION.mddocs/GZIP_OUTPUT.mdexamples/streaming_deflate_zlib.adbexamples/streaming_deflate_gzip.adbexamples/streaming_roundtrip_zlib.adbexamples/streaming_roundtrip_gzip.adbexamples/streaming_deflate_raw.adbexamples/raw_roundtrip.adbexamples/raw_vs_zlib_vs_gzip.adb
Useful validation commands:
alr exec -- gprbuild -P examples/examples.gpr
cd tools && alr build
cd check_zlib && alr build && ./bin/check_zlib && cd ..
./tools/bin/smoke_test
tools/bin/check_allRaw Deflate compression is now part of the public API through Deflate_Raw,
Deflate_Raw_File, Deflate_Raw_File_Size,
Deflate_Raw_File_To_Stream, and streaming Deflate_Init (Header => Raw_Deflate, ...). Raw output is Deflate block data only: it has no zlib
header/Adler-32 trailer and no gzip header/CRC32/ISIZE trailer.
Deflate_Raw_File_Size and Deflate_Raw_File_To_Stream support container
writers that need exact raw payload sizes or need to write into an already-open
output stream. Use raw
Deflate only when an outer protocol or container supplies framing and integrity
checks. See docs/RAW_DEFLATE.md and docs/RAW_COMPRESSION.md.
Examples and tools for raw output are included in examples/streaming_deflate_raw.adb,
examples/deflate_raw_file.adb, examples/deflate_raw_file_to_stream.adb, examples/inflate_raw_file.adb,
examples/deflate_raw_file_streaming.adb, examples/inflate_raw_file_streaming.adb,
examples/raw_roundtrip.adb, examples/raw_vs_zlib_vs_gzip.adb,
tools/raw_deflate_file.adb, tools/raw_roundtrip.adb, and
tools/raw_vs_zlib_vs_gzip.adb.
Raw Deflate compression is release-hardened by zlib_raw_release_tests,
zlib_raw_cross_wrapper_conformance_tests, the raw examples, and the raw tools.
The contract remains unchanged for output: Deflate_* APIs emit zlib-wrapped streams, GZip* APIs emit
gzip-wrapped streams, and Deflate_Raw* APIs emit raw Deflate blocks only.
One-shot Inflate, Inflate_With_Header (..., Default, ...), and
Inflate_Auto auto-detect zlib/gzip/raw input; gzip input accepts
concatenated members unless GZip_Mode => Single_Member is requested. Concrete
Inflate_With_Header headers remain wrapper-strict. Auto remains deterministic and block-local. Native .7z
creation and extraction cover the supported pure-Ada method set without calling
a local 7z executable.
Sync_Flush forces currently buffered compression input into the Deflate stream without ending it.
It finishes the current block as non-final and emits an empty non-final stored block on a byte
boundary. Full_Flush currently has the same byte-level behavior because the compressor has no
cross-block match history; the distinction is preserved in the API and tests. Neither mode emits
zlib/gzip trailers, and Compress_Stream_End remains False until Finish. Flush output may
require repeated drain calls with small output buffers. Finish after a partially drained flush
completes the pending flush work and then finalizes the stream. After stream end, Sync_Flush and
Full_Flush are lifecycle misuse and raise Status_Error. Streaming inflate treats Sync_Flush
and Full_Flush as No_Flush; Deflate flush markers are ordinary stored blocks.