42 releases (23 stable)

new 6.0.0-alpha9 May 22, 2024
6.0.0-alpha3 Apr 24, 2024
5.8.1 Nov 22, 2023
5.2.2 Jul 27, 2023
0.4.1 Dec 13, 2022

#117 in Filesystem

Download history 13435/week @ 2024-01-31 11820/week @ 2024-02-07 5881/week @ 2024-02-14 8072/week @ 2024-02-21 8586/week @ 2024-02-28 9543/week @ 2024-03-06 10384/week @ 2024-03-13 7511/week @ 2024-03-20 9870/week @ 2024-03-27 11978/week @ 2024-04-03 16393/week @ 2024-04-10 7728/week @ 2024-04-17 10339/week @ 2024-04-24 7143/week @ 2024-05-01 12133/week @ 2024-05-08 12742/week @ 2024-05-15

44,360 downloads per month
Used in 88 crates (16 directly)

MIT and maybe LGPL-2.0-or-later

610KB
15K SLoC

A library for reading and writing WEBC files.

The Container provides an abstraction over the various WEBC versions this crate can handle. As such, it tries to cater to the lowest common denominator and favors portability over performance or power.

use webc::Container;
let bytes: &[u8] = b"\0webc...";

let container = Container::from_bytes(bytes)?;

println!("{:?}", container.manifest());

println!("Atoms:");
for (name, atom) in container.atoms() {
    let length = atom.len();
    println!("{name}: {length} bytes");
}

for (name, volume) in container.volumes() {
    let root_items = volume.read_dir("/").expect("The root directory always exists");
    println!("{name}: {} items", root_items.len());
}

In general, errors that occur during lazy operations won't be accessible to the user.

Version-Specific Fallbacks

If more flexibility is required, consider using [crate::detect()] and instantiating a compatible parser directly.

use webc::{
    Container,
    Version,
};
use webc::v1::{ParseOptions, WebC};
use webc::v3::read::OwnedReader;
let bytes: &[u8] = b"...";

match webc::detect(bytes) {
    Ok(Version::V1) => {
        let options = ParseOptions::default();
        let webc = WebC::parse(bytes, &options).unwrap();
        if let Some(signature) = webc.signature {
            println!("Package signature: {:?}", signature);
        }
    }
    Ok(Version::V3) => {
        let webc = OwnedReader::parse(bytes).unwrap();
        let index = webc.index();
        let signature = &index.signature;
        if !signature.is_none() {
            println!("Package signature: {signature:?}");
        }
    }
    Ok(other) => todo!("Unsupported version, {other}"),
    Err(e) => todo!("An error occurred: {e}"),
}

Feature Flags

Dependencies

~7–21MB
~343K SLoC