#file-format #compression #stream #data #read #file-io #dictionary

bin+lib archiv

Read and write compressed, length-prefixed streams or file(s)

4 releases

0.1.3 Jan 3, 2024
0.1.2 Jul 10, 2023
0.1.1 Jan 29, 2023
0.1.0 Jan 29, 2023

#682 in Encoding

27 downloads per month

MIT/Apache

22KB
539 lines

archiv

archiv is a library and CLI for working with .archiv files.

.archiv files are a simplistic "file format" that keeps getting reinvented, by me.

This file format is:

A header, then, repeatedly:

  • length, 8 bytes, little-endian: the length of the following data
  • data, the data

You've probably heard of this before.

On top of this we can layer things like:

  • stream compression
  • item compression
  • item compression with a shared dictionary
  • item compression with an embedded dictionary
  • parallel processing of item compressed files
  • indexes
  • docs and shared terminology

Contributing

Github.

License

MIT / Apache-2


lib.rs:

use archiv::Compress;

let opts = archiv::CompressOptions::default();
let mut archiv = opts.stream_compress(io::stdout())?;
archiv.write_item(b"hello")?;
archiv.finish()?;
use archiv::Expand;

let opts = archiv::ExpandOptions::default();
let mut archiv = opts.stream(io::stdin().lock())?;
while let Some(mut item) = archiv.next_item()? {
    let mut s = String::new();
    item.read_to_string(&mut s)?;
    println!("{s}");
}

Dependencies

~4MB
~73K SLoC