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 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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.