Struct tectonic_io_base::InputHandle
source · pub struct InputHandle { /* private fields */ }
Expand description
Input handles are basically Read objects with a few extras. We don’t require the standard io::Seek because we need to provide a dummy implementation for GZip streams, which we wouldn’t be allowed to do because both the trait and the target struct are outside of our crate.
An important role for the InputHandle struct is computing a cryptographic
digest of the input file. The driver uses this information in order to
figure out if the TeX engine needs rerunning. TeX makes our life more
difficult, though, since it has somewhat funky file access patterns. LaTeX
file opens work by opening a file and immediately closing it, which tests
whether the file exists, and then by opening it again for real. Under the
hood, XeTeX reads a couple of bytes from each file upon open to sniff its
encoding. So we can’t just stream data from read()
calls into the SHA2
computer, since we end up seeking and reading redundant data.
The current system maintains some internal state that, so far, helps us Do
The Right Thing given all this. If there’s a seek on the file, we give up
on our digest computation. But if there’s a seek back to the file
beginning, we are open to the possibility of restarting the computation.
But if nothing is ever read from the file, we once again give up on the
computation. The ExecutionState
code then has further pieces that track
access to nonexistent files, which we treat as being equivalent to an
existing empty file for these purposes.
Implementations§
source§impl InputHandle
impl InputHandle
sourcepub fn new<T: 'static + InputFeatures>(
name: impl Into<String>,
inner: T,
origin: InputOrigin
) -> InputHandle ⓘ
pub fn new<T: 'static + InputFeatures>( name: impl Into<String>, inner: T, origin: InputOrigin ) -> InputHandle ⓘ
Create a new InputHandle wrapping an underlying type that implements
InputFeatures
.
sourcepub fn new_read_only<T: 'static + InputFeatures>(
name: impl Into<String>,
inner: T,
origin: InputOrigin
) -> InputHandle ⓘ
pub fn new_read_only<T: 'static + InputFeatures>( name: impl Into<String>, inner: T, origin: InputOrigin ) -> InputHandle ⓘ
Create a new InputHandle in read-only mode.
sourcepub fn origin(&self) -> InputOrigin
pub fn origin(&self) -> InputOrigin
Get the “origin” associated with this handle.
sourcepub fn into_inner(self) -> Box<dyn InputFeatures>
pub fn into_inner(self) -> Box<dyn InputFeatures>
Consumes the object and returns the underlying readable handle that it references.
sourcepub fn scan_remainder(&mut self) -> Result<()>
pub fn scan_remainder(&mut self) -> Result<()>
Read any remaining data in the file and incorporate them into the digest. This helps the rerun detection logic work correctly in the somewhat-unusual case that a file is read then written, but only part of the file is read, not the entire thing. This seems to happen with biblatex XML state files.
sourcepub fn into_name_digest(self) -> (String, Option<DigestData>)
pub fn into_name_digest(self) -> (String, Option<DigestData>)
Consumes the object and returns the SHA256 sum of the content that was read. No digest is returned if there was ever a seek on the input stream, since in that case the results will not be reliable. We also return None if the stream was never read, which is another common TeX access pattern: files are opened, immediately closed, and then opened again. Finally, no digest is returned if the file is marked read-only.
Trait Implementations§
source§impl InputFeatures for InputHandle
impl InputFeatures for InputHandle
source§fn get_size(&mut self) -> Result<usize>
fn get_size(&mut self) -> Result<usize>
TectonicIoError::NotSizeable
if the operation is not well-defined for this stream.source§impl Read for InputHandle
impl Read for InputHandle
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 Seek for InputHandle
impl Seek for InputHandle
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
)