SnappyEx (snappyex v0.1.3)

View Source

Public API for raw Snappy blocks.

compress/1 and decompress/1 work with the standard raw Snappy block format: an uncompressed-size varint followed by literal and copy commands.

compress_framed/1 and decompress_framed/1 work with the Snappy framed stream format. compress_framed_stream/1 and decompress_framed_stream/2 provide lazy, bounded-memory framed processing.

Summary

Functions

Compresses a binary into the raw Snappy block format.

Compresses a binary into the Snappy framed stream format.

Lazily compresses a binary or enumerable of iodata chunks into a Snappy framed stream.

Decompresses a raw Snappy block.

Decompresses a raw Snappy block, raising ArgumentError for malformed input or output-limit violations. Accepts the same options as decompress/2.

Decompresses a Snappy framed stream.

Decompresses a Snappy framed stream, raising ArgumentError for malformed input or output-limit violations. Accepts the same options as decompress_framed/2.

Lazily decompresses a binary or enumerable of iodata chunks containing a Snappy framed stream.

Types

decompress_error()

@type decompress_error() ::
  :empty_input
  | :malformed_preamble
  | :truncated_literal
  | :truncated_copy
  | :invalid_offset
  | :invalid_length
  | :output_limit_exceeded

framed_decompress_error()

@type framed_decompress_error() ::
  :missing_stream_identifier
  | :invalid_stream_identifier
  | :truncated_chunk_header
  | :truncated_chunk
  | :invalid_chunk_length
  | :unsupported_chunk
  | :checksum_mismatch
  | :output_limit_exceeded
  | {:invalid_compressed_chunk, decompress_error()}

Functions

compress(input)

@spec compress(binary()) :: binary()

Compresses a binary into the raw Snappy block format.

compress_framed(input)

@spec compress_framed(binary()) :: binary()

Compresses a binary into the Snappy framed stream format.

compress_framed_stream(input)

@spec compress_framed_stream(binary() | Enumerable.t()) :: Enumerable.t()

Lazily compresses a binary or enumerable of iodata chunks into a Snappy framed stream.

The returned stream yields binary frame fragments and begins with the stream identifier. Concatenating the fragments produces the same bytes as compress_framed/1 for the same input.

decompress(compressed, opts \\ [])

@spec decompress(
  binary(),
  keyword()
) :: {:ok, binary()} | {:error, decompress_error()}

Decompresses a raw Snappy block.

Returns {:ok, binary} on success or {:error, reason} for malformed input.

Options

  • :max_output_size - maximum number of uncompressed bytes to return, or :infinity for no limit. Defaults to :infinity.

decompress!(compressed, opts \\ [])

@spec decompress!(
  binary(),
  keyword()
) :: binary()

Decompresses a raw Snappy block, raising ArgumentError for malformed input or output-limit violations. Accepts the same options as decompress/2.

decompress_framed(compressed, opts \\ [])

@spec decompress_framed(
  binary(),
  keyword()
) :: {:ok, binary()} | {:error, framed_decompress_error()}

Decompresses a Snappy framed stream.

Returns {:ok, binary} on success or {:error, reason} for malformed input.

Options

  • :max_output_size - maximum total number of uncompressed bytes to return, or :infinity for no aggregate limit. Defaults to :infinity.

decompress_framed!(compressed, opts \\ [])

@spec decompress_framed!(
  binary(),
  keyword()
) :: binary()

Decompresses a Snappy framed stream, raising ArgumentError for malformed input or output-limit violations. Accepts the same options as decompress_framed/2.

decompress_framed_stream(input, opts \\ [])

@spec decompress_framed_stream(
  binary() | Enumerable.t(),
  keyword()
) :: Enumerable.t()

Lazily decompresses a binary or enumerable of iodata chunks containing a Snappy framed stream.

Each yielded binary is a complete checksum-verified data chunk. Input may be split at arbitrary byte boundaries.

Options

  • :max_output_size - maximum total number of uncompressed bytes to yield, or :infinity for no aggregate limit. Defaults to :infinity.

Malformed input and output-limit violations raise ArgumentError when the returned stream reaches the offending chunk. Unread input is not validated.