@@ -1396,7 +1396,7 @@ scan_file_for_valid_messages(Path) ->
13961396 {ok , Fd } ->
13971397 {ok , FileSize } = file :position (Fd , eof ),
13981398 {ok , _ } = file :position (Fd , bof ),
1399- Messages = scan (<<>>, Fd , 0 , FileSize , #{}, []),
1399+ Messages = scan (<<>>, Fd , 0 , FileSize , #{}, [], ? SCAN_BLOCK_SIZE ),
14001400 ok = file :close (Fd ),
14011401 case Messages of
14021402 [] ->
@@ -1412,8 +1412,8 @@ scan_file_for_valid_messages(Path) ->
14121412 Reason }}
14131413 end .
14141414
1415- scan (Buffer , Fd , Offset , FileSize , MsgIdsFound , Acc ) ->
1416- case file :read (Fd , ? SCAN_BLOCK_SIZE ) of
1415+ scan (Buffer , Fd , Offset , FileSize , MsgIdsFound , Acc , ScanSize ) ->
1416+ case file :read (Fd , ScanSize ) of
14171417 eof ->
14181418 Acc ;
14191419 {ok , Data0 } ->
@@ -1448,10 +1448,12 @@ scan_data(<<Size:64, MsgIdAndMsg:Size/binary, 255, Rest/bits>> = Data,
14481448% % This might be the start of a message.
14491449scan_data (<<Size :64 , Rest /bits >> = Data , Fd , Offset , FileSize , MsgIdsFound , Acc )
14501450 when byte_size (Rest ) < Size + 1 , Size < FileSize - Offset ->
1451- scan (Data , Fd , Offset , FileSize , MsgIdsFound , Acc );
1451+ RemainingMsgSize = Size - byte_size (Rest ),
1452+ ScanSize = max (? SCAN_BLOCK_SIZE , RemainingMsgSize + 1 ),
1453+ scan (Data , Fd , Offset , FileSize , MsgIdsFound , Acc , ScanSize );
14521454scan_data (Data , Fd , Offset , FileSize , MsgIdsFound , Acc )
14531455 when byte_size (Data ) < 8 ->
1454- scan (Data , Fd , Offset , FileSize , MsgIdsFound , Acc );
1456+ scan (Data , Fd , Offset , FileSize , MsgIdsFound , Acc , ? SCAN_BLOCK_SIZE );
14551457% % This is definitely not a message. Try the next byte.
14561458scan_data (<<_ , Rest /bits >>, Fd , Offset , FileSize , MsgIdsFound , Acc ) ->
14571459 scan_data (Rest , Fd , Offset + 1 , FileSize , MsgIdsFound , Acc ).
0 commit comments