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.