webc 5.8.1

WebContainer implementation for wapm.io
Documentation

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.

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

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

use webc::{
Container,
Version,
v2::read::OwnedReader,
v1::{ParseOptions, WebC},
};
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::V2) => {
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}"),
}