• Public
  • Public/Protected
  • All

External module "snappy/compress"




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


    • src: Uint8Array
    • Optional dst: Uint8Array

    Returns Uint8Array


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


    • srcLen: number

    Returns number

Generated using TypeDoc