conversionio

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrOutputLimitExceeded = errors.New("conversion output limit exceeded")

ErrOutputLimitExceeded reports that a conversion attempted to emit more data than its caller-authorized output budget.

Functions

func Check

func Check(ctx context.Context) error

Check normalizes a nil context and reports cancellation before a conversion starts another unit of work.

func Encode

func Encode(ctx context.Context, maxBytes int64, encode func(io.Writer) error) ([]byte, error)

Encode runs an encoder against a context-aware, size-limited memory buffer. It is useful for serializers that only expose an io.Writer API.

func ReadFile

func ReadFile(ctx context.Context, path string) ([]byte, error)

ReadFile reads a conversion input while observing ctx between filesystem reads. Format decoders may still contain indivisible CPU-bound operations; callers should also check ctx before and after invoking those decoders.

func WriteFile

func WriteFile(ctx context.Context, path string, data []byte, perm fs.FileMode, maxBytes int64) error

WriteFile writes one output with cancellation and a hard size limit.

Types

type Budget

type Budget struct {
	Context   context.Context
	Remaining int64
}

Budget shares one output allowance across a conversion's primary file and any sidecars it emits.

func NewBudget

func NewBudget(ctx context.Context, maxBytes int64) (*Budget, error)

func (*Budget) WriteFile

func (b *Budget) WriteFile(path string, data []byte, perm fs.FileMode) error

type File

type File struct {
	// contains filtered or unexported fields
}

File is an output file whose Write method observes a conversion context and enforces a hard byte limit.

func CreateFile

func CreateFile(ctx context.Context, path string, perm fs.FileMode, maxBytes int64) (*File, error)

func (*File) Close

func (f *File) Close() error

func (*File) Write

func (f *File) Write(p []byte) (int, error)

type LimitWriter

type LimitWriter struct {
	Context   context.Context
	Writer    io.Writer
	Remaining int64
}

LimitWriter checks cancellation and enforces a hard byte limit before each write reaches the wrapped writer.

func (*LimitWriter) Write

func (w *LimitWriter) Write(p []byte) (int, error)

type Reader

type Reader struct {
	Context context.Context
	Reader  io.Reader
}

Reader checks the conversion context before every underlying read.

func (*Reader) Read

func (r *Reader) Read(p []byte) (int, error)

Jump to

Keyboard shortcuts

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