gix-chunk 0.7.1

Interact with the git chunk file format used in multi-pack index and commit-graph files
Documentation

Low-level access to reading and writing chunk file based formats.

See the git documentation for details.

Examples

# fn main() -> Result<(), Box<dyn std::error::Error>> {
use std::io::Write;

let mut index = gix_chunk::file::Index::for_writing();
index.plan_chunk(*b"OIDF", 4);
index.plan_chunk(*b"DATA", 3);

let mut out = index.into_write(Vec::new(), 0)?;
while let Some(kind) = out.next_chunk() {
    match kind {
        [b'O', b'I', b'D', b'F'] => out.write_all(b"abcd")?,
        [b'D', b'A', b'T', b'A'] => out.write_all(b"xyz")?,
        _ => unreachable!("planned chunks are known"),
    }
}

let data = out.into_inner();
let decoded = gix_chunk::file::Index::from_bytes(&data, 0, 2)?;
assert_eq!(decoded.data_by_id(&data, *b"OIDF")?, b"abcd");
assert_eq!(decoded.data_by_id(&data, *b"DATA")?, b"xyz");
# Ok(()) }