pub struct Volume { /* private fields */ }
Expand description
A WEBC volume.
A Volume
represents a collection of files and directories, providing
methods to read file contents and traverse directories.
Example
use webc::compat::{Metadata, Volume};
fn get_webc_volume() -> Volume {
/* ... */
}
let volume = get_webc_volume();
// Accessing file content.
let content = volume.read_file("/path/to/file.txt").unwrap();
assert_eq!(content, b"Hello, World!");
// Inspect directories.
let entries = volume.read_dir("/").unwrap();
assert_eq!(entries.len(), 2);
assert_eq!(entries[0], (
PathSegment::parse("another.txt").unwrap(),
Metadata::File { length: 7 },
));
assert_eq!(entries[1], (
PathSegment::parse("path").unwrap(),
Metadata::Dir,
));
Implementations§
source§impl Volume
impl Volume
sourcepub fn metadata(&self, path: impl ToPathSegments) -> Option<Metadata>
pub fn metadata(&self, path: impl ToPathSegments) -> Option<Metadata>
Get the metadata of an item at the given path.
Returns None
if the item does not exist in the volume or an internal
error occurred.
sourcepub fn read_dir(
&self,
path: impl ToPathSegments
) -> Option<Vec<(PathSegment, Metadata)>>
pub fn read_dir( &self, path: impl ToPathSegments ) -> Option<Vec<(PathSegment, Metadata)>>
Read the contents of a directory at the given path.
Returns a vector of directory entries, including their metadata, if the path is a directory.
Returns None
if the path does not exist or is not a directory.
sourcepub fn read_file(&self, path: impl ToPathSegments) -> Option<OwnedBuffer>
pub fn read_file(&self, path: impl ToPathSegments) -> Option<OwnedBuffer>
Read the contents of a file at the given path.
Returns None
if the path is not valid or the file is not found.
sourcepub fn unpack(
&self,
volume_path: impl ToPathSegments,
out_dir: &Path
) -> Result<(), ContainerError>
pub fn unpack( &self, volume_path: impl ToPathSegments, out_dir: &Path ) -> Result<(), ContainerError>
Unpack a subdirectory of this volume into a local directory.
Use ‘/’ as the volume_path to unpack the entire volume.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Volume
impl Send for Volume
impl Sync for Volume
impl Unpin for Volume
impl !UnwindSafe for Volume
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more