Commit d96f9cbb authored by Jamie Stackhouse's avatar Jamie Stackhouse Committed by Brad Fitzpatrick

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/39223Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 8a4cee67
......@@ -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
......
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment