splix commented on code in PR #530:
URL: https://github.com/apache/avro-rs/pull/530#discussion_r3039860647


##########
avro/src/reader/block.rs:
##########
@@ -295,6 +355,36 @@ impl<'r, R: Read> Block<'r, R> {
     }
 }
 
+impl<R: Read + Seek> Block<'_, R> {
+    /// Seek the underlying stream to `offset` and read the block there.
+    /// Validates the sync marker to confirm it's a real block boundary.
+    /// Returns an error if no valid block can be read at the offset
+    /// (e.g., the offset is at or past EOF).
+    pub(super) fn seek_to_block(&mut self, offset: u64) -> AvroResult<()> {
+        self.reader
+            .seek(SeekFrom::Start(offset))
+            .map_err(Details::SeekToBlock)?;
+
+        self.buf.clear();
+        self.buf_idx = 0;
+        self.message_count = 0;
+        self.current_block_info = None;
+
+        // read_block_next treats UnexpectedEof as a clean end-of-stream
+        // (returns Ok with message_count=0). That's correct for forward
+        // iteration but wrong here — the caller asked for a specific block.
+        self.read_block_next()?;
+        if self.is_empty() {

Review Comment:
   That was a confusing part. Please take a look at the update



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to