-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Son Roy Almerol
committed
Nov 12, 2024
1 parent
0e13141
commit 7b68f5e
Showing
5 changed files
with
40 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package sftp | ||
|
||
import "io" | ||
|
||
type eofInjectingReaderAt struct { | ||
file io.ReaderAt | ||
length int64 | ||
} | ||
|
||
func NewEOFInjectingReaderAt(file io.ReaderAt, length int64) io.ReaderAt { | ||
return &eofInjectingReaderAt{file: file, length: length} | ||
} | ||
|
||
func (r *eofInjectingReaderAt) ReadAt(p []byte, off int64) (n int, err error) { | ||
if off >= r.length { | ||
// If reading beyond the file length, return EOF to simulate a proper end. | ||
return 0, io.EOF | ||
} | ||
|
||
// Attempt to read as usual. | ||
n, err = r.file.ReadAt(p, off) | ||
if err == io.ErrUnexpectedEOF || n < len(p) { | ||
// If an unexpected EOF or partial read, return what we have and inject EOF. | ||
return n, io.EOF | ||
} | ||
|
||
return n, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters