Xandra v0.6.0 Xandra.Compressor behaviour

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.

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

Callbacks

algorithm()
algorithm() :: :lz4 | :snappy

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

compress(iodata)
compress(iodata) :: iodata

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

decompress(binary)
decompress(binary) :: binary

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