Skip to main content

FileStore

Struct FileStore 

Source
pub struct FileStore { /* private fields */ }
Expand description

Storage for all open PostScript files.

Implementations§

Source§

impl FileStore

Source

pub fn new() -> Self

Create a new FileStore with stdin/stdout/stderr pre-allocated.

Source

pub fn add_embedded_file(&mut self, path: &str, data: &'static [u8])

Register an embedded file mapping (path → static byte data).

Source

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.

Source

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

Source

pub fn create_filter(&mut self, source: EntityId, kind: FilterKind) -> EntityId

Create a filter file that reads from source through kind.

Source

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

Source

pub fn create_encode_filter( &mut self, target: EntityId, kind: FilterKind, ) -> EntityId

Create an encode filter that writes encoded data to target.

Source

pub fn create_string_source(&mut self, data: Vec<u8>) -> EntityId

Create a string-backed data source.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn install_proc_data(&mut self, entity: EntityId, data: Vec<u8>)

Replace a PendingProc handle with the bytes its procedure produced.

Source

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.

Source

pub fn advance_position(&mut self, entity: EntityId, n: usize)

Advance the read position of a StringSource file by n bytes.

Source

pub fn line_num(&self, entity: EntityId) -> u32

Get the current line number (1-based) for a file.

Source

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.

Source

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.

Source

pub fn close(&mut self, entity: EntityId) -> Result<()>

Close a file.

Source

pub fn read_byte(&mut self, entity: EntityId) -> Result<Option<u8>>

Read one byte from a file. Returns None on EOF.

Source

pub fn read_into(&mut self, entity: EntityId, buf: &mut [u8]) -> Result<usize>

Read into a buffer. Returns number of bytes actually read.

Source

pub fn write_byte(&mut self, entity: EntityId, byte: u8) -> Result<()>

Write one byte to a file.

Source

pub fn write_from(&mut self, entity: EntityId, buf: &[u8]) -> Result<()>

Write bytes from a buffer.

Source

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

Source

pub fn position(&mut self, entity: EntityId) -> Result<u64>

Get file position.

Source

pub fn set_position(&mut self, entity: EntityId, pos: u64) -> Result<()>

Set file position.

Source

pub fn flush(&mut self, entity: EntityId) -> Result<()>

Flush a file.

Source

pub fn is_open(&self, entity: EntityId) -> bool

Check if a file entity is valid (not closed).

Source

pub fn is_readable(&self, entity: EntityId) -> bool

Check if a file entity is readable (open, not stdout/stderr).

Source

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.

Source

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.

Source

pub fn is_seekable(&self, entity: EntityId) -> bool

Check if a file entity is seekable (disk file).

Source

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.

Source

pub fn name(&self, entity: EntityId) -> &str

Get the name of a file.

Source

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

Source

pub fn mode(&self, entity: EntityId) -> &str

Get the mode of a file.

Source

pub fn len(&self) -> usize

Number of files allocated.

Source

pub fn is_empty(&self) -> bool

Whether no files are allocated.

Source

pub fn putback_byte(&mut self, entity: EntityId, byte: u8)

Push a byte back onto a filter’s putback buffer.

Source

pub fn read_all(&mut self, entity: EntityId) -> Result<Vec<u8>>

Read all remaining bytes from a source (used by DCTDecode at creation).

Source§

impl FileStore

Source

pub fn create_dct_filter( &mut self, source: EntityId, color_transform: Option<bool>, ) -> EntityId

Create a lazy DCTDecode filter (decodes on first read).

Source

pub fn create_dct_encode_filter( &mut self, target: EntityId, columns: u32, rows: u32, colors: u32, quality: u8, color_transform: bool, ) -> EntityId

Create a DCTEncode filter.

Trait Implementations§

Source§

impl Default for FileStore

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> 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, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

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

Source§

type Error = !

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.