pub struct Volume<'data> {
pub header: VolumeHeader<'data>,
pub data: &'data [u8],
}
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>
impl<'a> Volume<'a>
Sourcepub fn serialize_atoms(files: BTreeMap<DirOrFile, Vec<u8>>) -> Vec<u8> ⓘ
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
Sourcepub fn serialize_files(files: BTreeMap<DirOrFile, Vec<u8>>) -> Vec<u8> ⓘ
pub fn serialize_files(files: BTreeMap<DirOrFile, Vec<u8>>) -> Vec<u8> ⓘ
Create a volume from a set of initial files
Sourcepub fn get_all_file_and_dir_entries(
&'a self,
) -> Result<BTreeMap<DirOrFile, FsEntry<'a>>, Error>
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
Sourcepub fn get_all_file_entries_recursivesorted(&'a self) -> RecursiveFsEntryDir<'a>
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
Sourcepub fn get_all_file_entries_directorysorted(
&'a self,
) -> Vec<(DirOrFile, FsEntry<'a>)>
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
Sourcepub fn walk<'b>(&'b self) -> VolumeIterator<'a, 'b> ⓘ
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.
Sourcepub fn get_all_files_and_directories_with_bytes(
&self,
) -> Result<BTreeSet<DirOrFileWithBytes<'_>>, Error>
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”)
Sourcepub fn count_files(&self) -> u64
pub fn count_files(&self) -> u64
Returns the number of files in this volume
Sourcepub fn count_directories(&self) -> u64
pub fn count_directories(&self) -> u64
Returns the number of directories in this volume
pub fn list_directories(&self) -> Vec<String>
Sourcepub fn parse(data: &'a [u8]) -> Result<Self, Error>
pub fn parse(data: &'a [u8]) -> Result<Self, Error>
Parses a filesystem volume from a buffer of bytes
Sourcepub fn read_dir(&self, path: &str) -> Result<Vec<FsEntry<'a>>, Error>
pub fn read_dir(&self, path: &str) -> Result<Vec<FsEntry<'a>>, Error>
Returns file entries for $path
Sourcepub fn get_file_entry(&self, path: &str) -> Result<OwnedFsEntryFile, Error>
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.
Sourcepub fn get_file_bytes(
&self,
entry: &OwnedFsEntryFile,
) -> Result<&'a [u8], Error>
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)
Sourcepub fn get_file(&'a self, path: &str) -> Result<&'a [u8], Error>
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))
)
Sourcepub fn into_bytes(&self) -> Vec<u8> ⓘ
pub fn into_bytes(&self) -> Vec<u8> ⓘ
Serializes the volume into writable bytes (including the header and header length)
Trait Implementations§
impl<'data> Eq for Volume<'data>
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> 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.