@@ -839,13 +839,22 @@ func (f *File) Name() string {
839
839
// than calling Read multiple times. io.Copy will do this
840
840
// automatically.
841
841
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 ) {
842
851
// Split the read into multiple maxPacket sized concurrent reads
843
852
// bounded by maxConcurrentRequests. This allows reads with a suitably
844
853
// large buffer to transfer data at a much faster rate due to
845
854
// overlapping round trip times.
846
855
inFlight := 0
847
856
desiredInFlight := 1
848
- offset := f . offset
857
+ offset := uint64 ( off )
849
858
// maxConcurrentRequests buffer to deal with broadcastErr() floods
850
859
// also must have a buffer of max value of (desiredInFlight - inFlight)
851
860
ch := make (chan result , f .c .maxConcurrentRequests + 1 )
@@ -927,7 +936,6 @@ func (f *File) Read(b []byte) (int, error) {
927
936
if firstErr .err != nil && firstErr .err != io .EOF {
928
937
read = 0
929
938
}
930
- f .offset += uint64 (read )
931
939
return read , firstErr .err
932
940
}
933
941
0 commit comments