ioutils

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2015 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FprintfIfNotEmpty added in v1.7.0

func FprintfIfNotEmpty(w io.Writer, format, value string) (int, error)

FprintfIfNotEmpty prints the string value if it's not empty

func FprintfIfTrue added in v1.9.0

func FprintfIfTrue(w io.Writer, format string, ok bool) (int, error)

FprintfIfTrue prints the boolean value if it's true

func HashData added in v1.7.0

func HashData(src io.Reader) (string, error)

HashData returns the sha256 sum of src.

func MultiReadSeeker added in v1.8.0

func MultiReadSeeker(readers ...io.ReadSeeker) io.ReadSeeker

MultiReadSeeker returns a ReadSeeker that's the logical concatenation of the provided input readseekers. After calling this method the initial position is set to the beginning of the first ReadSeeker. At the end of a ReadSeeker, Read always advances to the beginning of the next ReadSeeker and returns EOF at the end of the last ReadSeeker. Seek can be used over the sum of lengths of all readseekers.

When a MultiReadSeeker is used, no Read and Seek operations should be made on its ReadSeeker components. Also, users should make no assumption on the state of individual readseekers while the MultiReadSeeker is used.

func NewBufReader

func NewBufReader(r io.Reader) io.ReadCloser

NewBufReader returns a new bufReader.

func NewBufReaderWithDrainbufAndBuffer

func NewBufReaderWithDrainbufAndBuffer(r io.Reader, drainBuffer []byte, buffer io.ReadWriter) io.ReadCloser

NewBufReaderWithDrainbufAndBuffer returns a BufReader with drainBuffer and buffer.

func NewReadCloserWrapper

func NewReadCloserWrapper(r io.Reader, closer func() error) io.ReadCloser

NewReadCloserWrapper returns a new io.ReadCloser.

func NewReaderErrWrapper

func NewReaderErrWrapper(r io.Reader, closer func()) io.Reader

NewReaderErrWrapper returns a new io.Reader.

func NewWriteCloserWrapper

func NewWriteCloserWrapper(r io.Writer, closer func() error) io.WriteCloser

NewWriteCloserWrapper returns a new io.WriteCloser.

func NopWriteCloser

func NopWriteCloser(w io.Writer) io.WriteCloser

NopWriteCloser returns a nopWriteCloser.

func TempDir added in v1.9.0

func TempDir(dir, prefix string) (string, error)

TempDir on Unix systems is equivalent to ioutil.TempDir.

Types

type BytesPipe added in v1.9.0

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

BytesPipe is io.ReadWriter which works similarly to pipe(queue). All written data could be read only once. Also BytesPipe is allocating and releasing new byte slices to adjust to current needs, so there won't be overgrown buffer after high load peak. BytesPipe isn't goroutine-safe, caller must synchronize it if needed.

func NewBytesPipe added in v1.9.0

func NewBytesPipe(buf []byte) *BytesPipe

NewBytesPipe creates new BytesPipe, initialized by specified slice. If buf is nil, then it will be initialized with slice which cap is 64. buf will be adjusted in a way that len(buf) == 0, cap(buf) == cap(buf).

func (*BytesPipe) Read added in v1.9.0

func (bp *BytesPipe) Read(p []byte) (n int, err error)

Read reads bytes from BytesPipe. Data could be read only once.

func (*BytesPipe) Write added in v1.9.0

func (bp *BytesPipe) Write(p []byte) (n int, err error)

Write writes p to BytesPipe. It can allocate new []byte slices in a process of writing.

type NopFlusher

type NopFlusher struct{}

NopFlusher represents a type which flush opetatin is nop.

func (*NopFlusher) Flush

func (f *NopFlusher) Flush()

Flush is a nop operation.

type NopWriter

type NopWriter struct{}

NopWriter represents a type which write operation is nop.

func (*NopWriter) Write

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

type OnEOFReader added in v1.8.0

type OnEOFReader struct {
	Rc io.ReadCloser
	Fn func()
}

OnEOFReader wraps a io.ReadCloser and a function the function will run at the end of file or close the file.

func (*OnEOFReader) Close added in v1.8.0

func (r *OnEOFReader) Close() error

Close closes the file and run the function.

func (*OnEOFReader) Read added in v1.8.0

func (r *OnEOFReader) Read(p []byte) (n int, err error)

type WriteCounter added in v1.7.0

type WriteCounter struct {
	Count  int64
	Writer io.Writer
}

WriteCounter wraps a concrete io.Writer and hold a count of the number of bytes written to the writer during a "session". This can be convenient when write return is masked (e.g., json.Encoder.Encode())

func NewWriteCounter added in v1.7.0

func NewWriteCounter(w io.Writer) *WriteCounter

NewWriteCounter returns a new WriteCounter.

func (*WriteCounter) Write added in v1.7.0

func (wc *WriteCounter) Write(p []byte) (count int, err error)

type WriteFlusher added in v1.7.0

type WriteFlusher struct {
	sync.Mutex
	// contains filtered or unexported fields
}

WriteFlusher wraps the Write and Flush operation.

func NewWriteFlusher added in v1.7.0

func NewWriteFlusher(w io.Writer) *WriteFlusher

NewWriteFlusher returns a new WriteFlusher.

func (*WriteFlusher) Flush added in v1.7.0

func (wf *WriteFlusher) Flush()

Flush the stream immediately.

func (*WriteFlusher) Flushed added in v1.7.0

func (wf *WriteFlusher) Flushed() bool

Flushed returns the state of flushed. If it's flushed, return true, or else it return false.

func (*WriteFlusher) Write added in v1.7.0

func (wf *WriteFlusher) Write(b []byte) (n int, err error)

Jump to

Keyboard shortcuts

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