pipeat

package module
v0.0.0-...-06b3e69 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2021 License: CC0-1.0 Imports: 6 Imported by: 10

README

PipeAt

Works like io.Pipe() but allows use of ReadAt/WriteAt and asynchronous operations. Useful for connecting IO pipelines where one or both ends require offset based file access.

GoDoc Build Status

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsyncWriterPipe

func AsyncWriterPipe() (*PipeReaderAt, *PipeWriterAt, error)

AsyncWriterPipe is just like Pipe but the writer is allowed to close before the reader is finished. Whereas in Pipe the writer blocks until the reader is done.

func AsyncWriterPipeInDir

func AsyncWriterPipeInDir(dirPath string) (*PipeReaderAt, *PipeWriterAt, error)

AsyncWriterPipeInDir is just like AsyncWriterPipe but the temporary file is created inside the specified directory

func Pipe

func Pipe() (*PipeReaderAt, *PipeWriterAt, error)

Pipe creates an asynchronous file based pipe. It can be used to connect code expecting an io.ReaderAt with code expecting an io.WriterAt. Writes all go to an unlinked temporary file, reads start up as the file gets written up to their area. It is safe to call multiple ReadAt and WriteAt in parallel with each other.

func PipeInDir

func PipeInDir(dirPath string) (*PipeReaderAt, *PipeWriterAt, error)

PipeInDir just like Pipe but the temporary file is created inside the specified directory

Types

type PipeReaderAt

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

PipeReaderAt is the io.ReaderAt side of pipe.

func (*PipeReaderAt) Close

func (r *PipeReaderAt) Close() error

Close will Close the temp file and subsequent writes or reads will return an ErrClosePipe error.

func (*PipeReaderAt) CloseWithError

func (r *PipeReaderAt) CloseWithError(err error) error

CloseWithError sets error and otherwise behaves like Close.

func (*PipeReaderAt) GetReadedBytes

func (r *PipeReaderAt) GetReadedBytes() int64

GetReadedBytes returns the bytes readed

func (*PipeReaderAt) Read

func (r *PipeReaderAt) Read(p []byte) (int, error)

It can also function as a io.Reader

func (*PipeReaderAt) ReadAt

func (r *PipeReaderAt) ReadAt(p []byte, off int64) (int, error)

ReadAt implements the standard ReaderAt interface. It blocks if it gets ahead of the writer. You can call it from multiple threads.

type PipeWriterAt

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

PipeWriterAt is the io.WriterAt side of pipe.

func (*PipeWriterAt) Close

func (w *PipeWriterAt) Close() error

Close on the writer will let the reader know that writing is complete. Once the reader catches up it will continue to return 0 bytes and an EOF error.

func (*PipeWriterAt) CloseWithError

func (w *PipeWriterAt) CloseWithError(err error) error

CloseWithError sets the error and otherwise behaves like Close.

func (*PipeWriterAt) GetWrittenBytes

func (w *PipeWriterAt) GetWrittenBytes() int64

GetWrittenBytes returns the bytes written

func (*PipeWriterAt) WaitForReader

func (w *PipeWriterAt) WaitForReader() error

WaitForReader will block until the reader is closed. Returns the error set when the reader closed.

func (*PipeWriterAt) Write

func (w *PipeWriterAt) Write(p []byte) (int, error)

Write provides a standard io.Writer interface.

func (*PipeWriterAt) WriteAt

func (w *PipeWriterAt) WriteAt(p []byte, off int64) (int, error)

WriteAt implements the standard WriterAt interface. It will write to the temp file without blocking. You can call it from multiple threads.

Jump to

Keyboard shortcuts

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