From 71ad5b56aeaf1aaaef462b1770677baef122dbae Mon Sep 17 00:00:00 2001 From: gagliardetto Date: Sun, 8 Oct 2023 14:08:23 +0200 Subject: [PATCH] Handle the case where the requested amount is larger than the chunk --- readahead/readahead.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/readahead/readahead.go b/readahead/readahead.go index dd1d5053..bea5cd30 100644 --- a/readahead/readahead.go +++ b/readahead/readahead.go @@ -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)