Documentation ¶
Overview ¶
Package ioutil implements some I/O utility functions which are not covered by the standard library.
Index ¶
- func AppendFile(dst string, src string, osync bool) error
- func CopyAligned(w *os.File, r io.Reader, alignedBuf []byte, totalSize int64) (int64, error)
- func NewDeadlineWriter(w io.WriteCloser, timeout time.Duration) io.WriteCloser
- func NewSkipReader(r io.Reader, n int64) io.Reader
- func NopCloser(w io.Writer) io.WriteCloser
- func ReadFile(name string) ([]byte, error)
- func SameFile(fi1, fi2 os.FileInfo) bool
- func WaitPipe() (*PipeReader, *PipeWriter)
- type DeadlineWriter
- type LimitWriter
- type PipeReader
- type PipeWriter
- type SkipReader
- type WriteOnCloser
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendFile ¶
AppendFile - appends the file "src" to the file "dst"
func CopyAligned ¶
CopyAligned - copies from reader to writer using the aligned input buffer, it is expected that input buffer is page aligned to 4K page boundaries. Without passing aligned buffer may cause this function to return error.
This code is similar in spirit to io.Copy but it is only to be used with DIRECT I/O based file descriptor and it is expected that input writer *os.File not a generic io.Writer. Make sure to have the file opened for writes with syscall.O_DIRECT flag.
func NewDeadlineWriter ¶
func NewDeadlineWriter(w io.WriteCloser, timeout time.Duration) io.WriteCloser
NewDeadlineWriter wraps a writer to make it respect given deadline value per Write(). If there is a blocking write, the returned Writer will return whenever the timer hits (the return values are n=0 and err=context.Canceled.)
func NewSkipReader ¶
NewSkipReader - creates a SkipReader
func NopCloser ¶
func NopCloser(w io.Writer) io.WriteCloser
NopCloser returns a WriteCloser with a no-op Close method wrapping the provided Writer w.
func ReadFile ¶
ReadFile reads the named file and returns the contents. A successful call returns err == nil, not err == EOF. Because ReadFile reads the whole file, it does not treat an EOF from Read as an error to be reported.
passes NOATIME flag for reads on Unix systems to avoid atime updates.
func WaitPipe ¶
func WaitPipe() (*PipeReader, *PipeWriter)
WaitPipe implements wait-group backend io.Pipe to provide synchronization between read() end with write() end.
Types ¶
type DeadlineWriter ¶
type DeadlineWriter struct { io.WriteCloser // contains filtered or unexported fields }
DeadlineWriter deadline writer with context
func (*DeadlineWriter) Close ¶
func (w *DeadlineWriter) Close() error
Close closer interface to close the underlying closer
type LimitWriter ¶
LimitWriter implements io.WriteCloser.
This is implemented such that we want to restrict an enscapsulated writer upto a certain length and skip a certain number of bytes.
func LimitedWriter ¶
func LimitedWriter(w io.Writer, skipBytes int64, limit int64) *LimitWriter
LimitedWriter takes an io.Writer and returns an ioutil.LimitWriter.
func (*LimitWriter) Close ¶
func (w *LimitWriter) Close() error
Close closes the LimitWriter. It behaves like io.Closer.
type PipeReader ¶
type PipeReader struct { *io.PipeReader // contains filtered or unexported fields }
PipeReader is similar to io.PipeReader with wait group
func (*PipeReader) CloseWithError ¶
func (r *PipeReader) CloseWithError(err error) error
CloseWithError close with supplied error the reader end
type PipeWriter ¶
type PipeWriter struct { *io.PipeWriter // contains filtered or unexported fields }
PipeWriter is similar to io.PipeWriter with wait group
func (*PipeWriter) CloseWithError ¶
func (w *PipeWriter) CloseWithError(err error) error
CloseWithError close with supplied error the writer end.
type SkipReader ¶
SkipReader skips a given number of bytes and then returns all remaining data.
type WriteOnCloser ¶
WriteOnCloser implements io.WriteCloser and always executes at least one write operation if it is closed.
This can be useful within the context of HTTP. At least one write operation must happen to send the HTTP headers to the peer.
func WriteOnClose ¶
func WriteOnClose(w io.Writer) *WriteOnCloser
WriteOnClose takes an io.Writer and returns an ioutil.WriteOnCloser.
func (*WriteOnCloser) Close ¶
func (w *WriteOnCloser) Close() error
Close closes the WriteOnCloser. It behaves like io.Closer.
func (*WriteOnCloser) HasWritten ¶
func (w *WriteOnCloser) HasWritten() bool
HasWritten returns true if at least one write operation was performed.