Documentation
¶
Overview ¶
Package body implements a write-once read-multiple io.ReadSeekCloser that is backed by a temporary file when too much data gets written into it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBodyTooLarge = errors.New("body too large")
Functions ¶
This section is empty.
Types ¶
type Body ¶
type Body struct {
DisableWriting bool // if set to true, Write will not write any data (same as io.Discard)
// contains filtered or unexported fields
}
Body is an io.ReadSeekCloser and io.Writer that starts buffering all data written to it in memory but when more than a configured amount of bytes is written to it Body will switch to writing to a temporary file.
After a call to Read or Seek no more data can be written to Body. Body is an io.Seeker so you can read it multiple times or get the size of the Body.
func New ¶
New creates a new Body that switches from memory-backed storage to file-backed storage when more than maxMem bytes were written to it.
If maxMem is less than 1, a temporary file gets always used. If maxSize is bigger than 0, the Body will return an error when more than maxSize bytes are written to it.
func (*Body) Close ¶
Close implements the io.Closer interface. If a temporary file got created it will be deleted.
func (*Body) Read ¶
Read implements the io.Reader interface. After calling Read you cannot call Write anymore.