8000 Merge pull request #285 from polygon-io/master · etherscan-io/sftp@3ee8d0b · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 3ee8d0b

Browse files
authored
Merge pull request pkg#285 from polygon-io/master
Add io.ReaderAt interface compatibility
2 parents 79788b4 + 00faa91 commit 3ee8d0b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

client.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,13 +839,22 @@ func (f *File) Name() string {
839839
// than calling Read multiple times. io.Copy will do this
840840
// automatically.
841841
func (f *File) Read(b []byte) (int, error) {
842+
r, err := f.ReadAt(b, int64( f.offset ))
843+
f.offset += uint64(r)
844+
return r, err
845+
}
846+
847+
// ReadAt reads up to len(b) byte from the File at a given offset `off`. It returns
848+
// the number of bytes read and an error, if any. ReadAt follows io.ReaderAt semantics,
849+
// so the file offset is not altered during the read.
850+
func (f *File) ReadAt(b []byte, off int64) (n int, err error) {
842851
// Split the read into multiple maxPacket sized concurrent reads
843852
// bounded by maxConcurrentRequests. This allows reads with a suitably
844853
// large buffer to transfer data at a much faster rate due to
845854
// overlapping round trip times.
846855
inFlight := 0
847856
desiredInFlight := 1
848-
offset := f.offset
857+
offset := uint64( off )
849858
// maxConcurrentRequests buffer to deal with broadcastErr() floods
850859
// also must have a buffer of max value of (desiredInFlight - inFlight)
851860
ch := make(chan result, f.c.maxConcurrentRequests+1)
@@ -927,7 +936,6 @@ func (f *File) Read(b []byte) (int, error) {
927936
if firstErr.err != nil && firstErr.err != io.EOF {
928937
read = 0
929938
}
930-
f.offset += uint64(read)
931939
return read, firstErr.err
932940
}
933941

0 commit comments

Comments
 (0)
0