Documentation ¶
Overview ¶
Package asyncreader provides an asynchronous reader which reads independently of write
Index ¶
Constants ¶
const (
// BufferSize is the default size of the async buffer
BufferSize = 1024 * 1024
)
Variables ¶
var ErrorStreamAbandoned = errors.New("stream abandoned")
ErrorStreamAbandoned is returned when the input is closed before the end of the stream
Functions ¶
This section is empty.
Types ¶
type AsyncReader ¶
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 ¶
func New(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 ¶
func (a *AsyncReader) Abandon()
Abandon will ensure that the underlying async reader is shut down. It will NOT close the input supplied on New.
func (*AsyncReader) Close ¶
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 ¶
func (a *AsyncReader) Read(p []byte) (n int, err error)
Read will return the next available data.
func (*AsyncReader) SkipBytes ¶
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.