Skip to main content

File

Struct File 

Source
pub struct File<'a> { /* private fields */ }
Expand description

Represents a file in the PFS.

Use read_at() for positional reads (thread-safe, &self), or as_slice() for zero-copy access when available.

Files may be compressed, in which case you should use pfsc::PfscImage as an Image adapter.

§Example

let pfs = orbis_pfs::open_slice(&data, None)?;
let root = pfs.root().open()?;

if let Some(orbis_pfs::directory::DirEntry::File(file)) = root.get(b"example.txt") {
    let mut contents = vec![0u8; file.len() as usize];
    file.read_at(0, &mut contents)?;
    println!("File contents: {}", String::from_utf8_lossy(&contents));
}

Implementations§

Source§

impl<'a> File<'a>

Source

pub fn mode(&self) -> u16

Source

pub fn flags(&self) -> u32

Source

pub fn len(&self) -> u64

Source

pub fn compressed_len(&self) -> u64

Source

pub fn atime(&self) -> u64

Returns the last access time as seconds since the Unix epoch.

Source

pub fn mtime(&self) -> u64

Returns the last modification time as seconds since the Unix epoch.

Source

pub fn ctime(&self) -> u64

Returns the last metadata change time as seconds since the Unix epoch.

Source

pub fn birthtime(&self) -> u64

Returns the creation time as seconds since the Unix epoch.

Source

pub fn mtimensec(&self) -> u32

Returns the sub-second nanosecond component of mtime().

Source

pub fn atimensec(&self) -> u32

Returns the sub-second nanosecond component of atime().

Source

pub fn ctimensec(&self) -> u32

Returns the sub-second nanosecond component of ctime().

Source

pub fn birthnsec(&self) -> u32

Returns the sub-second nanosecond component of birthtime().

Source

pub fn uid(&self) -> u32

Source

pub fn gid(&self) -> u32

Source

pub fn is_compressed(&self) -> bool

Source

pub fn is_empty(&self) -> bool

Source

pub fn as_slice(&self) -> Option<&'a [u8]>

Returns the file contents as a borrowed slice without a copy.

This returns Some only when all of the following are true:

  • The PFS was opened via open_slice() with an unencrypted image
  • The file is not compressed
  • The file’s blocks are laid out contiguously in the image

For compressed files, use pfsc::PfscImage instead. When this returns None, use read_at() as a fallback.

Source

pub fn read_at(&self, offset: u64, buf: &mut [u8]) -> Result<usize>

Reads file data at the given offset without modifying any cursor.

This is the primary read method. It takes &self (not &mut self) and requires no synchronization, making it safe to call from multiple threads concurrently.

Source

pub fn reader(&self) -> FileReader<'a>

Creates a FileReader that implements Read and Seek.

This is useful when you need to pass a PFS file to APIs that expect standard I/O traits (e.g. io::copy, decompressors, parsers).

Each reader maintains its own cursor position. Multiple readers can exist concurrently for the same file.

§Example
use std::io::Read;

let pfs = orbis_pfs::open_slice(&data, None)?;
let root = pfs.root().open()?;

if let Some(orbis_pfs::directory::DirEntry::File(file)) = root.get(b"example.txt") {
    let mut reader = file.reader();
    let mut contents = String::new();
    reader.read_to_string(&mut contents)?;
}
Source

pub fn into_image(self) -> PfsFileImage<'a>

Converts this file handle into a PfsFileImage for use as an Image source (e.g. to open a nested PFS or wrap in PfscImage).

Trait Implementations§

Source§

impl<'a> Clone for File<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for File<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for File<'a>

§

impl<'a> !RefUnwindSafe for File<'a>

§

impl<'a> Send for File<'a>

§

impl<'a> Sync for File<'a>

§

impl<'a> Unpin for File<'a>

§

impl<'a> !UnwindSafe for File<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.