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<R: Read + Seek> CdxReader<R>
impl<R: Read + Seek> CdxReader<R>
Sourcepub fn new(reader: R) -> Result<Self>
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
Sourcepub fn read_file(&mut self, path: &str) -> Result<Vec<u8>>
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
Sourcepub fn read_file_verified(
&mut self,
path: &str,
expected_hash: &DocumentId,
) -> Result<Vec<u8>>
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
Sourcepub fn read_content(&mut self) -> Result<Vec<u8>>
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.
Sourcepub fn read_dublin_core(&mut self) -> Result<Vec<u8>>
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.
Sourcepub fn file_exists(&self, path: &str) -> Result<bool>
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.
Sourcepub fn file_names(&self) -> Vec<String>
pub fn file_names(&self) -> Vec<String>
Get the list of all file paths in the archive.
Sourcepub fn file_count(&self) -> usize
pub fn file_count(&self) -> usize
Get the number of files in the archive.
Sourcepub fn hash_algorithm(&self) -> HashAlgorithm
pub fn hash_algorithm(&self) -> HashAlgorithm
Get the hash algorithm used by this document.
Sourcepub fn read_phantoms(&mut self) -> Result<Option<PhantomClusters>>
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.
Sourcepub fn verify_hashes(&mut self) -> Result<()>
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.