webc::v1

Struct Volume

Source
pub struct Volume<'data> {
    pub header: VolumeHeader<'data>,
    pub data: &'data [u8],
}
Available on crate feature v1 only.
Expand description

Filesystem volume, containing the uncompressed files in an ordered directory structure

Fields§

§header: VolumeHeader<'data>

Header, storing all the offsets and file names in order

§data: &'data [u8]

Volume filesystem

Implementations§

Source§

impl<'a> Volume<'a>

Source

pub fn serialize_atoms(files: BTreeMap<DirOrFile, Vec<u8>>) -> Vec<u8>

Serialize an atom volume.

This is essentially Volume::serialize_files(), but it will modify the input files to uphold several atom-specific invariants - namely that each atom is addressable by its module name. This means:

  • All atoms are hoisted to the top level folder
  • Extensions are removed from filenames
Source

pub fn serialize_files(files: BTreeMap<DirOrFile, Vec<u8>>) -> Vec<u8>

Create a volume from a set of initial files

Source

pub fn get_all_file_and_dir_entries( &'a self, ) -> Result<BTreeMap<DirOrFile, FsEntry<'a>>, Error>

Returns all files and directories with the corresponding FsEntry

Source

pub fn get_all_file_entries_recursivesorted(&'a self) -> RecursiveFsEntryDir<'a>

Returns all entries in a “tree” sorted structure, i.e. sorted in the same way you’d see the files in a tree explorer

Source

pub fn get_all_file_entries_directorysorted( &'a self, ) -> Vec<(DirOrFile, FsEntry<'a>)>

Returns all entries in a “tree” sorted structure, i.e. sorted in the same way you’d see the files in a tree explorer

Source

pub fn walk<'b>(&'b self) -> VolumeIterator<'a, 'b>

Generic walk function that walks recursively over the files and calls a callback function with self.data on every entry.

Source

pub fn get_all_files_and_directories_with_bytes( &self, ) -> Result<BTreeSet<DirOrFileWithBytes<'_>>, Error>

Returns all the files in this volume, indexed by the full path (in unix fashion, i.e. “/”, “/a”, “/b/file.txt”)

Source

pub fn count_files(&self) -> u64

Returns the number of files in this volume

Source

pub fn count_directories(&self) -> u64

Returns the number of directories in this volume

Source

pub fn list_directories(&self) -> Vec<String>

Source

pub fn parse(data: &'a [u8]) -> Result<Self, Error>

Parses a filesystem volume from a buffer of bytes

Source

pub fn read_dir(&self, path: &str) -> Result<Vec<FsEntry<'a>>, Error>

Returns file entries for $path

Source

pub fn get_file_entry(&self, path: &str) -> Result<OwnedFsEntryFile, Error>

Returns the file entry for $path. Note that this does not return the file contents directly, use volume.get_file(path) instead.

§Errors

Returns an error if the file is a directory.

Source

pub fn get_file_bytes( &self, entry: &OwnedFsEntryFile, ) -> Result<&'a [u8], Error>

Given an already-existing OwnedFsEntryFile, returns the byte slice for this file entry.

§Errors

The function returns an error if the file entry is out of bounds of the underlying data slice (should never happen)

Source

pub fn get_file(&'a self, path: &str) -> Result<&'a [u8], Error>

Returns the file contents (shorthand for volume.get_file_bytes(volume.get_file_entry(path)))

Source

pub fn into_bytes(&self) -> Vec<u8>

Serializes the volume into writable bytes (including the header and header length)

Trait Implementations§

Source§

impl<'data> Clone for Volume<'data>

Source§

fn clone(&self) -> Volume<'data>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'data> Debug for Volume<'data>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'data> Default for Volume<'data>

Source§

fn default() -> Volume<'data>

Returns the “default value” for a type. Read more
Source§

impl<'data> PartialEq for Volume<'data>

Source§

fn eq(&self, other: &Volume<'data>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'data> Eq for Volume<'data>

Source§

impl<'data> StructuralPartialEq for Volume<'data>

Auto Trait Implementations§

§

impl<'data> Freeze for Volume<'data>

§

impl<'data> RefUnwindSafe for Volume<'data>

§

impl<'data> Send for Volume<'data>

§

impl<'data> Sync for Volume<'data>

§

impl<'data> Unpin for Volume<'data>

§

impl<'data> UnwindSafe for Volume<'data>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T