Clarify and fix State's EOF behavior
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"slices"
|
||||
"strings"
|
||||
)
|
||||
@ -142,10 +143,19 @@ type State[In any] struct {
|
||||
}
|
||||
|
||||
func (s State[In]) Read(dst []In) (n uint64, next State[In], err error) {
|
||||
if s.pos > math.MaxInt64 {
|
||||
return 0, s, io.EOF
|
||||
}
|
||||
nread, err := s.r.ReadAt(dst, int64(s.pos))
|
||||
if nread > 0 {
|
||||
s.pos += uint64(nread)
|
||||
}
|
||||
if nread == len(dst) && err == io.EOF {
|
||||
if nread == 0 {
|
||||
return 0, s, io.EOF
|
||||
}
|
||||
return uint64(nread), s, nil
|
||||
}
|
||||
return uint64(nread), s, err
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user