MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / open

Method open

atomic-core/src/change/format_v3/reader/mod.rs:408–443  ·  view source on GitHub ↗

Open a V3 change file for reading. Reads and validates the 64-byte file header and the hash dedup table. After this call, the reader is positioned at the first section. # Arguments `reader` - The source to read from. # Returns A `ChangeReader` ready to read sections. # Errors - `FormatError::InvalidMagic` if the file doesn't start with `b"ATOM"`. - `FormatError::UnsupportedVersion` if the f

(reader: &'r mut R)

Source from the content-addressed store, hash-verified

406 /// let reader = ChangeReader::open(&mut cursor)?;
407 /// ```
408 pub fn open(reader: &'r mut R) -> FormatResult<Self> {
409 let mut hasher = blake3::Hasher::new();
410 let mut total_bytes_read: u64 = 0;
411
412 // 1. Read and validate file header (64 bytes)
413 let file_header = FileHeader::read_from(reader)?;
414 file_header.validate()?;
415 total_bytes_read += FileHeader::SIZE as u64;
416
417 // 2. Read hash dedup table
418 let hash_table_entry_count = file_header.hash_table_entries;
419 let hash_table = HashDedupTable::read_from(reader, hash_table_entry_count)?;
420 total_bytes_read += hash_table.serialized_size() as u64;
421
422 // Feed hash table bytes through the hasher (they are part of the content hash)
423 let mut hash_table_buf = Vec::with_capacity(hash_table.serialized_size());
424 hash_table.write_to(&mut hash_table_buf)?;
425 hasher.update(&hash_table_buf);
426
427 // 3. Compute expected total section count
428 let remaining_sections = file_header.total_section_count();
429
430 Ok(Self {
431 reader,
432 file_header,
433 hash_table,
434 hasher,
435 remaining_sections,
436 stats: ReaderStats {
437 total_bytes_read,
438 ..Default::default()
439 },
440 peeked: None,
441 sections_exhausted: false,
442 })
443 }
444
445 /// Returns a reference to the file header.
446 ///

Callers

nothing calls this directly

Calls 5

serialized_sizeMethod · 0.80
total_section_countMethod · 0.80
validateMethod · 0.45
write_toMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected