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, Version};
let bytes: &[u8] = b"\0webc...";
let container = Container::from_bytes_and_version(bytes.into(), Version::V3)?;
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
- 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.
- metadata
- Package metadata.
- migrationv2andv3
- 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.
Structs§
- Container
- A version-agnostic read-only WEBC container.
- PathSegment 
- a cheaply cloneable path segment (i.e. the path,to, andfile.txtinpath/to/file.txt).
- PathSegments 
- A series of PathSegments specifying the absolute path to something.
- Timestamps
- Represents file or directory timestamps.
- Version
- A WEBC file’s version number.
- Volume
- A WEBC volume.
Enums§
- ContainerError 
- Various errors that may occur during Containeroperations.
- DetectError 
- An error returned by detect().
- DirectoryFrom Path Error 
- Error returned from from_path_with_ignore.
- Metadata
- Metadata describing the properties of a file or directory.
- PathSegment Error 
- An error that may occur while parsing a PathSegmentorPathSegments.
- VolumeError 
- Errors that may occur when doing Volumeoperations.
Constants§
- MAGIC
- File identification bytes stored at the beginning of the file.
Traits§
- AbstractVolume 
- Abstraction over different volume implementations
- ToPathSegments 
- Convert something into PathSegments.
Functions§
- detect
- Check whether something looks like a valid WEBC file and extract its version number.
- is_webc
- Check if the provided item looks like a WEBC file.
- sanitize_path 
- Turn any path that gets passed in into something WASI can use.