Documentation
¶
Overview ¶
The readahead package will do asynchronous read-ahead from an input io.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.
The readahead object also fulfills the io.WriterTo interface, which is likely to speed up copies.
Package home: https://github.com/klauspost/readahead
Example ¶
package main
import (
"bytes"
"fmt"
"io"
"github.com/klauspost/readahead"
)
func main() {
// Buf is our input.
buf := bytes.NewBufferString("Example data")
// Create a Reader with default settings
reader := readahead.NewReader(buf)
defer reader.Close()
// Copy the content to dst
var dst = &bytes.Buffer{}
_, err := io.Copy(dst, reader)
if err != nil {
panic("error when reading: " + err.Error())
}
fmt.Println(dst.String())
}
Output: Example data
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewReadCloser ¶
func NewReadCloser(rd io.ReadCloser) io.ReadCloser
New returns a reader that will asynchronously read from the supplied reader into 4 buffers of 1MB each.
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, which will also close the supplied closer.
func NewReadCloserSize ¶
func NewReadCloserSize(rc io.ReadCloser, buffers, size int) (io.ReadCloser, error)
NewReadCloserSize returns a reader with a custom number of buffers and size. buffers is the number of queued buffers and size is the size of each buffer in bytes.
func NewReader ¶
func NewReader(rd io.Reader) io.ReadCloser
New returns a reader that will asynchronously read from the supplied reader into 4 buffers of 1MB each.
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.
func NewReaderSize ¶
NewReaderSize returns a reader with a custom number of buffers and size. buffers is the number of queued buffers and size is the size of each buffer in bytes.
Types ¶
This section is empty.