}
// DecodeHeader decodes all encoded-words of the given string. It returns an
-// error if and only if CharsetReader of d returns an error.
+// error if and only if WordDecoder.CharsetReader of d returns an error.
func (d *WordDecoder) DecodeHeader(header string) (string, error) {
// If there is no encoded-word, returns before creating a buffer.
i := strings.Index(header, "=?")
return nil
}
-// ErrInvalidMediaParameter is returned by ParseMediaType if
+// ErrInvalidMediaParameter is returned by [ParseMediaType] if
// the media type value was found but there was an error parsing
// the optional parameters
var ErrInvalidMediaParameter = errors.New("mime: invalid media parameter")
// to lowercase and trimmed of white space and a non-nil map.
// If there is an error parsing the optional parameter,
// the media type will be returned along with the error
-// ErrInvalidMediaParameter.
+// [ErrInvalidMediaParameter].
// The returned map, params, maps from the lowercase
// attribute to the attribute value with its case preserved.
func ParseMediaType(v string) (mediatype string, params map[string]string, err error) {
// It stores up to maxMemory bytes + 10MB (reserved for non-file parts)
// in memory. File parts which can't be stored in memory will be stored on
// disk in temporary files.
-// It returns ErrMessageTooLarge if all non-file parts can't be stored in
+// It returns [ErrMessageTooLarge] if all non-file parts can't be stored in
// memory.
func (r *Reader) ReadForm(maxMemory int64) (*Form, error) {
return r.readForm(maxMemory)
// Form is a parsed multipart form.
// Its File parts are stored either in memory or on disk,
-// and are accessible via the *FileHeader's Open method.
+// and are accessible via the [*FileHeader]'s Open method.
// Its Value parts are stored as strings.
// Both are keyed by field name.
type Form struct {
File map[string][]*FileHeader
}
-// RemoveAll removes any temporary files associated with a Form.
+// RemoveAll removes any temporary files associated with a [Form].
func (f *Form) RemoveAll() error {
var err error
for _, fhs := range f.File {
tmpshared bool
}
-// Open opens and returns the FileHeader's associated File.
+// Open opens and returns the [FileHeader]'s associated File.
func (fh *FileHeader) Open() (File, error) {
if b := fh.content; b != nil {
r := io.NewSectionReader(bytes.NewReader(b), 0, int64(len(b)))
To protect against malicious inputs, this package sets limits on the size
of the MIME data it processes.
-Reader.NextPart and Reader.NextRawPart limit the number of headers in a
-part to 10000 and Reader.ReadForm limits the total number of headers in all
+[Reader.NextPart] and [Reader.NextRawPart] limit the number of headers in a
+part to 10000 and [Reader.ReadForm] limits the total number of headers in all
FileHeaders to 10000.
These limits may be adjusted with the GODEBUG=multipartmaxheaders=<values>
setting.
return p.dispositionParams["name"]
}
-// FileName returns the filename parameter of the Part's Content-Disposition
+// FileName returns the filename parameter of the [Part]'s Content-Disposition
// header. If not empty, the filename is passed through filepath.Base (which is
// platform dependent) before being returned.
func (p *Part) FileName() string {
}
}
-// NewReader creates a new multipart Reader reading from r using the
+// NewReader creates a new multipart [Reader] reading from r using the
// given MIME boundary.
//
// The boundary is usually obtained from the "boundary" parameter of
-// the message's "Content-Type" header. Use mime.ParseMediaType to
+// the message's "Content-Type" header. Use [mime.ParseMediaType] to
// parse such headers.
func NewReader(r io.Reader, boundary string) *Reader {
b := []byte("\r\n--" + boundary + "--")
}
// NextPart returns the next part in the multipart or an error.
-// When there are no more parts, the error io.EOF is returned.
+// When there are no more parts, the error [io.EOF] is returned.
//
// As a special case, if the "Content-Transfer-Encoding" header
// has a value of "quoted-printable", that header is instead
}
// NextRawPart returns the next part in the multipart or an error.
-// When there are no more parts, the error io.EOF is returned.
+// When there are no more parts, the error [io.EOF] is returned.
//
-// Unlike NextPart, it does not have special handling for
+// Unlike [Reader.NextPart], it does not have special handling for
// "Content-Transfer-Encoding: quoted-printable".
func (r *Reader) NextRawPart() (*Part, error) {
return r.nextPart(true, maxMIMEHeaderSize, maxMIMEHeaders())
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+
package multipart
import (
_ "unsafe" // for go:linkname
)
-// readMIMEHeader is defined in package net/textproto.
+// readMIMEHeader is defined in package [net/textproto].
//
//go:linkname readMIMEHeader net/textproto.readMIMEHeader
func readMIMEHeader(r *textproto.Reader, maxMemory, maxHeaders int64) (textproto.MIMEHeader, error)
lastpart *part
}
-// NewWriter returns a new multipart Writer with a random boundary,
+// NewWriter returns a new multipart [Writer] with a random boundary,
// writing to w.
func NewWriter(w io.Writer) *Writer {
return &Writer{
}
}
-// Boundary returns the Writer's boundary.
+// Boundary returns the [Writer]'s boundary.
func (w *Writer) Boundary() string {
return w.boundary
}
-// SetBoundary overrides the Writer's default randomly-generated
+// SetBoundary overrides the [Writer]'s default randomly-generated
// boundary separator with an explicit value.
//
// SetBoundary must be called before any parts are created, may only
}
// FormDataContentType returns the Content-Type for an HTTP
-// multipart/form-data with this Writer's Boundary.
+// multipart/form-data with this [Writer]'s Boundary.
func (w *Writer) FormDataContentType() string {
b := w.boundary
// We must quote the boundary if it contains any of the
// CreatePart creates a new multipart section with the provided
// header. The body of the part should be written to the returned
-// Writer. After calling CreatePart, any previous part may no longer
+// [Writer]. After calling CreatePart, any previous part may no longer
// be written to.
func (w *Writer) CreatePart(header textproto.MIMEHeader) (io.Writer, error) {
if w.lastpart != nil {
return quoteEscaper.Replace(s)
}
-// CreateFormFile is a convenience wrapper around CreatePart. It creates
+// CreateFormFile is a convenience wrapper around [Writer.CreatePart]. It creates
// a new form-data header with the provided field name and file name.
func (w *Writer) CreateFormFile(fieldname, filename string) (io.Writer, error) {
h := make(textproto.MIMEHeader)
return w.CreatePart(h)
}
-// CreateFormField calls CreatePart with a header using the
+// CreateFormField calls [Writer.CreatePart] with a header using the
// given field name.
func (w *Writer) CreateFormField(fieldname string) (io.Writer, error) {
h := make(textproto.MIMEHeader)
return w.CreatePart(h)
}
-// WriteField calls CreateFormField and then writes the given value.
+// WriteField calls [Writer.CreateFormField] and then writes the given value.
func (w *Writer) WriteField(fieldname, value string) error {
p, err := w.CreateFormField(fieldname)
if err != nil {
const lineMaxLen = 76
-// A Writer is a quoted-printable writer that implements io.WriteCloser.
+// A Writer is a quoted-printable writer that implements [io.WriteCloser].
type Writer struct {
// Binary mode treats the writer's input as pure binary and processes end of
// line bytes as binary data.
cr bool
}
-// NewWriter returns a new Writer that writes to w.
+// NewWriter returns a new [Writer] that writes to w.
func NewWriter(w io.Writer) *Writer {
return &Writer{w: w}
}
// Write encodes p using quoted-printable encoding and writes it to the
-// underlying io.Writer. It limits line length to 76 characters. The encoded
-// bytes are not necessarily flushed until the Writer is closed.
+// underlying [io.Writer]. It limits line length to 76 characters. The encoded
+// bytes are not necessarily flushed until the [Writer] is closed.
func (w *Writer) Write(p []byte) (n int, err error) {
for i, b := range p {
switch {
return len(p), nil
}
-// Close closes the Writer, flushing any unwritten data to the underlying
-// io.Writer, but does not close the underlying io.Writer.
+// Close closes the [Writer], flushing any unwritten data to the underlying
+// [io.Writer], but does not close the underlying io.Writer.
func (w *Writer) Close() error {
if err := w.checkLastByte(); err != nil {
return err