Skip to main content

Reader

Struct Reader 

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

An open ASDF file.

Implementations§

Source§

impl Reader

Source

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

Open and scan a file from disk.

The file is memory-mapped, so block data is not read until it is used.

Source

pub fn from_bytes(bytes: Vec<u8>) -> Result<Self>

Scan an in-memory file.

Source

pub fn path(&self) -> Option<&Path>

The path this file was opened from, if it came from disk.

Source

pub fn bytes(&self) -> &[u8]

The whole file’s bytes.

Source

pub fn layout(&self) -> &Layout

The scanned layout.

Source

pub fn tree_text(&self) -> Option<&str>

The YAML tree’s text, if the file has a tree.

Source

pub fn tree(&self) -> Result<Option<Document>>

Parse the YAML tree.

A file with no tree – legitimate in exploded form – yields None.

Source

pub fn block_count(&self) -> usize

The number of binary blocks.

Source

pub fn block(&self, index: usize) -> Result<&BlockLocation>

A block’s location and header.

Source

pub fn block_raw(&self, index: usize) -> Result<&[u8]>

A block’s bytes exactly as stored, without decompressing.

For an uncompressed block this is the data itself; for a compressed one it is the compressed form.

Source

pub fn block_compression(&self, index: usize) -> Result<Compression>

The compression method a block uses.

Source

pub fn block_data(&self, index: usize) -> Result<Cow<'_, [u8]>>

A block’s data, decompressed if necessary.

An uncompressed block borrows straight from the file with no copy.

Source

pub fn verify_block_checksum( &self, index: usize, ) -> Result<(ChecksumStatus, [u8; 16])>

Verify a block’s MD5 checksum.

The returned digest is what the data actually hashes to, which is useful for reporting a mismatch.

§The Python asdf compatibility case

For a compressed block, the specification means the checksum to cover the bytes as stored. Python asdf 5.x and earlier instead checksum the uncompressed data (asdf#2015). libasdf works around this by consulting the file’s asdf_library metadata, and so do we: see Reader::has_python_checksum_bug. A compressed block whose stored bytes do not match is therefore retried against the decompressed bytes when the writer is known to be affected.

Source

pub fn has_python_checksum_bug(&self) -> bool

Whether this file was written by a Python asdf version that checksums compressed blocks incorrectly.

Matches libasdf’s test: the asdf_library name is asdf and its major version is 5 or below.

Source§

impl Reader

Source

pub fn external_block(&self, uri: &str) -> Result<Vec<u8>>

Resolve an external array source and read the data it names.

The standard makes source a URI relative to the file’s own, and exploded form writes one array per file with the data in block 0.

Resolution is deliberately narrow. The URI must be a relative path with no .. component and no scheme, so a file can only reach others beneath its own directory: a tree is untrusted input, and following an arbitrary path out of it would let a crafted file name anything on the machine. A file read from memory has no directory to resolve against and so resolves nothing.

Source

pub fn tree_inlined(&self) -> Result<Option<(Document, Vec<String>)>>

Parse the tree with every block-backed core/ndarray replaced by its data inline.

This is the transformation the ASDF Standard’s reference corpus asks for before comparing a file against its expected YAML. An array whose data lives in another file – exploded form’s external source – is resolved through Reader::external_block, which needs this file to have been read from disk.

Returns the transformed tree and the paths of any arrays that could not be inlined.

Trait Implementations§

Source§

impl Debug for Reader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.