rclone: github.com/ncw/rclone/fs/asyncreader Index | Files

package asyncreader

import "github.com/ncw/rclone/fs/asyncreader"

Package asyncreader provides an asynchronous reader which reads independently of write


Package Files



const (
    // BufferSize is the default size of the async buffer
    BufferSize = 1024 * 1024


var ErrorStreamAbandoned = errors.New("stream abandoned")

ErrorStreamAbandoned is returned when the input is closed before the end of the stream

type AsyncReader Uses

type AsyncReader struct {
    // contains filtered or unexported fields

AsyncReader will do async read-ahead from the input reader and make the data available as an io.Reader. This should be fully transparent, except that once an error has been returned from the Reader, it will not recover.

func New Uses

func New(ctx context.Context, rd io.ReadCloser, buffers int) (*AsyncReader, error)

New returns a reader that will asynchronously read from the supplied Reader into a number of buffers each of size BufferSize It will start reading from the input at once, maybe even before this function has returned. The input can be read from the returned reader. When done use Close to release the buffers and close the supplied input.

func (*AsyncReader) Abandon Uses

func (a *AsyncReader) Abandon()

Abandon will ensure that the underlying async reader is shut down and memory is returned. It does everything but close the input.

It will NOT close the input supplied on New.

func (*AsyncReader) Close Uses

func (a *AsyncReader) Close() (err error)

Close will ensure that the underlying async reader is shut down. It will also close the input supplied on New.

func (*AsyncReader) Read Uses

func (a *AsyncReader) Read(p []byte) (n int, err error)

Read will return the next available data.

func (*AsyncReader) SkipBytes Uses

func (a *AsyncReader) SkipBytes(skip int) (ok bool)

SkipBytes will try to seek 'skip' bytes relative to the current position. On success it returns true. If 'skip' is outside the current buffer data or an error occurs, Abandon is called and false is returned.

func (*AsyncReader) StopBuffering Uses

func (a *AsyncReader) StopBuffering()

StopBuffering will ensure that the underlying async reader is shut down so no more is read from the input.

This does not free the memory so Abandon() or Close() need to be called on the input.

This does not wait for Read/WriteTo to complete so can be called concurrently to those.

func (*AsyncReader) WriteTo Uses

func (a *AsyncReader) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes data to w until there's no more data to write or when an error occurs. The return value n is the number of bytes written. Any error encountered during the write is also returned.

Package asyncreader imports 8 packages (graph) and is imported by 7 packages. Updated 2021-01-21. Refresh now. Tools for package owners.