본문으로 건너뛰기
토파즈6.0 · 출시 전
다운로드 →

문서 검색

명세 6.0

방향키로 결과를 고르고 Enter를 눌러 여세요.

API 이름, 진단 번호, 규칙 또는 프로젝트 주제를 입력하세요.

    라이브러리 · std.bytes

    Bytes.deflateDecompress

    Decompresses a DEFLATE byte sequence.

    deflateDecompress() -> 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.

    결과

    The declared result type is Result<Bytes, string>.

    효과

    실패

    Result and effects

    링크

    Decode one complete raw DEFLATE stream. Invalid blocks, truncation, or trailing bytes return Err without partial output.

    Resolved contracts

    링크

    Related entries

    링크

    std.bytes →

    Distinguish raw DEFLATE from zlib framing

    링크
    규칙topaz.stdlib.contract.bytes-deflate.rule

    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

    링크
    main.tpzRecover bytes from a raw stream플레이그라운드 열기 →
    1. import std.io
    2. import std.test
    3. let encoded = test.assertOk("hello".encodeUtf8().deflateCompress())
    4. io.writeLine(test.assertOk(encoded.deflateDecompress()).toHex())
    5. io.writeLine(test.assertOk("".encodeUtf8().deflateFixedCompress()).toHex())
    6. io.writeLine(test.assertOk("".encodeUtf8().zlibFixedCompress()).toHex())
    기대 출력종료 코드 0
    68656c6c6f
    0300
    7801030000000001
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    실행을 마칩니다. 종료 코드 0.

    기대 표준 출력
    1. 68656c6c6f
    2. 0300
    3. 7801030000000001

    Decode a valid fixed Huffman stream

    링크
    main.tpzDecode a valid fixed Huffman stream플레이그라운드 열기 →
    1. import std.bytes { Bytes }
    2. import std.io
    3. import std.test
    4. let encoded = test.assertOk(Bytes.fromHex("cb48cdc9c90700"))
    5. match (encoded.deflateDecompress()) {
    6. case Ok(bytes) => io.writeLine(bytes.toHex())
    7. case Err(_) => io.writeLine("rejected")
    8. }
    기대 출력종료 코드 0
    68656c6c6f
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    실행을 마칩니다. 종료 코드 0.

    기대 표준 출력
    1. 68656c6c6f

    Decode short nonfinal stored blocks

    링크
    main.tpzDecode short nonfinal stored blocks플레이그라운드 열기 →
    1. import std.bytes { Bytes }
    2. import std.io
    3. import std.test
    4. let encoded = test.assertOk(Bytes.fromHex("000100feff41010100feff42"))
    5. match (encoded.deflateDecompress()) {
    6. case Ok(bytes) => io.writeLine(bytes.toHex())
    7. case Err(_) => io.writeLine("rejected")
    8. }
    기대 출력종료 코드 0
    4142
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    실행을 마칩니다. 종료 코드 0.

    기대 표준 출력
    1. 4142

    Ignore stored block alignment bits

    링크
    main.tpzIgnore stored block alignment bits플레이그라운드 열기 →
    1. import std.bytes { Bytes }
    2. import std.io
    3. import std.test
    4. let encoded = test.assertOk(Bytes.fromHex("f90100feff41"))
    5. match (encoded.deflateDecompress()) {
    6. case Ok(bytes) => io.writeLine(bytes.toHex())
    7. case Err(_) => io.writeLine("rejected")
    8. }
    기대 출력종료 코드 0
    41
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    실행을 마칩니다. 종료 코드 0.

    기대 표준 출력
    1. 41

    Reject truncated streams and trailing bytes

    링크
    main.tpzReject truncated streams and trailing bytes플레이그라운드 열기 →
    1. import std.bytes { Bytes }
    2. import std.io
    3. import std.test
    4. for hex in (["", "010100feff", "010000ffff00", "070000"]) {
    5. match (test.assertOk(Bytes.fromHex(hex)).deflateDecompress()) {
    6. case Err(_) => io.writeLine("invalid DEFLATE")
    7. case Ok(_) => io.writeLine("accepted")
    8. }
    9. }
    기대 출력종료 코드 0
    invalid DEFLATE
    invalid DEFLATE
    invalid DEFLATE
    invalid DEFLATE
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

    실행을 마칩니다. 종료 코드 0.

    기대 표준 출력
    1. invalid DEFLATE
    2. invalid DEFLATE
    3. invalid DEFLATE
    4. invalid DEFLATE

    메뉴

    다운로드 →