Elixir bindings for libbz2
View SourceStreaming bzip2 codec.
Installation
Your system must have the development package for bzip2. For example,
apt install libbz2-dev
This package can be installed by adding bzip2
to your list of dependencies in
mix.exs
:
def deps do
[
{:bzip2, "~> 0.3"}
]
end
Documentation can be generated with ExDoc and published on HexDocs.
Published docs are online at https://hexdocs.pm/bzip2.
Usage
Compress or decompress a stream:
File.stream!("/dev/zero", [], 1024 * 1024)
|> Stream.take(10)
|> Bzip2.compress!()
|> Enum.into("")
|> byte_size()
# 450
Or work on a fixed block of data:
iex> Bzip2.compress!("sample string") |> Bzip2.decompress!()
"sample string"
Debugging
This repo includs some basic tests:
mix test
You can also run against the bzip2 reference tests,
git clone https://sourceware.org/git/bzip2-tests.git
cd bzip2-ex
mix run test-reference-suite.exs ../bzip2-tests
To get verbose output from the NIF, uncomment this line in bzip2.c
:
#define BZIP2_EX_DEBUG
Known bugs and compatibility
- Only builds on linux-x86_64, please send patches to port to other platforms!
- Fully compliant with bzip2 reference tests.