pub struct FileUtils;Expand description
Enhanced file operations with safety checks.
This struct provides a collection of utility methods for file operations that include additional safety checks, validation, and enhanced functionality beyond the standard library’s file operations.
Implementations§
Source§impl FileUtils
impl FileUtils
Sourcepub fn safe_join<P: AsRef<Path>>(base: P, path: P) -> Result<PathBuf>
pub fn safe_join<P: AsRef<Path>>(base: P, path: P) -> Result<PathBuf>
Safely joins two paths while preventing directory traversal attacks.
This method ensures that the resulting path remains within the base
directory and cannot be used to access files outside of it through
path traversal techniques like ../.
§Arguments
base- The base directory path.path- The path to join to the base.
§Returns
A Result containing the safely joined PathBuf, or an error if
path traversal is detected.
Sourcepub async fn get_enhanced_metadata(path: &Path) -> Result<EnhancedFileMetadata>
pub async fn get_enhanced_metadata(path: &Path) -> Result<EnhancedFileMetadata>
Retrieves enhanced file metadata with additional information.
This method provides more comprehensive file information than the standard metadata, including MIME type detection and text file classification.
§Arguments
path- The path to the file or directory.
§Returns
A Result containing EnhancedFileMetadata with detailed file information.
Sourcepub async fn copy_with_progress<F>(
from: &Path,
to: &Path,
progress_callback: F,
) -> Result<()>
pub async fn copy_with_progress<F>( from: &Path, to: &Path, progress_callback: F, ) -> Result<()>
Copies a file with progress tracking.
This method copies a file from one location to another while providing progress updates through a callback function. It uses a buffered approach for efficient copying of large files.
§Arguments
from- The source file path.to- The destination file path.progress_callback- A function called with (copied_bytes, total_bytes).
§Returns
A Result indicating success or failure of the copy operation.
Sourcepub fn calculate_dir_size(
path: &Path,
) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + '_>>
pub fn calculate_dir_size( path: &Path, ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + '_>>
Calculates the total size of a directory recursively.
This method traverses a directory tree and sums up the sizes of all files contained within it, including subdirectories.
§Arguments
path- The directory path to calculate the size for.
§Returns
A Future that resolves to a Result containing the total size in bytes.
Sourcepub async fn find_duplicates(paths: &[PathBuf]) -> Result<Vec<Vec<PathBuf>>>
pub async fn find_duplicates(paths: &[PathBuf]) -> Result<Vec<Vec<PathBuf>>>
Finds duplicate files by comparing their content hashes.
This method analyzes a list of file paths and groups files that have identical content based on SHA-256 hash comparison.
§Arguments
paths- A slice of file paths to analyze for duplicates.
§Returns
A Result containing a vector of groups, where each group contains
paths to files with identical content.
Auto Trait Implementations§
impl Freeze for FileUtils
impl RefUnwindSafe for FileUtils
impl Send for FileUtils
impl Sync for FileUtils
impl Unpin for FileUtils
impl UnsafeUnpin for FileUtils
impl UnwindSafe for FileUtils
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<T> Fruit for T
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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 more