43 releases (23 stable)

6.0.0-rc1 May 30, 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

#40 in WebAssembly

Download history 11523/week @ 2024-04-01 13703/week @ 2024-04-08 11496/week @ 2024-04-15 11100/week @ 2024-04-22 5975/week @ 2024-04-29 12186/week @ 2024-05-06 15692/week @ 2024-05-13 15314/week @ 2024-05-20 18583/week @ 2024-05-27 12406/week @ 2024-06-03 18481/week @ 2024-06-10 18485/week @ 2024-06-17 9528/week @ 2024-06-24 22865/week @ 2024-07-01 28397/week @ 2024-07-08 29523/week @ 2024-07-15

91,433 downloads per month
Used in 112 crates (17 directly)

MIT and maybe LGPL-2.0-or-later

605KB
14K 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
~328K SLoC