Struct file_rw::FileWriter
source · pub struct FileWriter { /* private fields */ }Expand description
FileWriter is a structure that allows writing to a file.
It uses memory-mapped files for efficient file manipulation.
Implementations§
source§impl FileWriter
impl FileWriter
sourcepub fn open_file(file: File) -> Self
pub fn open_file(file: File) -> Self
Opens a file and returns a FileWriter instance.
It panics if it cannot get the path of the writer file.
sourcepub fn open(path: impl AsRef<Path> + Send + Sync) -> Self
pub fn open(path: impl AsRef<Path> + Send + Sync) -> Self
Opens a file in write mode and returns a FileWriter instance.
sourcepub fn write(&mut self, bytes: impl AsRef<[u8]>) -> &Self
pub fn write(&mut self, bytes: impl AsRef<[u8]>) -> &Self
Writes bytes to the file. It replaces the entire content of the file with the provided bytes.
pub fn write_to_offset( &mut self, bytes: impl AsRef<[u8]>, offset: usize ) -> &Self
pub fn append(&mut self, bytes: impl AsRef<[u8]>) -> &Self
pub fn overwrite(&mut self, bytes: impl AsRef<[u8]>) -> &Self
pub fn bytes_mut(&mut self) -> &mut [u8] ⓘ
pub fn bytes(&self) -> &[u8] ⓘ
sourcepub fn replace(&mut self, bytes: impl AsRef<[u8]>, offset: usize) -> &Self
pub fn replace(&mut self, bytes: impl AsRef<[u8]>, offset: usize) -> &Self
Replaces a portion of the file content starting from the provided offset with the provided bytes.
sourcepub fn find_replace(
&mut self,
find: impl AsRef<[u8]>,
replace: impl AsRef<[u8]>
) -> &Self
pub fn find_replace( &mut self, find: impl AsRef<[u8]>, replace: impl AsRef<[u8]> ) -> &Self
Finds a sequence of bytes in the file and replaces it with another sequence of bytes. If the sequence to find is not found, it does nothing.
sourcepub fn rfind_replace(
&mut self,
find: impl AsRef<[u8]>,
replace: impl AsRef<[u8]>
) -> &Self
pub fn rfind_replace( &mut self, find: impl AsRef<[u8]>, replace: impl AsRef<[u8]> ) -> &Self
Finds the last occurrence of a slice of bytes in the file and replaces it with another slice of bytes.
sourcepub fn rfind_replace_nth(
&mut self,
find: impl AsRef<[u8]>,
replace: impl AsRef<[u8]>,
n: usize
) -> &Self
pub fn rfind_replace_nth( &mut self, find: impl AsRef<[u8]>, replace: impl AsRef<[u8]>, n: usize ) -> &Self
Finds the nth occurrence of a slice of bytes in the file, in reverse order, and replaces it with another slice of bytes.
sourcepub fn find_replace_nth(
&mut self,
find: impl AsRef<[u8]>,
replace: impl AsRef<[u8]>,
n: usize
) -> &Self
pub fn find_replace_nth( &mut self, find: impl AsRef<[u8]>, replace: impl AsRef<[u8]>, n: usize ) -> &Self
Finds the nth occurrence of a slice of bytes in the file and replaces it with another slice of bytes. If the slice to find is not found, no replacement occurs.
sourcepub fn find_replace_all(
&mut self,
find: impl AsRef<[u8]>,
replace: impl AsRef<[u8]>
) -> &Self
pub fn find_replace_all( &mut self, find: impl AsRef<[u8]>, replace: impl AsRef<[u8]> ) -> &Self
Finds all occurrences of a slice of bytes in the file and replaces them with another slice of bytes.
sourcepub fn file(&mut self) -> File
pub fn file(&mut self) -> File
Returns a File object that represents the file being written to.
pub fn len(&mut self) -> u64
pub fn set_len(&mut self, len: u64) -> &Self
pub fn extend_len_by(&mut self, len: u64) -> &Self
sourcepub fn path(&mut self) -> &Box<dyn AsRef<Path> + Send + Sync>
pub fn path(&mut self) -> &Box<dyn AsRef<Path> + Send + Sync>
Returns a reference to the path of the file being written to.
sourcepub fn mmap(&mut self) -> &mut Box<MmapMut>
pub fn mmap(&mut self) -> &mut Box<MmapMut>
Returns a mutable reference to the memory-mapped file.
sourcepub fn to_reader(&mut self) -> FileReader
pub fn to_reader(&mut self) -> FileReader
Converts the FileWriter into a FileReader.
Trait Implementations§
source§impl Debug for FileWriter
impl Debug for FileWriter
Writes “FileWriter({Path})” to the provided formatter.