Crate webc

source
Expand description

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

  • v1 (enabled by default) — Load WEBC files in the v1 format
  • v2 (enabled by default) — Load WEBC files in the v2 format
  • v3 (enabled by default) — Load WEBC files in the v3 format
  • package (enabled by default) — Load Wasmer packages from disk (implies the v2 and v3 feature)
  • crypto — Sign and verify binaries in v1 webc format
  • mmap — No longer used

Re-exports§

Modules§

  • compatDeprecated
    A compatibility layer for dealing with different versions of the WEBC binary format.
  • Package metadata.
  • migrationv2 and v3
    Contains code for migrating v2 <–> v3
  • v1v1
    Parsing code for v1 of the WEBC format.
  • v2v2
    Parsing code for v2 of the WEBC format.
  • v3v3
    Parsing code for v3 of the WEBC format.
  • Load a Wasmer package from disk.

Structs§

  • A version-agnostic read-only WEBC container.
  • a cheaply cloneable path segment (i.e. the path, to, and file.txt in path/to/file.txt).
  • A series of PathSegments specifying the absolute path to something.
  • Represents file or directory timestamps.
  • A WEBC file’s version number.
  • A WEBC volume.

Enums§

Constants§

  • File identification bytes stored at the beginning of the file.

Traits§

Functions§

  • Check whether something looks like a valid WEBC file and extract its version number.
  • Check if the provided item looks like a WEBC file.

Type Aliases§