gzip Decompress() - > 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· 233
Receiver
Bytes
Parameter constraints
Bytes.gzipCompress returns Ok with one RFC 1952 gzip member containing the receiver bytes. Empty input is valid.
The compressor does not read a clock or derive a filename from its environment. The header timestamp is zero and optional name and comment fields are absent.
Bytes.gzipDecompress accepts one member with compression method DEFLATE, including valid timestamp, operating system, extra field, name, comment, and header CRC fields.
The decoder accepts stored, fixed Huffman, and dynamic Huffman DEFLATE blocks. It validates the member CRC-32 and uncompressed size modulo 4294967296.
Reserved header flags, malformed optional fields, invalid compressed data, checksum mismatches, and truncation return Err with a string.
A second member or other bytes after the member return Err. A Bytes value represents one complete compressed payload in this API.
Decoding a successfully compressed value recovers the original bytes. A decoder failure never exposes a prefix of the output.
The receiver evaluates once and remains unchanged. Compression and decompression perform no I/O and do not decode the payload as text.
Related rule: Read and write complete gzip membersResult
The declared result type is Result<Bytes, string>.
Effects
Failures
Result and effects
LinkDecode one complete gzip member and validate its header, DEFLATE blocks, CRC-32, and uncompressed size.
Resolved contracts
LinkRelated entries
LinkRead and write complete gzip members
LinkRead and write complete gzip members
Bytes.gzipCompress returns Ok with one RFC 1952 gzip member containing the receiver bytes. Empty input is valid.
The compressor does not read a clock or derive a filename from its environment. The header timestamp is zero and optional name and comment fields are absent.
Bytes.gzipDecompress accepts one member with compression method DEFLATE, including valid timestamp, operating system, extra field, name, comment, and header CRC fields.
The decoder accepts stored, fixed Huffman, and dynamic Huffman DEFLATE blocks. It validates the member CRC-32 and uncompressed size modulo 4294967296.
Reserved header flags, malformed optional fields, invalid compressed data, checksum mismatches, and truncation return Err with a string.
A second member or other bytes after the member return Err. A Bytes value represents one complete compressed payload in this API.
Decoding a successfully compressed value recovers the original bytes. A decoder failure never exposes a prefix of the output.
The receiver evaluates once and remains unchanged. Compression and decompression perform no I/O and do not decode the payload as text.
Why
Standard header and block handling allows gzip data to move between programs. Requiring one complete member prevents unconsumed suffixes from being silently discarded.
Source evidence
- compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 81 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 118 -
topaz.stdlib.contract.bytes-gzipatworking-tree - topaz.decision.bytes-compression-streams.1 at
topaz.decisi
Recover empty and nonempty payloads
Linkimport std.ioimport std.testfor text in (["", "hello"]) {let encoded = test.assertOk(text.encodeUtf8().gzipCompress())io.writeLine(test.assertOk(encoded.gzipDecompress()).toHex())}
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· 81 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 118 -
topaz.stdlib.contract.bytes-gzipatworking-tree - topaz.decision.bytes-compression-streams.1 at
topaz.decisi
Accept ordinary gzip header metadata
Linkimport std.bytes { Bytes }import std.ioimport std.testlet encoded = test.assertOk(Bytes.fromHex("1f8b0800010000000003010500faff68656c6c6f86a6103605000000"))match (encoded.gzipDecompress()) {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· 81 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 118 -
topaz.stdlib.contract.bytes-gzipatworking-tree - topaz.decision.bytes-compression-streams.1 at
topaz.decisi
Accept compressed gzip blocks
Linkimport std.bytes { Bytes }import std.ioimport std.testlet encoded = test.assertOk(Bytes.fromHex("1f8b08000000000000ffcb48cdc9c9070086a6103605000000"))match (encoded.gzipDecompress()) {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· 81 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 118 -
topaz.stdlib.contract.bytes-gzipatworking-tree - topaz.decision.bytes-compression-streams.1 at
topaz.decisi
Reject a truncated member and an invalid checksum
Linkimport std.bytes { Bytes }import std.ioimport std.testfor hex in (["1f8b0800", "1f8b08000000000000ff010500faff68656c6c6f87a6103605000000"]) {match (test.assertOk(Bytes.fromHex(hex)).gzipDecompress()) {case Err(_) => io.writeLine("invalid gzip")case Ok(_) => io.writeLine("accepted")}}
invalid gzip invalid gzip
Expected result
Expected result
Execution completes. Exit code 0.
invalid gzipinvalid gzip
Source evidence
- compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 81 - compiler/crates/topaz_value/src/value/builtins/hash_codec.rs at
912a5e86e1f9· 118 -
topaz.stdlib.contract.bytes-gzipatworking-tree - topaz.decision.bytes-compression-streams.1 at
topaz.decisi