@@ -143,19 +143,25 @@ func (br *BlockReader) Next() (blocks.Block, error) {
143143
144144// BlockMetadata contains metadata about a block's section in a CAR file/stream.
145145//
146- // There are two offsets for the block data which will be the same if the
147- // original CAR is a CARv1, but will differ if the original CAR is a CARv2. In
148- // the case of a CARv2, SourceOffset will be the offset from the beginning of
146+ // There are two offsets for the block section which will be the same if the
147+ // original CAR is a CARv1, but will differ if the original CAR is a CARv2.
148+ //
149+ // The block section offset is position where the CAR section begins; that is,
150+ // the begining of the length prefix (varint) prior to the CID and the block
151+ // data. Reading the varint at the offset will give the length of the rest of
152+ // the section (CID+data).
153+ //
154+ // In the case of a CARv2, SourceOffset will be the offset from the beginning of
149155// the file/steam, and Offset will be the offset from the beginning of the CARv1
150156// payload container within the CARv2.
151157//
152158// Offset is useful for index generation which requires an offset from the CARv1
153- // payload; while SourceOffset is useful for direct block reads out of the
159+ // payload; while SourceOffset is useful for direct section reads out of the
154160// source file/stream regardless of version.
155161type BlockMetadata struct {
156162 cid.Cid
157- Offset uint64 // Offset of the block data in the container CARv1
158- SourceOffset uint64 // SourceOffset is the offset of block data in the source file/stream
163+ Offset uint64 // Offset of the section data in the container CARv1
164+ SourceOffset uint64 // SourceOffset is the offset of section data in the source file/stream
159165 Size uint64
160166}
161167
@@ -185,7 +191,7 @@ func (br *BlockReader) SkipNext() (*BlockMetadata, error) {
185191 }
186192
187193 blockSize := sectionSize - uint64 (cidSize )
188- blockOffset := br .offset + lenSize + uint64 ( cidSize )
194+ blockOffset := br .offset
189195
190196 // move our reader forward; either by seeking or slurping
191197
@@ -231,7 +237,7 @@ func (br *BlockReader) SkipNext() (*BlockMetadata, error) {
231237 }
232238 }
233239
234- br .offset = blockOffset + blockSize
240+ br .offset = br . offset + lenSize + uint64 ( cidSize ) + blockSize
235241
236242 return & BlockMetadata {
237243 Cid : c ,
0 commit comments