pub struct RFile { /* private fields */ }Expand description
This struct represents an individual file, including the metadata associated with it.
It can represent both, a file within a Pack (or anything implementing Container really), or a single file on disk.
It supports Lazy-Loading to reduce RAM usage.
Implementations§
Source§impl RFile
impl RFile
Sourcepub fn new_from_container<C: Container>(
container: &C,
size: u64,
is_compressed: bool,
is_encrypted: Option<PFHVersion>,
data_pos: u64,
file_timestamp: u64,
path_in_container: &str,
) -> Result<Self>
pub fn new_from_container<C: Container>( container: &C, size: u64, is_compressed: bool, is_encrypted: Option<PFHVersion>, data_pos: u64, file_timestamp: u64, path_in_container: &str, ) -> Result<Self>
This function creates a RFile from a lazy-loaded file inside a Container.
About the parameters:
container: The container this RFile is on.size: Size in bytes of the RFile.is_compressed: If the RFile is compressed.is_encrypted: If the RFile is encrypted.data_pos: Byte offset of the data from the beginning of the Container.file_timestamp: Timestamp of this specific file (not of the container, but the file). If it doesn’t have one, pass 0.path_in_container: Path of the RFile in the container.
NOTE: Remember to call guess_file_type after this to properly set the FileType.
Sourcepub fn new_from_file(path: &str) -> Result<Self>
pub fn new_from_file(path: &str) -> Result<Self>
This function creates a RFile from a path on disk.
This may fail if the file doesn’t exist or errors out when trying to be read for metadata.
NOTE: Remember to call guess_file_type after this to properly set the FileType.
Sourcepub fn new_from_file_path(path: &Path) -> Result<Self>
pub fn new_from_file_path(path: &Path) -> Result<Self>
This function creates a RFile from a path on disk.
This may fail if the file doesn’t exist or errors out when trying to be read for metadata.
NOTE: Remember to call guess_file_type after this to properly set the FileType.
Sourcepub fn new_from_vec(
data: &[u8],
file_type: FileType,
timestamp: u64,
path: &str,
) -> Self
pub fn new_from_vec( data: &[u8], file_type: FileType, timestamp: u64, path: &str, ) -> Self
This function creates a RFile from raw data on memory.
NOTE: Remember to call guess_file_type after this to properly set the FileType.
Sourcepub fn new_from_decoded(data: &RFileDecoded, timestamp: u64, path: &str) -> Self
pub fn new_from_decoded(data: &RFileDecoded, timestamp: u64, path: &str) -> Self
This function creates a RFile from an RFileDecoded on memory.
NOTE: Remember to call guess_file_type after this to properly set the FileType.
Sourcepub fn cached(&self) -> Result<&[u8]>
pub fn cached(&self) -> Result<&[u8]>
This function returns a reference to the cached data of an RFile, if said RFile has been cached. If not, it returns an error.
Useful for accessing preloaded data.
Sourcepub fn cached_mut(&mut self) -> Result<&mut Vec<u8>>
pub fn cached_mut(&mut self) -> Result<&mut Vec<u8>>
This function returns a mutable reference to the cached data of an RFile, if said RFile has been cached. If not, it returns an error.
Useful for accessing preloaded data.
Sourcepub fn decoded(&self) -> Result<&RFileDecoded>
pub fn decoded(&self) -> Result<&RFileDecoded>
This function returns a reference to the decoded data of an RFile, if said RFile has been decoded. If not, it returns an error.
Useful for accessing preloaded data.
Sourcepub fn decoded_mut(&mut self) -> Result<&mut RFileDecoded>
pub fn decoded_mut(&mut self) -> Result<&mut RFileDecoded>
This function returns a mutable reference to the decoded data of an RFile, if said RFile has been decoded. If not, it returns an error.
Useful for accessing preloaded data.
Sourcepub fn set_cached(&mut self, data: &[u8])
pub fn set_cached(&mut self, data: &[u8])
This function replace any data a RFile has with the provided raw data.
Sourcepub fn set_decoded(&mut self, decoded: RFileDecoded) -> Result<()>
pub fn set_decoded(&mut self, decoded: RFileDecoded) -> Result<()>
This function allows to replace the inner decoded data of a RFile with another. It’ll fail if the decoded data is not valid for the file’s type.
Sourcepub fn decode(
&mut self,
extra_data: &Option<DecodeableExtraData<'_>>,
keep_in_cache: bool,
return_data: bool,
) -> Result<Option<RFileDecoded>>
pub fn decode( &mut self, extra_data: &Option<DecodeableExtraData<'_>>, keep_in_cache: bool, return_data: bool, ) -> Result<Option<RFileDecoded>>
This function decodes an RFile from binary data, optionally caching and returning the decoded RFile.
About the arguments:
extra_data: any data needed to decode specific file types. Check each file type for info about what do each file type need.keep_in_cache: if true, the data will be cached on memory.return_data: if true, the decoded data will be returned.
NOTE: Passing keep_in_cache and return_data at false causes this function to decode the RFile and
immediately drop the resulting data.
Sourcepub fn encode(
&mut self,
extra_data: &Option<EncodeableExtraData<'_>>,
move_decoded_to_cache: bool,
move_undecoded_to_cache: bool,
return_data: bool,
) -> Result<Option<Vec<u8>>>
pub fn encode( &mut self, extra_data: &Option<EncodeableExtraData<'_>>, move_decoded_to_cache: bool, move_undecoded_to_cache: bool, return_data: bool, ) -> Result<Option<Vec<u8>>>
This function encodes an RFile to binary, optionally caching and returning the data.
About the arguments:
extra_data: any data needed to encode specific file types. Check each file type for info about what do each file type need.move_decoded_to_cache: if true, the decoded data will be dropped in favor of undecoded cached data.move_undecoded_to_cache: if true, the data will be cached on memory.return_data: if true, the data will be returned.
Sourcepub fn load(&mut self) -> Result<()>
pub fn load(&mut self) -> Result<()>
This function loads the data of an RFile to memory if it’s not yet loaded.
If it has already been loaded either to cache, or for decoding, this does nothing.
Sourcepub fn timestamp(&self) -> Option<u64>
pub fn timestamp(&self) -> Option<u64>
This function returns a copy of the Last modified date of this RFile, if any.
Sourcepub fn file_type(&self) -> FileType
pub fn file_type(&self) -> FileType
This function returns a copy of the FileType of this RFile.
Sourcepub fn file_name(&self) -> Option<&str>
pub fn file_name(&self) -> Option<&str>
This function returns the file name if this RFile, if it has one.
Sourcepub fn container_name(&self) -> &Option<String>
pub fn container_name(&self) -> &Option<String>
This function returns the file name of the container this RFile originates from, if any.
Sourcepub fn path_in_container(&self) -> ContainerPath
pub fn path_in_container(&self) -> ContainerPath
This function returns the ContainerPath corresponding to this file.
Sourcepub fn path_in_container_raw(&self) -> &str
pub fn path_in_container_raw(&self) -> &str
This function returns the ContainerPath corresponding to this file as an &str.
Sourcepub fn path_in_container_split(&self) -> Vec<&str>
pub fn path_in_container_split(&self) -> Vec<&str>
This function returns the ContainerPath corresponding to this file as a Vec of &str.
Sourcepub fn db_table_name_from_path(&self) -> Option<&str>
pub fn db_table_name_from_path(&self) -> Option<&str>
This function the table_name of this file (the folder that contains this file) if this file is a DB table.
It returns None of the file provided is not a DB Table.
Sourcepub fn set_path_in_container_raw(&mut self, path: &str)
pub fn set_path_in_container_raw(&mut self, path: &str)
This function sets the ContainerPath of the provided RFile to the provided path..
Sourcepub fn is_compressible(&self, game_info: &GameInfo) -> bool
pub fn is_compressible(&self, game_info: &GameInfo) -> bool
This function returns if the RFile can be compressed or not.
Sourcepub fn guess_file_type(&mut self) -> Result<()>
pub fn guess_file_type(&mut self) -> Result<()>
This function guesses the FileType of the provided RFile and stores it on it for later queries.
The way it works is: first it tries to guess it by extension (fast), then by full path (not as fast), then by data (slow and it may fail on lazy-loaded files).
This may fail for some files, so if you doubt set the type manually.
Sourcepub fn tsv_import_from_path(
path: &Path,
schema: &Option<Schema>,
) -> Result<Self>
pub fn tsv_import_from_path( path: &Path, schema: &Option<Schema>, ) -> Result<Self>
This function allows to import a TSV file on the provided Path into a binary database file.
It requires the path on disk of the TSV file and the Schema to use. Schema is only needed for DB tables.
Sourcepub fn tsv_export_to_path(
&mut self,
path: &Path,
schema: &Schema,
keys_first: bool,
) -> Result<()>
pub fn tsv_export_to_path( &mut self, path: &Path, schema: &Schema, keys_first: bool, ) -> Result<()>
This function allows to export a RFile into a TSV file on disk.
Only supported for DB and Loc files.
Sourcepub fn merge(sources: &[&Self], path: &str) -> Result<Self>
pub fn merge(sources: &[&Self], path: &str) -> Result<Self>
This function tries to merge multiple files into one.
All files must be of the same type and said type must support merging.
Sourcepub fn update(&mut self, definition: &Option<Definition>) -> Result<()>
pub fn update(&mut self, definition: &Option<Definition>) -> Result<()>
This function tries to update a file to a new version of the same file’s format.
Files used by this function are expected to be pre-decoded.
Sourcepub fn data_hash(
&mut self,
extra_data: &Option<EncodeableExtraData<'_>>,
) -> Result<u64>
pub fn data_hash( &mut self, extra_data: &Option<EncodeableExtraData<'_>>, ) -> Result<u64>
This function returns the data hash of the file.
Sourcepub fn sanitize_and_create_file(
&mut self,
destination_path: &Path,
extra_data: &Option<EncodeableExtraData<'_>>,
) -> Result<PathBuf>
pub fn sanitize_and_create_file( &mut self, destination_path: &Path, extra_data: &Option<EncodeableExtraData<'_>>, ) -> Result<PathBuf>
Sanitizes a destination path and creates a file with the sanitized path. Logs a message if the filename was changed due to invalid Windows characters.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for RFile
impl<'de> Deserialize<'de> for RFile
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl StructuralPartialEq for RFile
Auto Trait Implementations§
impl Freeze for RFile
impl RefUnwindSafe for RFile
impl Send for RFile
impl Sync for RFile
impl Unpin for RFile
impl UnwindSafe for RFile
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§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.