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 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.