Xandra v0.10.1 Xandra.Compressor behaviour View Source

A behaviour to compress and decompress binary data.

Modules implementing this behaviour can be used to compress and decompress data using one of the compression algorithms supported by Cassandra (as of now, lz4 and snappy).

Example

Let's imagine you implemented the snappy compression algorithm in your application:

defmodule Snappy do
  def compress(binary), do: ...
  def decompress(binary), do: ...
end

You can then implement a module that implements the Xandra.Compressor behaviour and can be used to compress and decompress data flowing through the connection to Cassandra:

defmodule SnappyXandraCompressor do
  @behaviour Xandra.Compressor

  def algorithm(), do: :snappy
  defdelegate compress(binary), to: Snappy
  defdelegate decompress(binary), to: Snappy
end

Now, this module can be passed as the value of the :compressor option to many functions in Xandra:

Xandra.start_link(compressor: SnappyXandraCompressor)

For more information on compression, see the "Compression" section in the documentation for Xandra.

Link to this section Summary

Callbacks

Specifies which algorithm this module will use to compress and decompress data.

Compresses the given iodata according to the algorithm returned by algorithm/0.

Deompresses the given binary according to the algorithm returned by algorithm/0.

Link to this section Callbacks

Link to this callback

algorithm() View Source
algorithm() :: :lz4 | :snappy

Specifies which algorithm this module will use to compress and decompress data.

Link to this callback

compress(iodata) View Source
compress(iodata()) :: iodata()

Compresses the given iodata according to the algorithm returned by algorithm/0.

Link to this callback

decompress(binary) View Source
decompress(binary()) :: binary()

Deompresses the given binary according to the algorithm returned by algorithm/0.