deflate Fixed Compress() - > Result<Bytes, string>- 수신자
- Bytes
- 최소 인자 수
- 0
- 최대 인자 수
- 0
Declaration and parameters
링크사용 조건
기본 포함 · 미정
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.
수신자
Bytes
매개변수 제약
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.
관련 규칙 · Distinguish raw DEFLATE from zlib framing →결과
The declared result type is Result<Bytes, string>.
효과
실패
Result and effects
링크Return one final fixed Huffman DEFLATE block in Ok. Input beyond 268435456 bytes returns Err.
Resolved contracts
링크Related entries
링크Distinguish raw DEFLATE from zlib framing
링크Distinguish 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.
이유
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.
Recover bytes from a raw stream
링크import 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
기대 결과
기대 결과
실행을 마칩니다. 종료 코드 0.
68656c6c6f03007801030000000001
Decode a valid fixed Huffman stream
링크import 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
기대 결과
기대 결과
실행을 마칩니다. 종료 코드 0.
68656c6c6f
Decode short nonfinal stored blocks
링크import 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
기대 결과
기대 결과
실행을 마칩니다. 종료 코드 0.
4142
Ignore stored block alignment bits
링크import 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
기대 결과
기대 결과
실행을 마칩니다. 종료 코드 0.
41
Reject truncated streams and trailing bytes
링크import 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
기대 결과
기대 결과
실행을 마칩니다. 종료 코드 0.
invalid DEFLATEinvalid DEFLATEinvalid DEFLATEinvalid DEFLATE