Packages
xandra
0.12.0
0.19.4
0.19.3
0.19.2
0.19.1
0.19.0
0.18.1
0.18.0
0.18.0-rc.9
0.18.0-rc.8
0.18.0-rc.7
0.18.0-rc.6
0.18.0-rc.5
0.18.0-rc.4
0.18.0-rc.3
0.18.0-rc.2
0.18.0-rc.1
0.17.0
0.16.0
0.15.0
0.15.0-rc.1
0.14.0
0.13.1
0.13.0
0.12.0
0.11.0
0.10.1
0.10.0
0.9.2
0.9.1
0.9.0
0.8.0
0.7.2
0.7.1
0.7.0
0.6.1
0.6.0
0.5.1
0.5.0
0.4.3
0.4.2
0.4.1
0.4.0
0.3.2
0.3.1
0.3.0
0.2.0
0.1.0
Fast, simple, and robust Cassandra driver for Elixir.
Current section
Files
Jump to
Current section
Files
lib/xandra/compressor.ex
defmodule Xandra.Compressor do
@moduledoc """
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.`
"""
@doc """
Specifies which algorithm this module will use to compress and decompress
data.
"""
@callback algorithm() :: :lz4 | :snappy
@doc """
Compresses the given iodata according to the algorithm returned by
`c:algorithm/0`.
"""
@callback compress(iodata) :: iodata
@doc """
Deompresses the given binary according to the algorithm returned by
`c:algorithm/0`.
"""
@callback decompress(binary) :: binary
end