pub trait PathExt {
// Required methods
fn size_on_disk(&self) -> Result<u64>;
fn size_on_disk_fast(&self, metadata: &Metadata) -> Result<u64>;
}
Expand description
An extension trait for std::path::Path
to retrieve the on-disk size of a
given file.
Required Methods§
Sourcefn size_on_disk(&self) -> Result<u64>
fn size_on_disk(&self) -> Result<u64>
Get the on-disk size of the file at the given Path
.
use std::path::Path;
use filesize::PathExt;
let realsize = Path::new("Cargo.toml").size_on_disk()?;
Sourcefn size_on_disk_fast(&self, metadata: &Metadata) -> Result<u64>
fn size_on_disk_fast(&self, metadata: &Metadata) -> Result<u64>
Get the on-disk size of the file at the given Path
, using the provided
std::fs::Metadata
instance if possible.
This should normally only be used when metadata is cheaply available, for instance, during a directory traversal, or when metadata will be used for other purposes.
use std::path::Path;
use filesize::PathExt;
let path = Path::new("Cargo.toml");
let metadata = path.symlink_metadata()?;
let realsize = path.size_on_disk_fast(&metadata)?;