Struct omf::file::Reader

source ·
pub struct Reader { /* private fields */ }
Expand description

OMF reader object.

Typical usage pattern is:

  1. Create the reader object.
  2. Optional: retrieve the file version with reader.version().
  3. Optional: adjust the limits with reader.set_limits(...).
  4. Read the project from the file with reader.project().
  5. Iterate through the project’s contents to find the elements and attributes you want to load.
  6. For each of those items load the array or image data.

Warning: When loading arrays and images from OMF files, beware of “zip bombs” where data is maliciously crafted to expand to an excessive size when decompressed, leading to a potential denial of service attack. Use the limits provided check arrays sizes before allocating memory.

Implementations§

source§

impl Reader

source

pub fn image(&self, image: &Array<Image>) -> Result<DynamicImage, Error>

Read and decode an image.

source§

impl Reader

source

pub fn array_scalars(&self, array: &Array<Scalar>) -> Result<Scalars, Error>

Read an array_type::Scalar array.

source

pub fn array_vertices(&self, array: &Array<Vertex>) -> Result<Vertices, Error>

Read an array_type::Vertex array.

source

pub fn array_segments( &self, array: &Array<Segment>, ) -> Result<GenericPrimitives<2>, Error>

Read an array_type::Segment array.

source

pub fn array_triangles( &self, array: &Array<Triangle>, ) -> Result<GenericPrimitives<3>, Error>

Read an array_type::Triangle array.

source

pub fn array_names(&self, array: &Array<Name>) -> Result<Names, Error>

Read an array_type::Name array.

source

pub fn array_gradient(&self, array: &Array<Gradient>) -> Result<Gradient, Error>

Read an array_type::Gradient array.

source

pub fn array_texcoords( &self, array: &Array<Texcoord>, ) -> Result<Texcoords, Error>

Read an array_type::Texcoord array.

source

pub fn array_boundaries( &self, array: &Array<Boundary>, ) -> Result<Boundaries, Error>

Read an array_type::Boundary array.

source

pub fn array_regular_subblocks( &self, array: &Array<RegularSubblock>, ) -> Result<RegularSubblocks, Error>

source

pub fn array_freeform_subblocks( &self, array: &Array<FreeformSubblock>, ) -> Result<FreeformSubblocks, Error>

source

pub fn array_numbers(&self, array: &Array<Number>) -> Result<Numbers, Error>

Read an array_type::Number array.

source

pub fn array_indices(&self, array: &Array<Index>) -> Result<Indices, Error>

Read an array_type::Index array.

source

pub fn array_vectors(&self, array: &Array<Vector>) -> Result<Vectors, Error>

Read an array_type::Vector array.

source

pub fn array_text(&self, array: &Array<Text>) -> Result<Text, Error>

Read a `array_type::Text array.

source

pub fn array_booleans(&self, array: &Array<Boolean>) -> Result<Booleans, Error>

Read an array_type::Boolean array.

source

pub fn array_colors(&self, array: &Array<Color>) -> Result<Colors, Error>

Read an array_type::Color array.

source§

impl Reader

source

pub fn new(file: File) -> Result<Self, Error>

Creates the reader from a SeekRead implementation.

Makes only the minimum number of reads to check the file header and footer. Fails with an error if an IO error occurs or the file isn’t in OMF 2 format.

source

pub fn open(path: impl AsRef<Path>) -> Result<Self, Error>

Creates a reader by opening the given path.

source

pub fn limits(&self) -> Limits

Returns the current limits.

source

pub fn set_limits(&mut self, limits: Limits)

Sets the memory limits.

These limits prevent the reader from consuming excessive system resources, which might allow denial of service attacks with maliciously crafted files. Running without limits is not recommended.

source

pub fn version(&self) -> [u32; 2]

Return the version number of the file, which can only be [2, 0] right now.

source

pub fn project(&self) -> Result<(Project, Problems), Error>

Reads, validates, and returns the root Project object from the file.

Fails with an error if an IO error occurs, the json_bytes limit is exceeded, or validation fails. Validation warnings are returned alongside the project if successful or included with the errors if not.

source

pub fn array_compressed_size( &self, array: &Array<impl ArrayType>, ) -> Result<u64, Error>

Returns the size in bytes of the compressed array.

source

pub fn array_bytes_reader( &self, array: &Array<impl ArrayType>, ) -> Result<SubFile, Error>

Returns a sub-file for reading raw bytes from the file.

Fails with an error if the range is invalid. The contents are not checked or validated by this method. The caller must ensure they are valid and safe to use. This function doesn’t check against any limit.

source

pub fn array_bytes( &self, array: &Array<impl ArrayType>, ) -> Result<Vec<u8>, Error>

Return the compressed bytes of an array.

The will allocate memory to store the result. Call array_compressed_size to find out how much will be allocated.

Auto Trait Implementations§

§

impl Freeze for Reader

§

impl RefUnwindSafe for Reader

§

impl Send for Reader

§

impl Sync for Reader

§

impl Unpin for Reader

§

impl UnwindSafe for Reader

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