Skip to content

Commit

Permalink
Fixed issue with printing null bytes and this should allow us to read…
Browse files Browse the repository at this point in the history
… any number of bytes from the buffer even if it is more bytes than the buffer
  • Loading branch information
jmeaster30 committed Apr 6, 2023
1 parent e3cfb92 commit 0773763
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions libvore/vbufferedfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0773763

Please sign in to comment.