buffer

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: Apache-2.0 Imports: 1 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LimitWriter

func LimitWriter(w io.Writer, n int64, options ...LimitWriterOption) io.Writer

LimitWriter returns a Writer that reads from r but stops with EOF after n bytes. The underlying implementation is a *LimitedWriter.

func LimitWriterIgnoreError

func LimitWriterIgnoreError(lw *LimitedWriter)

Types

type LimitWriterOption

type LimitWriterOption func(*LimitedWriter)

type LimitedWriter

type LimitedWriter struct {
	W    io.Writer // underlying reader
	N    int64     // max bytes remaining
	MaxN int64     // max bytes remaining
	// contains filtered or unexported fields
}

A LimitedWriter reads from R but limits the amount of data returned to just N bytes. Each call to Read updates N to reflect the new amount remaining. Read returns EOF when N <= 0 or when the underlying R returns EOF.

func (*LimitedWriter) Write

func (l *LimitedWriter) Write(p []byte) (n int, err error)

type PreReader

type PreReader interface {
	io.ReadCloser
	Buffer() []byte
	String() string
}

func NewPreReader

func NewPreReader(reader io.ReadCloser, maxLen int) (PreReader, error)

NewPreReader

@Description[en-US]: Convert a io.ReadCloser to an io.ReadCloser that can read data in advance
@Description[zh-CN]: 将一个 io.ReadCloser 转换为可预读数据的 io.ReadCloser
@param reader 	io.ReadCloser
@param maxLen 	int
@return ${r}	PreReader
@return ${err}	error

Jump to

Keyboard shortcuts

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