@blockchaincommons/components - v1.0.0-beta.4
    Preparing search index...

    Class Compressed

    A compressed binary object with integrity verification.

    Uses DEFLATE compression with CRC32 checksums for integrity verification. Optionally includes a cryptographic digest for content identification.

    Implements

    Index
    • get compressedSize(): number

      Returns the size of the compressed data in bytes.

      Returns number

    • get decompressedSize(): number | bigint

      Returns the size of the decompressed data in bytes, as decoded: a bigint only when it exceeds Number.MAX_SAFE_INTEGER.

      Returns number | bigint

    • get checksum(): number

      Returns the CRC32 checksum of the decompressed data.

      Returns number

    • get compressionRatio(): number

      Returns the compression ratio of the data.

      The compression ratio is calculated as (compressed size) / (decompressed size), so lower values indicate better compression.

      Returns number

      A floating-point value representing the compression ratio.

      • Values less than 1.0 indicate effective compression
      • Values equal to 1.0 indicate no compression was applied
      • Values of NaN can occur if the decompressed size is zero
    • Creates a new Compressed object with the specified parameters.

      This is a low-level constructor that allows direct creation of a Compressed object without performing compression. It's primarily intended for deserialization or when working with pre-compressed data. checksum is a u32 and decompressedSize a usize (a bigint is accepted above Number.MAX_SAFE_INTEGER), as the reference's fields.

      Parameters

      • parts: {
            checksum: number;
            decompressedSize: number | bigint;
            compressedData: Uint8Array;
            digest?: Digest;
        }

        checksum, decompressedSize, compressedData and the optional digest

      Returns Compressed

      A new Compressed object

      ComponentsError Compression if the compressed data is larger than the decompressed size

    • Creates a new Compressed object by compressing the provided data.

      This is the primary method for creating compressed data. It compresses with raw DEFLATE at level 6, the reference's compress_to_vec(data, 6), so the stream is byte-identical to the reference's for the same input.

      If the compressed data would be larger than the original data (which can happen with small or already compressed inputs), the original data is stored instead.

      Parameters

      • decompressedData: Uint8Array

        The original data to compress

      • Optionaldigest: Digest

        Optional cryptographic digest of the content

      Returns Compressed

      A new Compressed object containing the compressed (or original) data

    • Decompresses and returns the original decompressed data.

      This method performs the reverse of the compression process, restoring the original data. It also verifies the integrity of the data using the stored checksum.

      Returns Uint8Array

      The decompressed data

      ComponentsError Compression if the stream is corrupt (corrupt compressed data) or the checksum does not match (compressed data checksum mismatch)

    • Returns the digest of the compressed data, if available.

      Returns Digest | undefined

      The Digest associated with this compressed data, or undefined if none.

    • Returns whether this compressed data has an associated digest.

      Returns boolean

    • Returns the cryptographic digest associated with this compressed data.

      Returns Digest

      A Digest

      ComponentsError Compression if there is no digest (the reference unwraps it)

    • Compare with another Compressed: checksum, size, compressed bytes and the digest, as the reference's derived PartialEq.

      Parameters

      Returns boolean

    • Get string representation (the reference's Debug).

      Returns string

    • The CBOR tags this type decodes from; the first one is used to encode.

      Returns Tag[]

    • Returns the untagged CBOR encoding (as an array).

      Format:

      [
      checksum: uint,
      decompressed_size: uint,
      compressed_data: bytes,
      digest?: Digest // Optional
      ]

      Returns Cbor

    • The tagged CBOR form.

      Returns Cbor

    • As a UR, typed by the first tag's name.

      Returns UR