pub struct FileStore { /* private fields */ }Expand description
Storage for all open PostScript files.
Implementations§
Source§impl FileStore
impl FileStore
Sourcepub fn add_embedded_file(&mut self, path: &str, data: &'static [u8])
pub fn add_embedded_file(&mut self, path: &str, data: &'static [u8])
Register an embedded file mapping (path → static byte data).
Sourcepub fn get_embedded_file(&self, path: &str) -> Option<&'static [u8]>
pub fn get_embedded_file(&self, path: &str) -> Option<&'static [u8]>
Look up an embedded file by path. Returns the data if found.
Normalizes the path by stripping leading / and collapsing // to /
to handle paths like /resources/Font//Helvetica.t1 built by PS code.
Sourcepub fn open(&mut self, name: &str, mode: &str) -> Result<EntityId>
pub fn open(&mut self, name: &str, mode: &str) -> Result<EntityId>
Open a file, returning its EntityId.
For read mode, checks the embedded file map first (for WASM builds).
Sourcepub fn create_filter(&mut self, source: EntityId, kind: FilterKind) -> EntityId
pub fn create_filter(&mut self, source: EntityId, kind: FilterKind) -> EntityId
Create a filter file that reads from source through kind.
Sourcepub fn create_filter_with_data(
&mut self,
source: EntityId,
kind: FilterKind,
data: Vec<u8>,
) -> EntityId
pub fn create_filter_with_data( &mut self, source: EntityId, kind: FilterKind, data: Vec<u8>, ) -> EntityId
Create a filter file with pre-filled output buffer (for DCTDecode).
Sourcepub fn create_encode_filter(
&mut self,
target: EntityId,
kind: FilterKind,
) -> EntityId
pub fn create_encode_filter( &mut self, target: EntityId, kind: FilterKind, ) -> EntityId
Create an encode filter that writes encoded data to target.
Sourcepub fn create_string_source(&mut self, data: Vec<u8>) -> EntityId
pub fn create_string_source(&mut self, data: Vec<u8>) -> EntityId
Create a string-backed data source.
Sourcepub fn create_proc_source(&mut self, proc: PsObject) -> EntityId
pub fn create_proc_source(&mut self, proc: PsObject) -> EntityId
Create a not-yet-run procedure data source (PLRM 3.8.4).
The procedure is executed by Context::pump_proc_sources, which
replaces this handle with a StringSource. See
FileHandle::PendingProc.
Sourcepub fn pending_proc_source(
&self,
entity: EntityId,
) -> Option<(EntityId, PsObject, bool)>
pub fn pending_proc_source( &self, entity: EntityId, ) -> Option<(EntityId, PsObject, bool)>
Find the first procedure data source underneath entity that has not
been run yet, following the chain of filters down to their sources.
Returns the source’s entity, the procedure to run, and whether a
FlateDecode filter sits anywhere above it — see
Context::pump_proc_sources for what that flag is for.
Sourcepub fn close_pending_proc(&mut self, entity: EntityId)
pub fn close_pending_proc(&mut self, entity: EntityId)
Close a not-yet-run procedure data source whose procedure did not
survive a restore.
PLRM 3.7.3: restore closes any file opened since the matching save.
A procedure source created inside the save is exactly that, and its
procedure lives in the local VM the restore just reclaimed, so the
handle has to go rather than be left pointing at a retired array.
Sourcepub fn pending_proc_handles(&self) -> Vec<(EntityId, PsObject)>
pub fn pending_proc_handles(&self) -> Vec<(EntityId, PsObject)>
Every not-yet-run procedure data source, as (file entity, procedure).
PendingProc is the only place FileStore holds a PsObject, so it is
the only thing here the VM audit has to treat as a root: the procedure
keeps an array alive that a restore would otherwise be free to retire.
Sourcepub fn install_proc_data(&mut self, entity: EntityId, data: Vec<u8>)
pub fn install_proc_data(&mut self, entity: EntityId, data: Vec<u8>)
Replace a PendingProc handle with the bytes its procedure produced.
Sourcepub fn get_remaining_bytes(&self, entity: EntityId) -> &[u8] ⓘ
pub fn get_remaining_bytes(&self, entity: EntityId) -> &[u8] ⓘ
Get remaining unread bytes from a StringSource file as a slice.
Returns a borrowed slice of the remaining bytes (from pos to end).
For non-StringSource files, returns an empty slice.
Sourcepub fn advance_position(&mut self, entity: EntityId, n: usize)
pub fn advance_position(&mut self, entity: EntityId, n: usize)
Advance the read position of a StringSource file by n bytes.
Sourcepub fn line_num(&self, entity: EntityId) -> u32
pub fn line_num(&self, entity: EntityId) -> u32
Get the current line number (1-based) for a file.
Sourcepub fn add_pending_newlines(&mut self, entity: EntityId, count: u32)
pub fn add_pending_newlines(&mut self, entity: EntityId, count: u32)
Record newlines as pending. They will be applied to line_num at the
start of the next token read via flush_pending_newlines.
Sourcepub fn flush_pending_newlines(&mut self, entity: EntityId)
pub fn flush_pending_newlines(&mut self, entity: EntityId)
Apply any pending newlines to line_num. Call this at the start of
each token read so the line number reflects the current token’s line.
Sourcepub fn read_byte(&mut self, entity: EntityId) -> Result<Option<u8>>
pub fn read_byte(&mut self, entity: EntityId) -> Result<Option<u8>>
Read one byte from a file. Returns None on EOF.
Sourcepub fn read_into(&mut self, entity: EntityId, buf: &mut [u8]) -> Result<usize>
pub fn read_into(&mut self, entity: EntityId, buf: &mut [u8]) -> Result<usize>
Read into a buffer. Returns number of bytes actually read.
Sourcepub fn write_byte(&mut self, entity: EntityId, byte: u8) -> Result<()>
pub fn write_byte(&mut self, entity: EntityId, byte: u8) -> Result<()>
Write one byte to a file.
Sourcepub fn write_from(&mut self, entity: EntityId, buf: &[u8]) -> Result<()>
pub fn write_from(&mut self, entity: EntityId, buf: &[u8]) -> Result<()>
Write bytes from a buffer.
Sourcepub fn readline(
&mut self,
entity: EntityId,
buf: &mut [u8],
) -> Result<(usize, bool)>
pub fn readline( &mut self, entity: EntityId, buf: &mut [u8], ) -> Result<(usize, bool)>
Read a line (up to newline or EOF). Returns (bytes_read, hit_newline).
Sourcepub fn is_readable(&self, entity: EntityId) -> bool
pub fn is_readable(&self, entity: EntityId) -> bool
Check if a file entity is readable (open, not stdout/stderr).
Sourcepub fn read_n_bytes(&mut self, entity: EntityId, n: usize) -> Result<Vec<u8>>
pub fn read_n_bytes(&mut self, entity: EntityId, n: usize) -> Result<Vec<u8>>
Read exactly N bytes from a file. Returns error on premature EOF.
Sourcepub fn putback_bytes(&mut self, entity: EntityId, bytes: &[u8])
pub fn putback_bytes(&mut self, entity: EntityId, bytes: &[u8])
Put bytes back into a file so they’ll be returned on the next read. For filters, uses the filter’s putback buffer. For StringSource, decrements position.
Sourcepub fn is_seekable(&self, entity: EntityId) -> bool
pub fn is_seekable(&self, entity: EntityId) -> bool
Check if a file entity is seekable (disk file).
Sourcepub fn bytes_available(&mut self, entity: EntityId) -> i32
pub fn bytes_available(&mut self, entity: EntityId) -> i32
Get bytes available for reading. Returns -1 for stdin/filters/unknown, closed files, write-only files, and files at EOF. For disk files opened for reading, returns remaining bytes.
Sourcepub fn set_name(&mut self, entity: EntityId, name: String)
pub fn set_name(&mut self, entity: EntityId, name: String)
Set the name of a file (e.g. to record the resolved path for run).
Sourcepub fn putback_byte(&mut self, entity: EntityId, byte: u8)
pub fn putback_byte(&mut self, entity: EntityId, byte: u8)
Push a byte back onto a filter’s putback buffer.