50 releases (26 stable)

7.0.0-rc.2 Nov 5, 2024
6.1.0 Oct 2, 2024
6.0.0-rc1 May 30, 2024
5.8.1 Nov 22, 2023
0.4.1 Dec 13, 2022

#36 in WebAssembly

Download history 22910/week @ 2024-07-30 28394/week @ 2024-08-06 20510/week @ 2024-08-13 38308/week @ 2024-08-20 20339/week @ 2024-08-27 15266/week @ 2024-09-03 14889/week @ 2024-09-10 13011/week @ 2024-09-17 9596/week @ 2024-09-24 16492/week @ 2024-10-01 20847/week @ 2024-10-08 14053/week @ 2024-10-15 13700/week @ 2024-10-22 18217/week @ 2024-10-29 16199/week @ 2024-11-05 7933/week @ 2024-11-12

58,820 downloads per month
Used in 77 crates (19 directly)

MIT and maybe LGPL-2.0-or-later

500KB
12K 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

~5–21MB
~277K SLoC