iox

package
v1.0.15 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 10 Imported by: 3

Documentation

Index

Constants

View Source
const BOM = '\uFEFF'

BOM '\uFEFF'

View Source
const CR = "\r"

CR "\r"

View Source
const CRLF = "\r\n"

CRLF "\r\n"

View Source
const LF = "\n"

LF "\n"

View Source
const MimeChunkSize = 76

MimeChunkSize As required by RFC 2045, 6.8. (page 25) for base64.

View Source
const PemChunkSize = 64

PemChunkSize PEM chunk size per RFC 1421 section 4.3.2.4.

Variables

View Source
var ConsoleColor = defineColor()

ConsoleColor console color

View Source
var Discard = io.Discard

Discard is an io.Writer on which all Write calls succeed without doing anything.

View Source
var EOL = geteol()

EOL windows: "\r\n" other: "\n"

Functions

func Copy

func Copy(dst io.Writer, src io.Reader) (written int64, err error)

Copy copies from src to dst until either EOF is reached on src or an error occurs. It returns the number of bytes copied and the first error encountered while copying, if any.

A successful Copy returns err == nil, not err == EOF. Because Copy is defined to read from src until EOF, it does not treat an EOF from Read as an error to be reported.

If src implements the WriterTo interface, the copy is implemented by calling src.WriteTo(dst). Otherwise, if dst implements the ReaderFrom interface, the copy is implemented by calling dst.ReadFrom(src).

func CopyBuffer

func CopyBuffer(dst io.Writer, src io.Reader, buf []byte) (written int64, err error)

CopyBuffer is identical to Copy except that it stages through the provided buffer (if one is required) rather than allocating a temporary one. If buf is nil, one is allocated; otherwise if it has zero length, CopyBuffer panics.

If either src implements WriterTo or dst implements ReaderFrom, buf will not be used to perform the copy.

func CopyN

func CopyN(dst io.Writer, src io.Reader, n int64) (written int64, err error)

CopyN copies n bytes (or until an error) from src to dst. It returns the number of bytes copied and the earliest error encountered while copying. On return, written == n if and only if err == nil.

If dst implements the ReaderFrom interface, the copy is implemented using it.

func Drain

func Drain(r io.Reader)

Drain drain the reader

func DrainAndClose

func DrainAndClose(r io.ReadCloser)

DrainAndClose drain and close the reader

func LimitWriter added in v1.0.12

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

LimitWriter returns a Writer that writes limited bytes to the underlying writer. The underlying implementation is a *limitWriter.

func LineWriter added in v1.0.12

func LineWriter(w io.Writer, eol ...string) io.Writer

LineWriter return a eol append writer

func NewSectionReader

func NewSectionReader(r io.ReaderAt, off int64, n int64) *io.SectionReader

NewSectionReader returns a SectionReader that reads from r starting at offset off and stops with EOF after n bytes.

func NopCloser

func NopCloser(r io.Reader) io.ReadCloser

NopCloser returns a ReadCloser with a no-op Close method wrapping the provided Reader r.

func ReadAll

func ReadAll(r io.Reader) ([]byte, error)

ReadAll reads from r until an error or EOF and returns the data it read. A successful call returns err == nil, not err == EOF. Because ReadAll is defined to read from src until EOF, it does not treat an EOF from Read as an error to be reported.

func ReadAtLeast

func ReadAtLeast(r io.Reader, buf []byte, min int) (n int, err error)

ReadAtLeast reads from r into buf until it has read at least min bytes. It returns the number of bytes copied and an error if fewer bytes were read. The error is EOF only if no bytes were read. If an EOF happens after reading fewer than min bytes, ReadAtLeast returns ErrUnexpectedEOF. If min is greater than the length of buf, ReadAtLeast returns ErrShortBuffer. On return, n >= min if and only if err == nil. If r returns an error having read at least min bytes, the error is dropped.

func ReadFull

func ReadFull(r io.Reader, buf []byte) (n int, err error)

ReadFull reads exactly len(buf) bytes from r into buf. It returns the number of bytes copied and an error if fewer bytes were read. The error is EOF only if no bytes were read. If an EOF happens after reading some but not all the bytes, ReadFull returns ErrUnexpectedEOF. On return, n == len(buf) if and only if err == nil. If r returns an error having read at least len(buf) bytes, the error is dropped.

func SkipBOM

func SkipBOM(r io.Reader) (io.Reader, error)

SkipBOM skip bom and return a reader

func StripWriter added in v1.0.12

func StripWriter(w io.Writer) io.Writer

StripWriter return a string strip writer

func SyncWriter

func SyncWriter(w io.Writer) io.Writer

SyncWriter return a synchronized writer

func TeeReader

func TeeReader(r io.Reader, w io.Writer) io.Reader

TeeReader returns a Reader that writes to w what it reads from r. All reads from r performed through it are matched with corresponding writes to w. There is no internal buffering - the write must complete before the read completes. Any error encountered while writing is reported as a read error.

func WrapWriter

func WrapWriter(w io.Writer, prefix, suffix string) io.Writer

WrapWriter return a prefix/suffix wrap writer

func WriteString

func WriteString(w io.Writer, s string) (n int, err error)

WriteString writes the contents of the string s to w, which accepts a slice of bytes. If w implements StringWriter, its WriteString method is invoked directly. Otherwise, w.Write is called exactly once.

Types

type ChunkLineWriter

type ChunkLineWriter struct {
	Writer   io.Writer
	EOL      string
	LineSize int // chunk line size
	// contains filtered or unexported fields
}

ChunkLineWriter limits text to n characters per line

func NewMimeChunkWriter

func NewMimeChunkWriter(w io.Writer) *ChunkLineWriter

NewMimeChunkWriter create a writer for split base64 to 76 characters per line

func NewPemChunkWriter

func NewPemChunkWriter(w io.Writer) *ChunkLineWriter

NewPemChunkWriter create a writer for split base64 to 76 characters per line

func (*ChunkLineWriter) Write

func (cw *ChunkLineWriter) Write(p []byte) (n int, err error)

Write implements io.Writer

type CompactWriter added in v1.0.12

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

func NewCompactWriter added in v1.0.12

func NewCompactWriter(w io.Writer, f func(rune) bool, r rune) *CompactWriter

NewCompactWriter return a compact writer

func SpaceCompactWriter added in v1.0.12

func SpaceCompactWriter(w io.Writer) *CompactWriter

SpaceCompactor return a space compact writer

func (*CompactWriter) Reset added in v1.0.12

func (cw *CompactWriter) Reset(c bool)

func (*CompactWriter) Write added in v1.0.12

func (cw *CompactWriter) Write(p []byte) (int, error)

func (*CompactWriter) WriteString added in v1.0.12

func (cw *CompactWriter) WriteString(s string) (int, error)

type FileReader

type FileReader struct {
	Path string
	// contains filtered or unexported fields
}

FileReader a file reader

func (*FileReader) Close

func (fr *FileReader) Close() error

Close implements io.Close

func (*FileReader) Read

func (fr *FileReader) Read(p []byte) (n int, err error)

Read implements io.Reader

type MaxBytesError added in v1.0.14

type MaxBytesError struct {
	Limit int64
}

MaxBytesError is returned by MaxBytesReader when its read limit is exceeded.

func (*MaxBytesError) Error added in v1.0.14

func (e *MaxBytesError) Error() string

type MaxBytesReader added in v1.0.14

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

func NewMaxBytesReader added in v1.0.14

func NewMaxBytesReader(r io.Reader, n int64) *MaxBytesReader

func (*MaxBytesReader) Close added in v1.0.14

func (mbr *MaxBytesReader) Close() error

func (*MaxBytesReader) Error added in v1.0.14

func (mbr *MaxBytesReader) Error() error

func (*MaxBytesReader) Read added in v1.0.14

func (mbr *MaxBytesReader) Read(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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