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 formatv2
(enabled by default) — Load WEBC files in the v2 formatv3
(enabled by default) — Load WEBC files in the v3 formatcrypto
— Sign and verify binaries in v1 webc formatmmap
— No longer used
Re-exports§
Modules§
- compat
Deprecated A compatibility layer for dealing with different versions of the WEBC binary format. - Package metadata.
- migration
v2
andv3
Contains code for migrating v2 <–> v3 - v1
v1
Parsing code for v1 of the WEBC format. - v2
v2
Parsing code for v2 of the WEBC format. - v3
v3
Parsing code for v3 of the WEBC format.
Structs§
- A version-agnostic read-only WEBC container.
- a cheaply cloneable path segment (i.e. the
path
,to
, andfile.txt
inpath/to/file.txt
). - A series of
PathSegment
s specifying the absolute path to something. - Represents file or directory timestamps.
- A WEBC file’s version number.
- A WEBC volume.
Enums§
- Various errors that may occur during
Container
operations. - An error returned by
detect()
. - Metadata describing the properties of a file or directory.
- An error that may occur while parsing a
PathSegment
orPathSegments
. - Errors that may occur when doing
Volume
operations.
Constants§
- File identification bytes stored at the beginning of the file.
Traits§
- Abstraction over different volume implementations
- Convert something into
PathSegments
.
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.
- Turn any path that gets passed in into something WASI can use.
Type Aliases§
- The type for
MAGIC
.