pub struct OwnedFile<'a> { /* private fields */ }
Expand description
An object packaging a File
with the Node
from which it was constructed.
File
s reference data in the Node
objects that created them, so a File
cannot be used
after its corresponding Node
has been dropped. This object packages the two together,
creating an object that is valid for the lifetime of the owning Archive
.
This is a simple wrapper around an OwningHandle
that re-implements the Read
and
Seek
traits so that it can still be treated as a file. Deref
and
DerefMut
are also available to access the contained file.
Create an OwnedFile
using Node::into_owned_file
.
Methods from Deref<Target = File<'a>>§
Sourcepub fn to_bytes(&mut self) -> Result<Vec<u8>>
pub fn to_bytes(&mut self) -> Result<Vec<u8>>
Retrieve the entire contents of the file in the form of a byte Vec.
Sourcepub fn to_string(&mut self) -> Result<String>
pub fn to_string(&mut self) -> Result<String>
Retrieve the entire contents of the file in the form of a String.
This calls Read::read_to_string
under the hood. Consequently, a UTF-8 error
will be raised if the entire file is not valid UTF-8.
Sourcepub fn mmap<'b>(&'b mut self) -> Option<&'b [u8]>
pub fn mmap<'b>(&'b mut self) -> Option<&'b [u8]>
Map a file into memory for fast parallel random access.
This uses mmap
to map the file into memory. It will fail and return None
if the
file is compressed or fragmented. If the DontCompress
and DontFragment
options are set for a file at
archive creation time, it will be added to the archive in one contiguous unmodified chunk.
This is necessary because mmap
provides a view into a file exactly as it is on-disk;
there is no opportunity for the library to apply decompression or other transformations
when mapping.
let map = file.mmap().expect("File is not mmappable");
println!("{}", str::from_utf8(map)?);
Trait Implementations§
Source§impl<'a> Read for OwnedFile<'a>
impl<'a> Read for OwnedFile<'a>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read
, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf
. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf
. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf
. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moreSource§impl<'a> Seek for OwnedFile<'a>
impl<'a> Seek for OwnedFile<'a>
Source§fn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
1.55.0 · Source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
Source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
seek_stream_len
)