pub struct Volume<'data> {
pub header: VolumeHeader<'data>,
pub data: &'data [u8],
}
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
sourceimpl<'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
pub fn get_all_file_entries(
&'a self
) -> Result<BTreeMap<DirOrFile, FsEntry<'a>>, Error>
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 get_all_file_entries_with_offset(
&self
) -> Result<BTreeMap<DirOrFile, &'a [u8]>, Error>
pub fn get_all_file_entries_with_offset(
&self
) -> Result<BTreeMap<DirOrFile, &'a [u8]>, 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)