deflate Fixed Compress() - > Result<Bytes, string>- Module
- std.
bytes - Receiver
- Bytes
- Minimum arity
- 0
- Maximum arity
- 0
Declaration and parameters
LinkAvailability
Included by default: Pending
Import std.bytes in language mode 5.21.
The current compiler selects std/bytes.tpz for this language mode. Availability in other released editions and inclusion in each installed distribution are Pending.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1272 - compiler/crates/topaz_resolve/src/stdlib.rs at
b48527d0a174· 52 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1272 - compiler/crates/topaz_self_frontend/topaz/checker/builtin_signatures.tpz at
b48527d0a174· 519 - compiler/crates/topaz_self_frontend/topaz/checker/members_capabilities.tpz at
b48527d0a174· 1296 - compiler/crates/topaz_value/src/value/members.rs at
b48527d0a174· 235
Receiver
Bytes
Parameter constraints
Bytes.deflateCompress returns Ok with one complete raw RFC 1951 DEFLATE stream. It adds no zlib or gzip header or checksum.
Bytes.deflateFixedCompress returns Ok with one final fixed Huffman block. Empty input is valid and the final unused bits are zero.
Fixed Huffman compression accepts at most 268435456 input bytes. Larger inputs return Err with a string before producing output.
Bytes.zlibFixedCompress applies the same fixed Huffman compression and input bound, with an RFC 1950 zlib header and Adler-32 trailer.
The zlib stream declares a 32768-byte window and no preset dictionary. Its header bytes are 0x78 and 0x01.
Bytes.deflateDecompress accepts raw streams containing stored, fixed Huffman, and dynamic Huffman blocks. It reconstructs the original bytes in Ok.
The decoder consumes one complete stream. Malformed or truncated blocks, invalid back-references, and complete trailing bytes return Err with a string.
Final unused padding bits are not decoded as data. A zlib or gzip wrapper is not a raw DEFLATE stream.
Bytes.deflateDecompress reverses either raw compressor for every supported input. Bytes.zlibFixedCompress requires a zlib decoder because its wrapper is part of the result.
Each receiver evaluates once and remains unchanged. The operations perform no I/O and errors expose no partially decoded Bytes.
Compression does not promise a particular size reduction. Except for the fixed block and wrapper requirements, encoded byte choices may change while preserving the stream format.
Related rule: Distinguish raw DEFLATE from zlib framingResult
The declared result type is Result<Bytes, string>.
Effects
Failures
Result and effects
LinkReturn one final fixed Huffman DEFLATE block in Ok. Input beyond 268435456 bytes returns Err.
Resolved contracts
LinkRelated entries
LinkDistinguish raw DEFLATE from zlib framing
LinkDistinguish raw DEFLATE from zlib framing
Bytes.deflateCompress returns Ok with one complete raw RFC 1951 DEFLATE stream. It adds no zlib or gzip header or checksum.
Bytes.deflateFixedCompress returns Ok with one final fixed Huffman block. Empty input is valid and the final unused bits are zero.
Fixed Huffman compression accepts at most 268435456 input bytes. Larger inputs return Err with a string before producing output.
Bytes.zlibFixedCompress applies the same fixed Huffman compression and input bound, with an RFC 1950 zlib header and Adler-32 trailer.
The zlib stream declares a 32768-byte window and no preset dictionary. Its header bytes are 0x78 and 0x01.
Bytes.deflateDecompress accepts raw streams containing stored, fixed Huffman, and dynamic Huffman blocks. It reconstructs the original bytes in Ok.
The decoder consumes one complete stream. Malformed or truncated blocks, invalid back-references, and complete trailing bytes return Err with a string.
Final unused padding bits are not decoded as data. A zlib or gzip wrapper is not a raw DEFLATE stream.
Bytes.deflateDecompress reverses either raw compressor for every supported input. Bytes.zlibFixedCompress requires a zlib decoder because its wrapper is part of the result.
Each receiver evaluates once and remains unchanged. The operations perform no I/O and errors expose no partially decoded Bytes.
Compression does not promise a particular size reduction. Except for the fixed block and wrapper requirements, encoded byte choices may change while preserving the stream format.
Why
Raw DEFLATE and zlib are different wire formats. The fixed Huffman operation additionally specifies block coding, so it serves a distinct format requirement rather than another name for a general compressor.
Source evidence
- compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 203 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 512 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 540 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 662 - docs/topaz-v5.9/SPEC.md at
912a5e86e1f9· 2917 -
topaz.stdlib.contract.bytes-deflateatworking-tree - topaz.decision.bytes-compression-streams.1 at
topaz.decisi
Recover bytes from a raw stream
Linkimport std.ioimport std.testlet encoded = test.assertOk("hello".encodeUtf8().deflateCompress())io.writeLine(test.assertOk(encoded.deflateDecompress()).toHex())io.writeLine(test.assertOk("".encodeUtf8().deflateFixedCompress()).toHex())io.writeLine(test.assertOk("".encodeUtf8().zlibFixedCompress()).toHex())
68656c6c6f 0300 7801030000000001
Expected result
Expected result
Execution completes. Exit code 0.
68656c6c6f03007801030000000001
Source evidence
- compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 203 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 512 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 540 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 662 - docs/topaz-v5.9/SPEC.md at
912a5e86e1f9· 2917 -
topaz.stdlib.contract.bytes-deflateatworking-tree - topaz.decision.bytes-compression-streams.1 at
topaz.decisi
Decode a valid fixed Huffman stream
Linkimport std.bytes { Bytes }import std.ioimport std.testlet encoded = test.assertOk(Bytes.fromHex("cb48cdc9c90700"))match (encoded.deflateDecompress()) {case Ok(bytes) => io.writeLine(bytes.toHex())case Err(_) => io.writeLine("rejected")}
68656c6c6f
Expected result
Expected result
Execution completes. Exit code 0.
68656c6c6f
Source evidence
- compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 203 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 512 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 540 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 662 - docs/topaz-v5.9/SPEC.md at
912a5e86e1f9· 2917 -
topaz.stdlib.contract.bytes-deflateatworking-tree - topaz.decision.bytes-compression-streams.1 at
topaz.decisi
Decode short nonfinal stored blocks
Linkimport std.bytes { Bytes }import std.ioimport std.testlet encoded = test.assertOk(Bytes.fromHex("000100feff41010100feff42"))match (encoded.deflateDecompress()) {case Ok(bytes) => io.writeLine(bytes.toHex())case Err(_) => io.writeLine("rejected")}
4142
Expected result
Expected result
Execution completes. Exit code 0.
4142
Source evidence
- compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 203 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 512 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 540 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 662 - docs/topaz-v5.9/SPEC.md at
912a5e86e1f9· 2917 -
topaz.stdlib.contract.bytes-deflateatworking-tree - topaz.decision.bytes-compression-streams.1 at
topaz.decisi
Ignore stored block alignment bits
Linkimport std.bytes { Bytes }import std.ioimport std.testlet encoded = test.assertOk(Bytes.fromHex("f90100feff41"))match (encoded.deflateDecompress()) {case Ok(bytes) => io.writeLine(bytes.toHex())case Err(_) => io.writeLine("rejected")}
41
Expected result
Expected result
Execution completes. Exit code 0.
41
Source evidence
- compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 203 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 512 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 540 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 662 - docs/topaz-v5.9/SPEC.md at
912a5e86e1f9· 2917 -
topaz.stdlib.contract.bytes-deflateatworking-tree - topaz.decision.bytes-compression-streams.1 at
topaz.decisi
Reject truncated streams and trailing bytes
Linkimport std.bytes { Bytes }import std.ioimport std.testfor hex in (["", "010100feff", "010000ffff00", "070000"]) {match (test.assertOk(Bytes.fromHex(hex)).deflateDecompress()) {case Err(_) => io.writeLine("invalid DEFLATE")case Ok(_) => io.writeLine("accepted")}}
invalid DEFLATE invalid DEFLATE invalid DEFLATE invalid DEFLATE
Expected result
Expected result
Execution completes. Exit code 0.
invalid DEFLATEinvalid DEFLATEinvalid DEFLATEinvalid DEFLATE
Source evidence
- compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 203 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 512 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 540 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 662 - docs/topaz-v5.9/SPEC.md at
912a5e86e1f9· 2917 -
topaz.stdlib.contract.bytes-deflateatworking-tree - topaz.decision.bytes-compression-streams.1 at
topaz.decisi