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 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.
- metadata
- 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§
- Container
- A version-agnostic read-only WEBC container.
- Path
Segment - a cheaply cloneable path segment (i.e. the
path
,to
, andfile.txt
inpath/to/file.txt
). - Path
Segments - A series of
PathSegment
s specifying the absolute path to something. - Timestamps
- Represents file or directory timestamps.
- Version
- A WEBC file’s version number.
- Volume
- A WEBC volume.
Enums§
- Container
Error - Various errors that may occur during
Container
operations. - Detect
Error - An error returned by
detect()
. - Directory
From Path Error - Error returned from
from_path_with_ignore
. - Metadata
- Metadata describing the properties of a file or directory.
- Path
Segment Error - An error that may occur while parsing a
PathSegment
orPathSegments
. - Volume
Error - Errors that may occur when doing
Volume
operations.
Constants§
- MAGIC
- File identification bytes stored at the beginning of the file.
Traits§
- Abstract
Volume - Abstraction over different volume implementations
- ToPath
Segments - 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.