Skip to main content

CdxReader

Struct CdxReader 

Source
pub struct CdxReader<R: Read + Seek> { /* private fields */ }
Expand description

Reader for Codex document archives.

CdxReader opens and validates .cdx files, providing access to their contents. The reader validates the archive structure on creation and provides lazy access to individual files.

§Example

use cdx_core::archive::CdxReader;

let mut reader = CdxReader::open("document.cdx")?;

// Access the manifest
let manifest = reader.manifest();
println!("Document state: {:?}", manifest.state);

// Read a file from the archive
let content = reader.read_file("content/document.json")?;

Implementations§

Source§

impl CdxReader<BufReader<File>>

Source

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

Open a Codex document from a file path.

§Errors

Returns an error if:

  • The file cannot be opened
  • The file is not a valid ZIP archive
  • Required files are missing
  • The manifest is invalid
Source§

impl CdxReader<Cursor<Vec<u8>>>

Source

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

Open a Codex document from bytes in memory.

§Errors

Returns an error if:

  • The data is not a valid ZIP archive
  • Required files are missing
  • The manifest is invalid
Source§

impl<R: Read + Seek> CdxReader<R>

Source

pub fn new(reader: R) -> Result<Self>

Create a new reader from any Read + Seek source.

This enables reading from files, memory buffers, network streams, etc.

§Errors

Returns an error if:

  • The source is not a valid ZIP archive
  • Required files are missing
  • The manifest is invalid
Source

pub fn manifest(&self) -> &Manifest

Get a reference to the document manifest.

Source

pub fn read_file(&mut self, path: &str) -> Result<Vec<u8>>

Read a file from the archive.

§Errors

Returns an error if:

  • The path contains traversal patterns (security check)
  • The file does not exist in the archive
  • Reading the file fails
Source

pub fn read_file_verified( &mut self, path: &str, expected_hash: &DocumentId, ) -> Result<Vec<u8>>

Read a file and verify its hash against the expected hash.

§Errors

Returns an error if:

  • The path contains traversal patterns
  • The file does not exist
  • The hash does not match the expected value
Source

pub fn read_content(&mut self) -> Result<Vec<u8>>

Read the content file.

This is a convenience method for reading content/document.json.

§Errors

Returns an error if reading the content file fails.

Source

pub fn read_dublin_core(&mut self) -> Result<Vec<u8>>

Read the Dublin Core metadata file.

This is a convenience method for reading metadata/dublin-core.json.

§Errors

Returns an error if reading the metadata file fails.

Source

pub fn file_exists(&self, path: &str) -> Result<bool>

Check if a file exists in the archive.

§Errors

Returns an error if the path contains traversal patterns.

Source

pub fn file_names(&self) -> Vec<String>

Get the list of all file paths in the archive.

Source

pub fn file_count(&self) -> usize

Get the number of files in the archive.

Source

pub fn hash_algorithm(&self) -> HashAlgorithm

Get the hash algorithm used by this document.

Source

pub fn read_phantoms(&mut self) -> Result<Option<PhantomClusters>>

Read phantom clusters from the archive.

Returns None if the phantom clusters file doesn’t exist.

§Errors

Returns an error if the file exists but cannot be parsed.

Source

pub fn verify_hashes(&mut self) -> Result<()>

Verify all file hashes in the manifest.

This checks:

  • Content file hash
  • Presentation file hashes (if any)
§Errors

Returns an error if any hash verification fails.

Auto Trait Implementations§

§

impl<R> Freeze for CdxReader<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for CdxReader<R>
where R: RefUnwindSafe,

§

impl<R> Send for CdxReader<R>
where R: Send,

§

impl<R> Sync for CdxReader<R>
where R: Sync,

§

impl<R> Unpin for CdxReader<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for CdxReader<R>
where R: UnsafeUnpin,

§

impl<R> UnwindSafe for CdxReader<R>
where R: UnwindSafe,

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more