moxio

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2023 License: MIT Imports: 8 Imported by: 16

Documentation

Overview

Package moxio has common i/o functions.

Index

Constants

This section is empty.

Variables

View Source
var ErrLimit = errors.New("input exceeds maximum size") // Returned by LimitReader.
View Source
var ErrLineTooLong = errors.New("line from remote too long") // Returned by Bufpool.Readline.

Functions

func IsClosed

func IsClosed(err error) bool

IsClosed returns whether i/o failed, typically because the connection is closed or otherwise cannot be used for further i/o.

Used to prevent error logging for connections that are closed.

func IsStorageSpace

func IsStorageSpace(err error) bool

IsStorageSpace returns whether the error is for storage space issue. Like disk full, no inodes, quota reached.

func SyncDir

func SyncDir(dir string) error

SyncDir opens a directory and syncs its contents to disk.

Types

type AtReader

type AtReader struct {
	R      io.ReaderAt
	Offset int64
}

AtReader is turns an io.ReaderAt into a io.Reader by keeping track of the offset.

func (*AtReader) Read

func (r *AtReader) Read(buf []byte) (int, error)

type Bufpool

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

Bufpool caches byte slices for reuse during parsing of line-terminated commands.

func NewBufpool

func NewBufpool(max, size int) *Bufpool

NewBufpool makes a new pool, initially empty, but holding at most "max" buffers of "size" bytes each.

func (*Bufpool) Readline

func (b *Bufpool) Readline(r *bufio.Reader) (line string, rerr error)

Readline reads a \n- or \r\n-terminated line. Line is returned without \n or \r\n. If the line was too long, ErrLineTooLong is returned. If an EOF is encountered before a \n, io.ErrUnexpectedEOF is returned.

type LimitAtReader

type LimitAtReader struct {
	R     io.ReaderAt
	Limit int64
}

LimitAtReader is a reader at that returns ErrLimit if reads would extend beyond Limit.

func (*LimitAtReader) ReadAt

func (r *LimitAtReader) ReadAt(buf []byte, offset int64) (int, error)

ReadAt passes the read on to R, but returns an error if the read data would extend beyond Limit.

type LimitReader

type LimitReader struct {
	R     io.Reader
	Limit int64
}

LimitReader reads up to Limit bytes, returning an error if more bytes are read. LimitReader can be used to enforce a maximum input length.

func (*LimitReader) Read

func (r *LimitReader) Read(buf []byte) (int, error)

Read reads bytes from the underlying reader.

type PrefixConn

type PrefixConn struct {
	PrefixReader io.Reader // If not nil, reads are fulfilled from here. It is cleared when a read returns io.EOF.
	net.Conn
}

PrefixConn is a net.Conn prefixed with a reader that is first drained. Used for STARTTLS where already did a buffered read of initial TLS data.

func (*PrefixConn) Read

func (c *PrefixConn) Read(buf []byte) (int, error)

Read returns data when PrefixReader when not nil, and net.Conn otherwise.

type TraceReader

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

func NewTraceReader

func NewTraceReader(log *mlog.Log, prefix string, r io.Reader) *TraceReader

NewTraceReader wraps reader "r" into a reader that logs all reads to "log" with log level trace, prefixed with "prefix".

func (*TraceReader) Read

func (r *TraceReader) Read(buf []byte) (int, error)

Read does a single Read on its underlying reader, logs data of successful reads, and returns the data read.

func (*TraceReader) SetTrace

func (r *TraceReader) SetTrace(level mlog.Level)

type TraceWriter

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

func NewTraceWriter

func NewTraceWriter(log *mlog.Log, prefix string, w io.Writer) *TraceWriter

NewTraceWriter wraps "w" into a writer that logs all writes to "log" with log level trace, prefixed with "prefix".

func (*TraceWriter) SetTrace

func (w *TraceWriter) SetTrace(level mlog.Level)

func (*TraceWriter) Write

func (w *TraceWriter) Write(buf []byte) (int, error)

Write logs a trace line for writing buf to the client, then writes to the client.

Jump to

Keyboard shortcuts

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