8000 Document that ReadFrom/WriteTo are best for high throughput - fixes #158 · etherscan-io/sftp@0fc9a33 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0fc9a33

Browse files
committed
Document that ReadFrom/WriteTo are best for high throughput - fixes pkg#158
1 parent d2aa419 commit 0fc9a33

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

client.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,11 @@ const maxConcurrentRequests = 64
765765
// read and an error, if any. Read follows io.Reader semantics, so when Read
766766
// encounters an error or EOF condition after successfully reading n > 0 bytes,
767767
// 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.
768773
func (f *File) Read(b []byte) (int, error) {
769774
// Split the read into multiple maxPacket sized concurrent reads
770775
// bounded by maxConcurrentRequests. This allows reads with a suitably
@@ -860,6 +865,10 @@ func (f *File) Read(b []byte) (int, error) {
860865

861866
// WriteTo writes the file to w. The return value is the number of bytes
862867
// 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).
863872
func (f *File) WriteTo(w io.Writer) (int64, error) {
864873
fi, err := f.Stat()
865874
if err != nil {
@@ -1005,6 +1014,11 @@ func (f *File) Stat() (os.FileInfo, error) {
10051014
// Write writes len(b) bytes to the File. It returns the number of bytes
10061015
// written and an error, if any. Write returns a non-nil error when n !=
10071016
// 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.
10081022
func (f *File) Write(b []byte) (int, error) {
10091023
// Split the write into multiple maxPacket sized concurrent writes
10101024
// bounded by maxConcurrentRequests. This allows writes with a suitably
@@ -1070,6 +1084,10 @@ func (f *File) Write(b []byte) (int, error) {
10701084
// ReadFrom reads data from r until EOF and writes it to the file. The return
10711085
// value is the number of bytes read. Any error except io.EOF encountered
10721086
// 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).
10731091
func (f *File) ReadFrom(r io.Reader) (int64, error) {
10741092
inFlight := 0
10751093
desiredInFlight := 1

0 commit comments

Comments
 (0)
0