提交 c598673b 作者: Matt Bell

commands/http: Documented MultiFileReader

上级 5614234d
...@@ -10,6 +10,9 @@ import ( ...@@ -10,6 +10,9 @@ import (
cmds "github.com/jbenet/go-ipfs/commands" cmds "github.com/jbenet/go-ipfs/commands"
) )
// MultiFileReader reads from a `commands.File` (which can be a directory of files
// or a regular file) as HTTP multipart encoded data.
// WARNING: Not thread-safe!
type MultiFileReader struct { type MultiFileReader struct {
io.Reader io.Reader
...@@ -24,6 +27,9 @@ type MultiFileReader struct { ...@@ -24,6 +27,9 @@ type MultiFileReader struct {
form bool form bool
} }
// NewMultiFileReader constructs a MultiFileReader. `file` can be any `commands.File`.
// If `form` is set to true, the multipart data will have a Content-Type of 'multipart/form-data',
// if `form` is false, the Content-Type will be 'multipart/mixed'.
func NewMultiFileReader(file cmds.File, form bool) *MultiFileReader { func NewMultiFileReader(file cmds.File, form bool) *MultiFileReader {
mfr := &MultiFileReader{ mfr := &MultiFileReader{
files: file, files: file,
...@@ -103,6 +109,7 @@ func (mfr *MultiFileReader) Read(buf []byte) (written int, err error) { ...@@ -103,6 +109,7 @@ func (mfr *MultiFileReader) Read(buf []byte) (written int, err error) {
return written, err return written, err
} }
// Boundary returns the boundary string to be used to separate files in the multipart data
func (mfr *MultiFileReader) Boundary() string { func (mfr *MultiFileReader) Boundary() string {
return mfr.mpWriter.Boundary() return mfr.mpWriter.Boundary()
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论