Brotlic (or BrotliC) is a thin wrapper around brotli.

Overview

Brotlic

Crates.io docs.rs GitHub Workflow Status License

Brotlic (or BrotliC) is a thin wrapper around brotli.

Table of Contents

Requirements

A C compiler is required for building brotli with cargo.

Usage

Brotlic provides Rust bindings to all compression and decompression APIs. On the fly compression and decompression is supported for both BufRead and Write via CompressorReader, CompressorWriter, DecompressorReader and DecompressorWriter. For low-level instances, see BrotliEncoder and BrotliDecoder. These can be configured via BrotliEncoderOptions and BrotliDecoderOptions respectively.

When dealing with BufRead:

  • DecompressorReader - Reads a brotli compressed input stream and decompresses it.
  • CompressorReader - Reads a stream and compresses it while reading.

When dealing with Write:

  • CompressorWriter - Writes brotli compressed data to the underlying writer.
  • DecompressorWriter - Writes brotli decompressed data to the underlying writer.

To simplify this decision, the following table outlines all the differences:

Input Output Wraps
CompressorReader Uncompressed Compressed BufRead
DecompressorReader Compressed Uncompressed BufRead
CompressorWriter Uncompressed Compressed Write
DecompressorWriter Compressed Uncompressed Write

To compress a file with brotli:

use std::fs::File;
use std::io::{self, Write};
use brotlic::CompressorWriter;

let mut input = File::open("test.txt")?; // uncompressed text file
let mut output = File::create("test.brotli")?; // compressed text output file
let mut output_compressed = CompressorWriter::new(output);

output_compressed.write_all(b"test")?;

To decompress that same file:

use std::fs::File;
use std::io::{self, BufReader, Read};
use brotlic::DecompressorReader;

let mut input = BufReader::new(File::open("test.brotli")?); // uncompressed text file
let mut input_decompressed = DecompressorReader::new(input); // requires BufRead

let mut text = String::new();
input_decompressed.read_to_string(&mut text)?;

assert_eq!(text, "test");

To compress and decompress in memory:

use std::io::{self, Read, Write};
use brotlic::{CompressorWriter, DecompressorReader};

let input = vec![0; 1024];

// create a wrapper around Write that supports on the fly brotli compression.
let mut compressor = CompressorWriter::new(Vec::new()); // write to memory
compressor.write_all(input.as_slice());
let encoded_input = compressor.into_inner()?; // read to vec

// create a wrapper around BufRead that supports on the fly brotli decompression.
let mut decompressed_reader = DecompressorReader::new(encoded_input);
let mut decoded_input = Vec::new();

decompressed_reader.read_to_end(&mut decoded_input)?;

assert_eq!(input, decoded_input);

Sometimes it can be desirable to trade run-time costs for an even better compression ratio by customizing compression quality:

use brotlic::{BlockSize, BrotliEncoderOptions, CompressorWriter, Quality, WindowSize};

let encoder = BrotliEncoderOptions::new()
    .quality(Quality::best())
    .window_size(WindowSize::best())
    .block_size(BlockSize::best())
    .build()?;

let writer = Vec::new();
let compressed_writer = CompressorWriter::with_encoder(encoder, writer);

It is recommended to not use the encoder directly but instead pass it onto the higher level abstractions like CompressorWriter or DecompressorReader.

Performance

Brotlic has comparable performance to the rust-brotli library:

To conduct your own testing, run cargo bench. This will compare the performance of this library and the rust brotli library using inputs with different sizes and different amounts of entropy.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Credits

You might also like...
The classic game Pong, written in lambda calculus, and a thin layer of Rust.

What? The good old game Pong, written in lambda calculus, and a thin layer of Rust. Why? I was bored. No, seriously, why? Everyone keeps saying that l

Safe and rich Rust wrapper around the Vulkan API
Safe and rich Rust wrapper around the Vulkan API

Vulkano See also vulkano.rs. Vulkano is a Rust wrapper around the Vulkan graphics API. It follows the Rust philosophy, which is that as long as you do

Wrapper around Microsoft CNTK library

Bindings for CNTK library Simple low level bindings for CNTK library from Microsoft. API Documentation Status Currently exploring ways how to interact

Wrapper around Microsoft CNTK library

Bindings for CNTK library Simple low level bindings for CNTK library from Microsoft. API Documentation Status Currently exploring ways how to interact

📼 Wrapper around ffmpeg which simplifies merging of multiple videos
📼 Wrapper around ffmpeg which simplifies merging of multiple videos

Vidmerger A wrapper around ffmpeg which simplifies merging of multiple videos. 🙉 What is this exactly? Vidmerger is a command-line-tool which uses ff

A super minimal wrapper around unix sockets for IPC on top of tokio.

tokio-unix-ipc This crate implements a minimal abstraction over UNIX domain sockets for the purpose of IPC on top of tokio.

Wrapper around reqwest to allow for client middleware chains.

reqwest-middleware A crate implementing a wrapper around reqwest to allow for client middleware chains. Overview The reqwest-middleware client exposes

"A light wrapper around rr, the time-travelling debugger

cargo-rr A light wrapper around rr, the time-travelling debugger. Do you find yourself running the same test over and over in the debugger, trying to

A stupid wrapper around Meilisearch 🐻

Mieli 🐻 Usage 🧸 mieli 0.1.10 A stupid wrapper around meilisearch USAGE: mieli [OPTIONS] SUBCOMMAND FLAGS: -h, --help Prints help i

A wrapper around the Win32 API credential management functions.

wincredentials-rs A wrapper around the Win32 API credential management functions. Currently only supports generic credentials. Example use wincredenti

A wrapper around SDL2's game controller API.

fishsticks System for handling gamepad input, using SDL2's game controller API as the backend. License Fishsticks is dual-licensed under either Apache

Deno wrapper around minifb, for making a framebuffer you can draw pixels to

deno minifb This is a thin wrapper around minifb that you can use in deno. Combine it with canvas for native window that works like the canvas web API

Wrapper around atspi-code to provide higher-level at-spi Rust bindings

atspi Wrapper around atspi-codegen to provide higher-level at-spi Rust bindings. Contributions Take a look at our atspi-codegen crate, and try inpleme

FFI wrapper around cfitsio in Rust

rust-fitsio FFI wrapper around cfitsio in Rust Installation fitsio supports versions of cfitsio = 3.08. cfitsio must be compiled with reentrant suppo

cargo-check This is a wrapper around cargo rustc

cargo-check This is a wrapper around cargo rustc -- -Zno-trans. It can be helpful for running a faster compile if you only need correctness checks. In

Shared memory - A Rust wrapper around native shared memory for Linux and Windows

shared_memory A crate that allows you to share memory between processes. This crate provides lightweight wrappers around shared memory APIs in an OS a

A safe Rust wrapper around a subset of cuFFT.

cufft_rust This is a safe Rust wrapper around CUDA FFT (cuFFT). It only supports a subset of the API which I need for private projects. For now this o

A simple, yet feature-filled wrapper around the coqui-stt C API

A simple, yet feature-filled wrapper around the coqui-stt C API

A wrapper around the code action dump from https://mcdiamondfire.com.

DiamondFire Action Dump for Rust A wrapper around the code action dump from https://mcdiamondfire.com. This currently only provides schema types for u

Comments
Releases(0.8.0)
  • 0.8.0(Aug 14, 2022)

    This release removes allocator support because it suffers from several issues:

    1. It misuses the GlobalAlloc trait as opposed to the Allocator api to remain stable. The allocator API would be the best fit but it is currently unstable.

    2. Secondly it uses a double Box to pass the GlobalAlloc trait object, because trait objects are fat pointers and across FFI boundaries for the brotli API only thin pointers are accepted. This would be more efficiently done using a ThinBox, which would only allocate once instead of twice.

    3. Performance improvements are negligible

    I plan to readd support later under a feature gate. Preferably once the required primitives are stabilized.

    Source code(tar.gz)
    Source code(zip)
  • 0.7.0(May 2, 2022)

    This release adds custom memory allocator support. Currently it is based on the GlobalAlloc trait. This is subject to change when the allocator_api gets stabilized.

    The following new APIs were added: DecompressorReader<R>::new_in CompressorReader<R>::new_in CompressorWriter<W>::new_in DecompressorWriter<W>::new_in BrotliDecoder::new_in BrotliEncoder::new_in BrotliDecoderOptions::build_in BrotliEncoderOptions::build_in

    Source code(tar.gz)
    Source code(zip)
Owner
Aron Parker
Aron Parker
Brotli compressor and decompressor written in rust that optionally avoids the stdlib

rust-brotli What's new in 3.2 into_inner conversions for both Reader and Writer classes What's new in 3.0 A fully compatible FFI for drop-in compatibi

Dropbox 659 Dec 29, 2022
Thin wrapper around starship.rs to format kakoune status line

kakship is just a thin wrapper around starship to format the status line of kakoune and is meant to be used with the included kakoune script kakship.kak.

Eric Burghard 15 Jun 7, 2022
Thin wrapper around [`tokio::process`] to make it streamable

process-stream Wraps tokio::process::Command to future::stream. Install process-stream = "0.2.2" Example usage: From Vec<String> or Vec<&str> use proc

null 4 Jun 25, 2022
Thin wrapper around [`tokio::process`] to make it streamable

This library provide ProcessExt to create your own custom process

null 4 Jun 25, 2022
A Brotli implementation in pure and safe Rust

Brotli-rs - Brotli decompression in pure, safe Rust Documentation Compression provides a <Read>-struct to wrap a Brotli-compressed stream. A consumer

Thomas Pickert 59 Oct 7, 2022
Brotli compressor and decompressor written in rust that optionally avoids the stdlib

rust-brotli What's new in 3.2 into_inner conversions for both Reader and Writer classes What's new in 3.0 A fully compatible FFI for drop-in compatibi

Dropbox 659 Dec 29, 2022
Command-Line program that takes images and produces the copy of the image with a thin frame and palette made of the 10 most frequent colors.

paleatra v.0.0.1 Command-Line program that takes an image and produces the copy of the image with a thin frame and palette made of the 10 most frequen

Beka Modebadze 24 Dec 29, 2022
rsmpeg is a thin&safe layer above the FFmpeg's Rust bindings

A Rust crate that exposes FFmpeg's power as much as possible.

Lark Technologies Pte. Ltd. 384 Jan 2, 2023
Thin but safe ALSA wrappers for Rust

ALSA bindings for Rust Thin but safe wrappers for ALSA, the most common API for accessing audio devices on Linux. The ALSA API is rather big, so every

null 91 Dec 26, 2022
A thin-hypervisor that runs on aarch64 CPUs.

How to build the hypervisor By Rust toolchain (TBD) By docker Requirements Docker (Tested by Docker version 20.10.8, build 3967b7d28e) I tested by non

RIKEN R-CCS 54 Dec 12, 2022