Documentation ¶
Index ¶
- Constants
- Variables
- func Copy(dst io.Writer, src io.Reader) (written int64, err error)
- func CopyBuffer(dst io.Writer, src io.Reader, buf []byte) (written int64, err error)
- func CopyN(dst io.Writer, src io.Reader, n int64) (written int64, err error)
- func Drain(r io.Reader)
- func DrainAndClose(r io.ReadCloser)
- func LimitWriter(w io.Writer, n int64) io.Writer
- func LineWriter(w io.Writer, eol ...string) io.Writer
- func NewSectionReader(r io.ReaderAt, off int64, n int64) *io.SectionReader
- func NopCloser(r io.Reader) io.ReadCloser
- func ReadAll(r io.Reader) ([]byte, error)
- func ReadAtLeast(r io.Reader, buf []byte, min int) (n int, err error)
- func ReadFull(r io.Reader, buf []byte) (n int, err error)
- func SkipBOM(r io.Reader) (io.Reader, error)
- func StripWriter(w io.Writer) io.Writer
- func SyncWriter(w io.Writer) io.Writer
- func TeeReader(r io.Reader, w io.Writer) io.Reader
- func WrapWriter(w io.Writer, prefix, suffix string) io.Writer
- func WriteString(w io.Writer, s string) (n int, err error)
- type ChunkLineWriter
- type CompactWriter
- type FileReader
- type MaxBytesError
- type MaxBytesReader
Constants ¶
const BOM = '\uFEFF'
BOM '\uFEFF'
const CR = "\r"
CR "\r"
const CRLF = "\r\n"
CRLF "\r\n"
const LF = "\n"
LF "\n"
const MimeChunkSize = 76
MimeChunkSize As required by RFC 2045, 6.8. (page 25) for base64.
const PemChunkSize = 64
PemChunkSize PEM chunk size per RFC 1421 section 4.3.2.4.
Variables ¶
var ConsoleColor = defineColor()
ConsoleColor console color
var Discard = io.Discard
Discard is an io.Writer on which all Write calls succeed without doing anything.
var EOL = geteol()
EOL windows: "\r\n" other: "\n"
Functions ¶
func Copy ¶
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 ¶
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 ¶
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 LimitWriter ¶ added in v1.0.12
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
LineWriter return a eol append writer
func NewSectionReader ¶
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 ¶
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 ¶
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 ¶
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 StripWriter ¶ added in v1.0.12
StripWriter return a string strip writer
func TeeReader ¶
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 ¶
WrapWriter return a prefix/suffix wrap writer
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
type CompactWriter ¶ added in v1.0.12
type CompactWriter struct {
// contains filtered or unexported fields
}
func NewCompactWriter ¶ added in v1.0.12
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
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