From 07737635dee87c115158351c592768aa3c86d108 Mon Sep 17 00:00:00 2001 From: jmeaster30 Date: Thu, 6 Apr 2023 00:08:32 -0400 Subject: [PATCH] Fixed issue with printing null bytes and this should allow us to read any number of bytes from the buffer even if it is more bytes than the buffer --- libvore/vbufferedfile.go | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/libvore/vbufferedfile.go b/libvore/vbufferedfile.go index db40cd0..947513c 100644 --- a/libvore/vbufferedfile.go +++ b/libvore/vbufferedfile.go @@ -46,31 +46,21 @@ func (v *VBufferedFile) Read(p []byte) (int, error) { // there is probably a fancier way to do this outputOffset := 0 outputSize := len(p) - for v.currentOffset < v.maxOffset && outputOffset < outputSize { - p[outputOffset] = v.buffer[v.currentOffset-v.minOffset] - v.currentOffset += 1 - outputOffset += 1 - } - - if outputOffset == outputSize { - return outputOffset, nil - } - - // resizes buffer - _, err := v.Seek(0, io.SeekCurrent) - if err != nil { - return outputOffset, err - } + for { + for v.currentOffset < v.maxOffset && outputOffset < outputSize { + p[outputOffset] = v.buffer[v.currentOffset-v.minOffset] + v.currentOffset += 1 + outputOffset += 1 + } - if v.currentOffset == v.maxOffset { - panic("THIS SHOULDN'T HAPPEN I DON'T THINK... EOF?") - } + if outputOffset == outputSize { + break + } - // This probably doesn't work if we are reading over 8kb in one go. Will need to make this more sophisticated - for v.currentOffset < v.maxOffset && outputOffset < outputSize { - p[outputOffset] = v.buffer[v.currentOffset-v.minOffset] - v.currentOffset += 1 - outputOffset += 1 + _, err := v.Seek(0, io.SeekCurrent) // we seek to where we are now to recenter the buffer + if err != nil { + return outputOffset, err + } } return outputOffset, nil