@@ -451,7 +451,7 @@ pub fn readSegmentFile(dir: fs.Dir, info: SegmentInfo, segment: *FileSegment) !v
451
451
452
452
const block_size = header .block_size ;
453
453
const padding_size = block_size - fixed_buffer_stream .pos % block_size ;
454
- try reader . skipBytes ( padding_size , .{} );
454
+ try fixed_buffer_stream . seekBy ( @intCast ( padding_size ) );
455
455
456
456
const blocks_data_start = fixed_buffer_stream .pos ;
457
457
@@ -462,23 +462,24 @@ pub fn readSegmentFile(dir: fs.Dir, info: SegmentInfo, segment: *FileSegment) !v
462
462
var num_blocks : u32 = 0 ;
463
463
var crc = std .hash .crc .Crc64Xz .init ();
464
464
465
- var block_data_buffer : [ max_block_size ] u8 = undefined ;
466
- var block_data = block_data_buffer [0 .. block_size ];
467
- while ( true ) {
468
- try reader . readNoEof ( block_data ) ;
465
+ var ptr = blocks_data_start ;
466
+ while ( ptr + block_size <= raw_data . len ) {
467
+ const block_data = raw_data [ ptr .. ptr + block_size ];
468
+ ptr += block_size ;
469
469
const block_header = try decodeBlockHeader (block_data , segment .min_doc_id );
470
470
if (block_header .num_items == 0 ) {
471
471
break ;
472
472
}
473
473
segment .index .appendAssumeCapacity (block_header .first_item .hash );
474
474
num_items += block_header .num_items ;
475
475
num_blocks += 1 ;
476
- crc .update (block_data [0 .. ] );
476
+ crc .update (block_data );
477
477
}
478
-
479
- const blocks_data_end = fixed_buffer_stream .pos ;
478
+ const blocks_data_end = ptr ;
480
479
segment .blocks = raw_data [blocks_data_start .. blocks_data_end ];
481
480
481
+ try fixed_buffer_stream .seekBy (@intCast (segment .blocks .len ));
482
+
482
483
const footer = try unpacker .read (SegmentFileFooter );
483
484
if (footer .magic != segment_file_footer_magic_v1 ) {
484
485
return error .InvalidSegment ;
0 commit comments