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 0 | 0 | 0 | 0 |
| 2.4.0 | 0 | 0 | 0 | 0 | 0 |
| 2.3.0 | 0 | 0 | 0 | 0 | 0 |
| 2.2.1 | 0 | 0 | 0 | 0 | 0 |
| 2.2.0 | 0 | 0 | 0 | 0 | 0 |
| 2.1.0 | 0 | 0 | 0 | 0 | 0 |
| 2.0.1 | 0 | 0 | 0 | 0 | 0 |
| 2.0.0 | 0 | 0 | 0 | 0 | 0 |
| 1.2.0 | 0 | 0 | 0 | 0 | 0 |
| 1.1.4 | 0 | 0 | 0 | 0 | 0 |
| 1.1.3 | 0 | 0 | 0 | 0 | 0 |
| 1.1.2 | 0 | 0 | 0 | 0 | 0 |
| 1.1.1 | 0 | 0 | 0 | 0 | 0 |
| 1.1.0 | 0 | 0 | 0 | 0 | 0 |
| 1.0.9 | 0 | 0 | 0 | 0 | 0 |
| 1.0.8 | 0 | 0 | 0 | 0 | 0 |
| 1.0.7 | 0 | 0 | 1 | 0 | 0 |
| 1.0.6 | 0 | 0 | 1 | 0 | 0 |
| 0.1.1 | 0 | 0 | 1 | 0 | 0 |
| 0.1.0 | 0 | 0 | 1 | 0 | 0 |
8.0.2 - This version is safe to use because it has no known security vulnerabilities at this time. Find out if your coding project uses this component and get notified of any reported security vulnerabilities with Meterian-X Open Source Security Platform
Maintain your licence declarations and avoid unwanted licences to protect your IP the way you intended.
BSD-3-Clause - BSD 3-Clause "New" or "Revised" LicenseFix for memory leak in ffi API
Compatibility for ffi builds
Pinned to a rust-brotli-decompressor that can disable the ffi with the ffi-api flag. This can help avoid symbol conflicts with other brotli libs.
Updated SIMD support. Better CI integration. Cleaned up some of the clippy warnings.
Brotli decompressor's reader and writer has better behavior when operating upon brotli streams with extra bits at the end. Optional features like stdsimd are now tested or disabled for now.
Direct no-stdlib port of the C brotli compressor to Rust
no dependency on the Rust stdlib: this library would be ideal for decompressing within a rust kernel among other things.
This is useful to see how C and Rust compare in an apples-to-apples comparison where the same algorithms and data structures and optimizations are employed.
Rust brotli currently supports compression levels 0 - 11 They should be bitwise identical to the brotli C compression engine at compression levels 0-9 Recommended lg_window_size is between 20 and 22
let mut input = brotli::CompressorReader::new(&mut io::stdin(), 4096 /* buffer size */,
quality as u32, lg_window_size as u32);then you can simply read input as you would any other io::Read class
let mut writer = brotli::Compressor::new(&mut io::stdout(), 4096 /* buffer size */,
quality as u32, lg_window_size as u32);There are also methods to build Compressor Readers or Writers using the with_params static function
eg:
let params = BrotliEncoderParams::default();
// modify params to fit the application needs
let mut writer = brotli::Compressor::with_params(&mut io::stdout(), 4096 /* buffer size */,
params);or for the reader
let params = BrotliEncoderParams::default();
// modify params to fit the application needs
let mut writer = brotli::CompressorReader::with_params(&mut io::stdin(), 4096 /* buffer size */,
params);match brotli::BrotliCompress(&mut io::stdin(), &mut io::stdout(), &brotli_encoder_params) {
Ok(_) => {},
Err(e) => panic!("Error {:?}", e),
}let mut input = brotli::Decompressor::new(&mut io::stdin(), 4096 /* buffer size */);then you can simply read input as you would any other io::Read class
let mut writer = brotli::DecompressorWriter::new(&mut io::stdout(), 4096 /* buffer size */);match brotli::BrotliDecompress(&mut io::stdin(), &mut io::stdout()) {
Ok(_) => {},
Err(e) => panic!("Error {:?}", e),
}There are 3 steps to using brotli without stdlib
in Detail
// at global scope declare a MemPool type -- in this case we'll choose the heap to
// avoid unsafe code, and avoid restrictions of the stack size
declare_stack_allocator_struct!(MemPool, heap);
// at local scope, make a heap allocated buffers to hold uint8's uint32's and huffman codes
let mut u8_buffer = define_allocator_memory_pool!(4096, u8, [0; 32 * 1024 * 1024], heap);
let mut u32_buffer = define_allocator_memory_pool!(4096, u32, [0; 1024 * 1024], heap);
let mut hc_buffer = define_allocator_memory_pool!(4096, HuffmanCode, [0; 4 * 1024 * 1024], heap);
let heap_u8_allocator = HeapPrealloc::<u8>::new_allocator(4096, &mut u8_buffer, bzero);
let heap_u32_allocator = HeapPrealloc::<u32>::new_allocator(4096, &mut u32_buffer, bzero);
let heap_hc_allocator = HeapPrealloc::<HuffmanCode>::new_allocator(4096, &mut hc_buffer, bzero);
// At this point no more syscalls are going to be needed since everything can come from the allocators.
// Feel free to activate SECCOMP jailing or other mechanisms to secure your application if you wish.
// Now it's possible to setup the decompressor state
let mut brotli_state = BrotliState::new(heap_u8_allocator, heap_u32_allocator, heap_hc_allocator);
// at this point the decompressor simply needs an input and output buffer and the ability to track
// the available data left in each buffer
loop {
result = BrotliDecompressStream(&mut available_in, &mut input_offset, &input.slice(),
&mut available_out, &mut output_offset, &mut output.slice_mut(),
&mut written, &mut brotli_state);
// just end the decompression if result is BrotliResult::ResultSuccess or BrotliResult::ResultFailure
}This interface is the same interface that the C brotli decompressor uses
Also feel free to use custom allocators that invoke Box directly. This example illustrates a mechanism to avoid subsequent syscalls after the initial allocation
rust-brotli is a drop-in replacement for the official https://github.com/google/brotli C implementation. That means you can use it from any place that supports that library. To build rust-brotli in this manner enter the c subdirectory and run make there
cd c && make
this should build c/target/release/libbrotli.so and should build the vanilla command line tool in C for compressing and decompressing any brotli file.
the libbrotli.so in c/target/release should be able to replace any other libbrotli.so file, but with all the advantages of using safe rust (except in the FFI bindings)
The code also allows a wider range of options, including forcing the prediction mode (eg UTF8 vs signed vs MSB vs LSB) and changing the weight of the literal cost from 540 to other values.
Brotli supports creating streams that can be concatenated together, useful for streaming scenarios where you want to compress chunks independently but decompress as a single stream.
Use -bare -appendable for the first file and -bare -catable for subsequent files.
These can be combined using plain byte concatenation without special tools, with a
finalization byte (0x03) added at the end:
# Create the base file with header but no trailer (must specify window size)
brotli -c -bare -appendable -w22 input1.txt > base.br
# Create bare-catable streams (no header, no trailer, same window size!)
brotli -c -bare -catable -w22 input2.txt > part2.br
brotli -c -bare -catable -w22 input3.txt > part3.br
# Simple concatenation with finalization byte
# Note: printf '\x03' adds the required final byte
(cat base.br part2.br part3.br; printf '\x03') > combined.br
# Decompress normally
brotli -d combined.br -o output.txtAdvantages:
Requirements:
-w22 recommended)-bare -appendable (has header, no trailer)-bare -catable (no header, no trailer, no dictionary refs)0x03 byte must be appended to complete the streamUse the catbrotli tool with -catable and -appendable flags for better compression
at the cost of processing time:
# Create files for catbrotli tool
brotli -c -appendable input1.txt > appendable.br
brotli -c -catable input2.txt > catable1.br
brotli -c -catable input3.txt > catable2.br
# Concatenate using catbrotli tool
catbrotli appendable.br catable1.br catable2.br > combined.brTradeoff: catbrotli produces smaller output but requires CPU time to process the
streams intelligently. Use this when size matters more than concatenation speed.
Stream Types and Their Parameters:
| Stream Type | bare_stream | byte_align | appendable | catable | use_dictionary | Description |
|---|---|---|---|---|---|---|
| Standard | false | false | false | false | true | Normal brotli stream with header and trailer |
| First (simple concat) | true | true | true | false | true | Has header, no trailer - for simple cat concatenation |
| Subsequent (simple concat) | true | true | true | true | false | No header, no trailer, no dict refs - append to first |
| Appendable (catbrotli) | false | varies | true | false | true | For use with catbrotli tool |
| Catable (catbrotli) | false | varies | true | true | false | For use with catbrotli tool |
Important Notes:
SanitizeParams function ensures:
catable = true → automatically sets appendable = true and use_dictionary = false
bare_stream = true → automatically sets byte_align = true
!appendable → automatically sets byte_align = false
set_parameter(), dependencies are applied immediatelyparams.catable = true), dependencies are applied during compression initializationuse_dictionary = false for catable streams prevents references to bytes before the chunk boundary0x03 byte to complete the streamExample API Usage:
// First file: -bare -appendable equivalent
params.bare_stream = true; // Sets bare_stream=true, byte_align=true (automatic)
params.appendable = true; // Sets appendable=true
// Subsequent files: -bare -catable equivalent
params.bare_stream = true; // Sets bare_stream=true, byte_align=true (automatic)
params.catable = true; // Sets catable=true, appendable=true, use_dictionary=false (automatic)
// All parameter dependencies are handled automatically by the library.
// No manual fixups required - just set the primary flags you want.