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

문서 검색

명세 6.0

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

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

    라이브러리 · std.bytes

    Bytes.gzipCompress

    Compresses this byte sequence in gzip format.

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

    결과

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

    효과

    실패

    Result and effects

    링크

    Return one gzip member in Ok with a zero timestamp and no ambient filename or comment.

    Resolved contracts

    링크

    Related entries

    링크

    std.bytes →

    Read and write complete gzip members

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

    Read 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.

    이유

    Standard header and block handling allows gzip data to move between programs. Requiring one complete member prevents unconsumed suffixes from being silently discarded.

    Recover empty and nonempty payloads

    링크
    main.tpzRecover empty and nonempty payloads플레이그라운드 열기 →
    1. import std.io
    2. import std.test
    3. for text in (["", "hello"]) {
    4. let encoded = test.assertOk(text.encodeUtf8().gzipCompress())
    5. io.writeLine(test.assertOk(encoded.gzipDecompress()).toHex())
    6. }
    기대 출력종료 코드 0
    
    68656c6c6f
    
    $ topaz run main.tpz · 대상 제품 5.21.3
    기대 결과

    기대 결과

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

    기대 표준 출력
    1. 68656c6c6f

    Accept ordinary gzip header metadata

    링크
    main.tpzAccept ordinary gzip header metadata플레이그라운드 열기 →
    1. import std.bytes { Bytes }
    2. import std.io
    3. import std.test
    4. let encoded = test.assertOk(Bytes.fromHex("1f8b0800010000000003010500faff68656c6c6f86a6103605000000"))
    5. match (encoded.gzipDecompress()) {
    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

    Accept compressed gzip blocks

    링크
    main.tpzAccept compressed gzip blocks플레이그라운드 열기 →
    1. import std.bytes { Bytes }
    2. import std.io
    3. import std.test
    4. let encoded = test.assertOk(Bytes.fromHex("1f8b08000000000000ffcb48cdc9c9070086a6103605000000"))
    5. match (encoded.gzipDecompress()) {
    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

    Reject a truncated member and an invalid checksum

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

    기대 결과

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

    기대 표준 출력
    1. invalid gzip
    2. invalid gzip

    메뉴

    다운로드 →