README.md

# Varint

[![Elixir CI](https://github.com/ahamez/varint/actions/workflows/elixir.yml/badge.svg)](https://github.com/ahamez/varint/actions/workflows/elixir.yml) [![Coverage Status](https://coveralls.io/repos/github/ahamez/varint/badge.svg?branch=master)](https://coveralls.io/github/ahamez/varint?branch=master) [![Hex.pm](https://img.shields.io/hexpm/v/varint)](https://hex.pm/packages/varint) [![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/varint/) [![License](https://img.shields.io/hexpm/l/varint.svg)](https://github.com/ahamez/varint/blob/master/LICENSE)

A library to compress integers using [LEB128](https://en.wikipedia.org/wiki/LEB128).

## Installation

Add `:varint` to your list of dependencies in `mix.exs`:

```elixir
def deps do
  [{:varint, "~> 1.4"}]
end
```

## Usage

### LEB128

Use this module to compress and decompress unsigned integers:

```elixir
iex> Varint.LEB128.encode(300)
<<172, 2>>
```

```elixir
iex> Varint.LEB128.decode(<<172, 2>>)
{300, <<>>}
```

### Zigzag

As LEB128 works with unsigned integers, you can use the the Zigzag module to process signed integers.

```elixir
iex> Varint.Zigzag.encode(-2)
3
```

```elixir
iex> Varint.Zigzag.decode(3)
-2
```

```elixir
iex> Varint.Zigzag.encode(2)
4
```

```elixir
iex> Varint.Zigzag.decode(4)
2
```

You'll find detailed instructions at [hexdocs.pm](https://hexdocs.pm/varint/api-reference.html).

## License

Copyright (c) 2016 Alexandre Hamez

This work is free. You can redistribute it and/or modify it under the
terms of the MIT License. See the LICENSE file for more details.