File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change 1
1
package sftp_test
2
2
3
3
import (
4
+ "bufio"
4
5
"fmt"
6
+ "io"
5
7
"log"
6
8
"os"
7
9
"os/exec"
@@ -107,13 +109,13 @@ func ExampleClient_Mkdir_parents() {
107
109
sshFxFailure := uint32 (4 )
108
110
mkdirParents := func (client * sftp.Client , dir string ) (err error ) {
109
111
var parents string
110
-
112
+
111
113
if path .IsAbs (dir ) {
112
114
// Otherwise, an absolute path given below would be turned in to a relative one
113
115
// by splitting on "/"
114
116
parents = "/"
115
117
}
116
-
118
+
117
119
for _ , name := range strings .Split (dir , "/" ) {
118
120
if name == "" {
119
121
// Paths with double-/ in them should just move along
@@ -145,3 +147,18 @@ func ExampleClient_Mkdir_parents() {
145
147
log .Fatal (err )
146
148
}
147
149
}
150
+
151
+ func ExampleFile_ReadFrom_bufio () {
152
+ // Using Bufio to buffer writes going to an sftp.File won't buffer as it
153
+ // skips buffering if the underlying writer support ReadFrom. The
154
+ // workaround is to wrap your writer in a struct that only implements
155
+ // io.Writer.
156
+ //
157
+ // For background see github.com/pkg/sftp/issues/125
158
+
159
+ var data_source io.Reader
160
+ var f * sftp.File
161
+ type writerOnly struct { io.Writer }
162
+ bw := bufio .NewWriter (writerOnly {f }) // no ReadFrom()
163
+ bw .ReadFrom (data_source )
164
+ }
You can’t perform that action at this time.
0 commit comments