Snappyrex (snappyrex v0.1.0)

View Source

Snappyrex is a Rustler wrapper leveraging the 'snap' package as a NIF for fast Snappy compression/decompression in Elixir.

Usage

iex> Snappyrex.compress("hello")
{:ok, <<5, 16, 104, 101, 108, 108, 111>>}
iex> Snappyrex.decompress(<<5, 16, 104, 101, 108, 108, 111>>)
{:ok, "hello"}
iex> Snappyrex.compress("hello", format: :frame)
{:ok, <<255, 6, 0, 0, 115, 78, 97, 80, 112, 89, 1, 9, 0, 0, 187, 31, 28, 25, 104, 101, 108, 108, 111>>}
iex> Snappyrex.decompress(<<255, 6, 0, 0, 115, 78, 97, 80, 112, 89, 1, 9, 0, 0, 187, 31, 28, 25, 104, 101, 108, 108, 111>>, format: :frame)
{:ok, "hello"}

Summary

Functions

Compress a binary.

Decompress a binary.

Functions

compress(data, opts \\ [])

@spec compress(
  binary(),
  keyword()
) :: {:ok, binary()} | {:error, :invalid_format | :compression_failed}

Compress a binary.

Options

  • :format - :frame or :raw (default: :raw)

decompress(data, opts \\ [])

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

Decompress a binary.

Setting detect to true will attempt to detect the format of the compressed data. It will first try to decompress with the format specified, only use the detected format if the decompression fails and the detected format is different from the specified format.

Options

  • :format - :frame or :raw (default: :raw)
  • :detect - true or false (default: false)