Skip to content

Commit

Permalink
Fix readEOFSeen behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanBaulch committed Jan 17, 2025
1 parent ccdc8dc commit cfe59a2
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions backend/s3/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,12 @@ func (f *File) tempToS3() error {

// Read implements the standard for io.Reader.
func (f *File) Read(p []byte) (n int, err error) {
// s3 reader returns io.EOF when reading the last byte (but not past the last byte) to save on bandwidth,
// but we want to return io.EOF only when reading past the last byte
if f.readEOFSeen {
return 0, io.EOF
}

// check/initialize for reader
r, err := f.getReader()
if err != nil {
Expand All @@ -362,18 +368,6 @@ func (f *File) Read(p []byte) (n int, err error) {
if !errors.Is(err, io.EOF) {
return 0, utils.WrapReadError(err)
}
// s3 reader returns io.EOF when reading the last byte (but not past the last byte) to save on bandwidth,
// but we want to return io.EOF only when reading past the last byte
if f.readEOFSeen {
return 0, io.EOF
}
sz, err := f.Size()
if err != nil {
return 0, utils.WrapReadError(err)
}
if f.cursorPos+int64(read) > int64(sz) {
return read, utils.WrapReadError(err)
}
f.readEOFSeen = true
}

Expand Down Expand Up @@ -457,11 +451,8 @@ func (f *File) Seek(offset int64, whence int) (int64, error) {
}
f.cursorPos = pos

// Reset readEOFSeen if seeking to the beginning of the file
if f.cursorPos == 0 {
f.readEOFSeen = false
}

// set readEOFSeen if seeking to the end of the file
f.readEOFSeen = f.cursorPos >= int64(length)
f.seekCalled = true
return f.cursorPos, nil
}
Expand Down

0 comments on commit cfe59a2

Please sign in to comment.