body

package
v0.0.0-...-cd718fc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 7, 2026 License: BSD-2-Clause, BSD-3-Clause Imports: 4 Imported by: 0

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

View Source
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

func New(maxMem int, maxSize int64) *Body

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

func (b *Body) Close() error

Close implements the io.Closer interface. If a temporary file got created it will be deleted.

func (*Body) Read

func (b *Body) Read(p []byte) (n int, err error)

Read implements the io.Reader interface. After calling Read you cannot call Write anymore.

func (*Body) Seek

func (b *Body) Seek(offset int64, whence int) (int64, error)

Seek implements the io.Seeker interface. After calling Seek you cannot call Write anymore.

func (*Body) Write

func (b *Body) Write(p []byte) (n int, err error)

Write implements the io.Writer interface. Write will create a temporary file on-the-fly when you write more than the configured amount of bytes.

type ErrReader

type ErrReader struct {
	Err error
}

ErrReader is an io.Reader that always returns an error.

func (ErrReader) Read

func (e ErrReader) Read(_ []byte) (n int, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL