Options
All
  • Public
  • Public/Protected
  • All
Menu

Module @stablelib/snappy

Index

Functions

  • compress(src: Uint8Array, dst?: Uint8Array): Uint8Array
  • Compresses src into dst and returns a subarray into dst containing the compressed data.

    If no dst is given or if it's smaller than compress bound, it's automatically allocated with the length given by compressBound(src.length).

    Usually, the length of original (decompressed data) is stored somewhere with compressed data (for example, as 4 little-endian bytes in the beginning), so that an appropriate space can be allocated for decompress(), but this function doesn't do it — it so it's up to the caller to write it.

    Throws an error if input is too large (see maxCompressedLength()).

    This is a bare block compression without any framing.

    Parameters

    • src: Uint8Array
    • Optional dst: Uint8Array

    Returns Uint8Array

  • decompress(src: Uint8Array, dst?: Uint8Array): Uint8Array
  • Decompresses src into dst and returns a subarray into dst containing decompressed data.

    The length of decompress data is read from src. If dst is smaller than it, the new appropriately sized dst is allocated and returned.

    Throws an error if input is corrupted.

    This is a bare block compression without any framing.

    Parameters

    • src: Uint8Array
    • Optional dst: Uint8Array

    Returns Uint8Array

  • decompressedLength(src: Uint8Array): number
  • Reads decompressed length from src and returns it.

    Throws an error if the length is too large or the input is corrupted.

    Parameters

    • src: Uint8Array

    Returns number

  • maxCompressedLength(srcLen: number): number
  • Returns the maximum length of buffer needed for compression of input of the given length.

    Returns 0 if the length is too large.

    Snappy format specifications limits the maximum uncompressed length to 2^32-1, but since JavaScript runtimes can't allocate so much anyway, and Snappy framing format uses no longer than 65536-byte chunks, we limit the maximum compressed size to 2^31-1 = 0x7FFFFFFF, which requires that the maximum uncompressed size is 1840700241 bytes (0x7FFFFFFF ~= 32 + x + x/6).

    Current JavaScript VMs will still most likely fail to allocate that much, so it is a good idea to limit source length to something smaller.

    Parameters

    • srcLen: number

    Returns number

Generated using TypeDoc