Coder Social home page Coder Social logo

brotlex's Introduction

Brotlex

CI

Elixir wrapper for rust-brotli using rustler NIFs.

Disclaimer: This is a clone of https://gitlab.com/normanganderson/brotlex with updates for latest rustler and precompiled NIFs. GitHub Actions copied from html5ever_elixir.

Installation

If available in Hex, the package can be installed by adding brotlex to your list of dependencies in mix.exs:

def deps do
  [
    {:brotlex, github: "hwuethrich/brotlex", tag: "v0.4.0"}
  ]
end

By default you don't need Rust installed because the lib will try to download a precompiled NIF file. In case you want to force compilation set the BROTLEX_BUILD environment variable to true or 1. Alternatively you can also set the application env :build_from_source to true in order to force the build:

config :brotlex, Brotlex, build_from_source: true

Usage

iex> {:ok, data} = Brotlex.compress("Hello World")
{:ok, <<11, 5, 128, 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 3>>}

iex> Brotlex.decompress(data)
{:ok, "Hello World"}

You can use this in to compress arbitrary binaries by doing Brotlex.compress(arbitrary_binary). You can then decompress with Brotlex.decompress(arbitrary_compressed_data). The error handling is probably a bit iffy if you try to decompress something that isn't a brotli compressed binary.

Benchmarks

You can run some benchmarks between Brotlex and brotli, by running the following command MIX_ENV=bench mix run bench/run.exs. This will compile Brotlex in release mode and compress things with the defaults for both packages.

I'm definitely just discovering how to use Rustler and Elixir together. If you have any ideas on how to make the Rust or Elixir code better please feel free to post issues to the repo.

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/brotlex.

brotlex's People

Contributors

callmenorm avatar hwuethrich avatar skipmike avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.