@@ -765,6 +765,11 @@ const maxConcurrentRequests = 64
765
765
// read and an error, if any. Read follows io.Reader semantics, so when Read
766
766
// encounters an error or EOF condition after successfully reading n > 0 bytes,
767
767
// it returns the number of bytes read.
768
+ //
769
+ // To maximise throughput for transferring the entire file (especially
770
+ // over high latency links) it is recommended to use WriteTo rather
771
+ // than calling Read multiple times. io.Copy will do this
772
+ // automatically.
768
773
func (f * File ) Read (b []byte ) (int , error ) {
769
774
// Split the read into multiple maxPacket sized concurrent reads
770
775
// bounded by maxConcurrentRequests. This allows reads with a suitably
@@ -860,6 +865,10 @@ func (f *File) Read(b []byte) (int, error) {
860
865
861
866
// WriteTo writes the file to w. The return value is the number of bytes
862
867
// written. Any error encountered during the write is also returned.
868
+ //
869
+ // This method is preferred over calling Read multiple times to
870
+ // maximise throughput for transferring the entire file (especially
871
+ // over high latency links).
863
872
func (f * File ) WriteTo (w io.Writer ) (int64 , error ) {
864
873
fi , err := f .Stat ()
865
874
if err != nil {
@@ -1005,6 +1014,11 @@ func (f *File) Stat() (os.FileInfo, error) {
1005
1014
// Write writes len(b) bytes to the File. It returns the number of bytes
1006
1015
// written and an error, if any. Write returns a non-nil error when n !=
1007
1016
// len(b).
1017
+ //
1018
+ // To maximise throughput for transferring the entire file (especially
1019
+ // over high latency links) it is recommended to use ReadFrom rather
1020
+ // than calling Write multiple times. io.Copy will do this
1021
+ // automatically.
1008
1022
func (f * File ) Write (b []byte ) (int , error ) {
1009
1023
// Split the write into multiple maxPacket sized concurrent writes
1010
1024
// bounded by maxConcurrentRequests. This allows writes with a suitably
@@ -1070,6 +1084,10 @@ func (f *File) Write(b []byte) (int, error) {
1070
1084
// ReadFrom reads data from r until EOF and writes it to the file. The return
1071
1085
// value is the number of bytes read. Any error except io.EOF encountered
1072
1086
// during the read is also returned.
1087
+ //
1088
+ // This method is preferred over calling Write multiple times to
1089
+ // maximise throughput for transferring the entire file (especially
1090
+ // over high latency links).
1073
1091
func (f * File ) ReadFrom (r io.Reader ) (int64 , error ) {
1074
1092
inFlight := 0
1075
1093
desiredInFlight := 1
0 commit comments