Skip to content

Commit

Permalink
Handle the case where the requested amount is larger than the chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
gagliardetto committed Oct 8, 2023
1 parent 3279987 commit 71ad5b5
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions readahead/readahead.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ func (cr *CachingReader) Read(p []byte) (int, error) {
return 0, nil
}

if len(p) > cr.chunkSize {
cr.buffer.Reset() // clear buffer
// If the read is larger than the chunk size, read directly from the file
return cr.file.Read(p)
}

// Refill the buffer if needed
if cr.buffer.Len() < len(p) {
tmp := make([]byte, cr.chunkSize)
Expand Down

0 comments on commit 71ad5b5

Please sign in to comment.