Skip to content

Commit

Permalink
Fixed issue with processing files that are less than 4096bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeaster30 committed Mar 29, 2023
1 parent ffee0d0 commit 9a3b599
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion libvore/bytecode.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func findMatches(insts []SearchInstruction, all bool, skip int, take int, last i
for currentState.status == INPROCESS {
inst := insts[currentState.programCounter]
currentState = inst.execute(currentState)
//fmt.Printf("PC: %d INST: %+v MATCH: '%s'\n", currentState.programCounter, inst, currentState.currentMatch)
//fmt.Printf("PC: %d INST: %+v STATE: %+v\n", currentState.programCounter, inst, currentState)
if currentState.status == INPROCESS && currentState.programCounter >= len(insts) {
currentState.SUCCESS()
}
Expand Down
12 changes: 10 additions & 2 deletions libvore/vbufferedfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,20 @@ func (v *VBufferedFile) Seek(offset int64, whence int) (int64, error) {
newStart = 0
}

if newStart >= v.fileSize-4096 {
fileBound := v.fileSize - 4096
if fileBound < 0 {
fileBound = v.fileSize
}
if newStart >= fileBound {
newStart = v.fileSize - 4096
if newStart < 0 {
newStart = 0
}
}

bytesRead, err := v.file.ReadAt(v.buffer, newStart)
if err != nil {
// it is actually expected to have an EOF error here when we are working with a file that is less than 4096 bytes
if err != nil && err != io.EOF {
return v.currentOffset, err
}
v.minOffset = newStart
Expand Down

0 comments on commit 9a3b599

Please sign in to comment.