Blockchain Commons Components TypeScript Library - v1.0.0-alpha.13
    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

    Methods

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

      Parameters

      • checksum: number

        CRC32 checksum of the decompressed data

      • decompressedSize: number

        Size of the original decompressed data in bytes

      • compressedData: Uint8Array

        The compressed data bytes

      • Optionaldigest: Digest

        Optional cryptographic digest of the content

      Returns Compressed

      A new Compressed object

      CryptoError 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 automatically handles compression using the DEFLATE algorithm with compression level 6.

      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

      CryptoError if the compressed data is corrupt or checksum doesn't match

    • 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
    • Returns the digest of the compressed data, if available.

      Returns Digest | undefined

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

    • Returns the CBOR tags associated with Compressed.

      Returns Tag[]

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

      Format:

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

      Returns Cbor

    • Returns the tagged value in CBOR binary representation.

      Returns Uint8Array