utils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AcquireBuffer

func AcquireBuffer() *bytes.Buffer

AcquireBuffer returns a reset buffer from the pool.

func BytesReader

func BytesReader(b []byte) *bytes.Reader

BytesReader creates an io.Reader backed by b without allocation.

func CloneBytes

func CloneBytes(b []byte) []byte

CloneBytes returns a copy of b (safe for use after the source buffer is released).

func DetectFormat

func DetectFormat(data []byte) string

DetectFormat sniffs the first 512 bytes of data and returns the image format.

func DrainReader

func DrainReader(ctx context.Context, r io.Reader, chunkSize int) (*bytes.Buffer, error)

DrainReader reads all bytes from r into a pooled buffer and returns them. The caller owns the returned slice; pass the buffer back with ReleaseBuffer.

func PeekReader

func PeekReader(orig []byte, n int) (peek []byte, rest []byte)

PeekReader reads up to n bytes without consuming them (returns a new reader containing the peeked bytes followed by the rest of orig).

func ReleaseBuffer

func ReleaseBuffer(b *bytes.Buffer)

ReleaseBuffer returns b to the pool. Callers must not use b after this call.

func ScaleDimensions

func ScaleDimensions(srcW, srcH, targetW, targetH int) (int, int)

ScaleDimensions computes output (w, h) preserving aspect ratio. Pass 0 for either axis to calculate it from the other.

Types

type ChunkedWriter

type ChunkedWriter struct {
	W         io.Writer
	ChunkSize int
}

ChunkedWriter splits writes into fixed-size chunks; useful for streaming uploads.

func (*ChunkedWriter) Write

func (c *ChunkedWriter) Write(p []byte) (int, error)

type LimitedReader

type LimitedReader struct {
	R   io.Reader
	Max int64
	// contains filtered or unexported fields
}

LimitedReader wraps r and returns an error when more than max bytes are read.

func (*LimitedReader) Read

func (l *LimitedReader) Read(p []byte) (int, error)

Jump to

Keyboard shortcuts

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