https://github.com/ahamez/varint
An Elixir library to compress integers using the Variable Length Encoding LEB128 compression.
https://github.com/ahamez/varint
compress-integers elixir varint
Last synced: about 2 months ago
JSON representation
An Elixir library to compress integers using the Variable Length Encoding LEB128 compression.
- Host: GitHub
- URL: https://github.com/ahamez/varint
- Owner: ahamez
- License: mit
- Created: 2016-12-10T14:54:03.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2025-03-31T06:08:48.000Z (2 months ago)
- Last Synced: 2025-04-11T13:30:18.278Z (about 2 months ago)
- Topics: compress-integers, elixir, varint
- Language: Elixir
- Homepage:
- Size: 121 KB
- Stars: 11
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Varint
[](https://github.com/ahamez/varint/actions/workflows/elixir.yml) [](https://coveralls.io/github/ahamez/varint?branch=master) [](https://hex.pm/packages/varint) [](https://hexdocs.pm/varint/) [](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.