diff options
author | Jamie Stackhouse <contin673@gmail.com> | 2017-04-01 01:07:59 -0300 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2017-04-01 10:04:56 +0000 |
commit | d96f9cbb87bfdbb809d1f4f18e0552b94475b86e (patch) | |
tree | d3e53d57ce75e994358298db800aae60671b143e /src/mime | |
parent | 8a4cee67afeda7c89e4a6e97cd95820f1904095d (diff) | |
download | go-d96f9cbb87bfdbb809d1f4f18e0552b94475b86e.tar.gz go-d96f9cbb87bfdbb809d1f4f18e0552b94475b86e.zip |
mime/multipart: add Size to FileHeader
This change makes it possible to retrieve the size of a file part
without having to Seek to determine file-size.
Resolves #19501
Change-Id: I7b9994c4cf41c9b06a046eb7046f8952ae1f15e9
Reviewed-on: https://go-review.googlesource.com/39223
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/mime')
-rw-r--r-- | src/mime/multipart/formdata.go | 5 | ||||
-rw-r--r-- | src/mime/multipart/formdata_test.go | 3 |
2 files changed, 7 insertions, 1 deletions
diff --git a/src/mime/multipart/formdata.go b/src/mime/multipart/formdata.go index c9e3188c33..26817a188b 100644 --- a/src/mime/multipart/formdata.go +++ b/src/mime/multipart/formdata.go @@ -79,7 +79,7 @@ func (r *Reader) readForm(maxMemory int64) (_ *Form, err error) { if err != nil { return nil, err } - _, err = io.Copy(file, io.MultiReader(&b, p)) + size, err := io.Copy(file, io.MultiReader(&b, p)) if cerr := file.Close(); err == nil { err = cerr } @@ -88,8 +88,10 @@ func (r *Reader) readForm(maxMemory int64) (_ *Form, err error) { return nil, err } fh.tmpfile = file.Name() + fh.Size = size } else { fh.content = b.Bytes() + fh.Size = int64(len(fh.content)) maxMemory -= n } form.File[name] = append(form.File[name], fh) @@ -128,6 +130,7 @@ func (f *Form) RemoveAll() error { type FileHeader struct { Filename string Header textproto.MIMEHeader + Size int64 content []byte tmpfile string diff --git a/src/mime/multipart/formdata_test.go b/src/mime/multipart/formdata_test.go index 1deca0b94d..ed848e1a09 100644 --- a/src/mime/multipart/formdata_test.go +++ b/src/mime/multipart/formdata_test.go @@ -44,6 +44,9 @@ func testFile(t *testing.T, fh *FileHeader, efn, econtent string) File { if fh.Filename != efn { t.Errorf("filename = %q, want %q", fh.Filename, efn) } + if fh.Size != int64(len(econtent)) { + t.Errorf("size = %d, want %d", fh.Size, len(econtent)) + } f, err := fh.Open() if err != nil { t.Fatal("opening file:", err) |