commands/http: Documented MultiFileReader
Matt Bell committed
Nov 17, 2014 at 03:21 UTC
c598673b4cda659038209a076881556d1c384f96
1 file changed
+7
commands/http/multifilereader.go
+7
@@ -10,6 +10,9 @@ import (
10
cmds "github.com/jbenet/go-ipfs/commands"
11
)
12
13
+// MultiFileReader reads from a `commands.File` (which can be a directory of files
14
+// or a regular file) as HTTP multipart encoded data.
15
+// WARNING: Not thread-safe!
16
type MultiFileReader struct {
17
io.Reader
18
@@ -24,6 +27,9 @@ type MultiFileReader struct {
27
form bool
28
}
29
30
+// NewMultiFileReader constructs a MultiFileReader. `file` can be any `commands.File`.
31
+// If `form` is set to true, the multipart data will have a Content-Type of 'multipart/form-data',
32
+// if `form` is false, the Content-Type will be 'multipart/mixed'.
33
func NewMultiFileReader(file cmds.File, form bool) *MultiFileReader {
34
mfr := &MultiFileReader{
35
files: file,
@@ -103,6 +109,7 @@ func (mfr *MultiFileReader) Read(buf []byte) (written int, err error) {
109
return written, err
110
}
111
112
+// Boundary returns the boundary string to be used to separate files in the multipart data
113
func (mfr *MultiFileReader) Boundary() string {
114
return mfr.mpWriter.Boundary()
115
}