Documentation
¶
Overview ¶
Package stream provides a way to read and write to a synchronous buffered pipe, with multiple reader support.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFoundInMem = errors.New("not found")
ErrNotFoundInMem is returned when an in-memory FileSystem cannot find a file.
var ErrRemoving = errors.New("cannot open a new reader while removing file")
ErrRemoving is returned when requesting a Reader on a Stream which is being Removed.
Functions ¶
This section is empty.
Types ¶
type File ¶
type File interface {
Name() string // The name used to Create/Open the File
io.Reader // Reader must continue reading after EOF on subsequent calls after more Writes.
io.ReaderAt // Similarly to Reader
io.Writer // Concurrent reading/writing must be supported.
io.Closer // Close should do any cleanup when done with the File.
}
File is a backing data-source for a Stream.
type FileSystem ¶
type FileSystem interface {
Create(name string) (File, error) // Create must return a new File for Writing
Open(name string) (File, error) // Open must return an existing File for Reading
Remove(name string) error // Remove deletes an existing File
}
FileSystem is used to manage Files
var StdFileSystem FileSystem = stdFS{}
StdFileSystem is backed by the os package.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader is a concurrent-safe Stream Reader.
func (*Reader) Close ¶
Close closes this Reader on the Stream. This must be called when done with the Reader or else the Stream cannot be Removed.
func (*Reader) Read ¶
Read reads from the Stream. If the end of an open Stream is reached, Read blocks until more data is written or the Stream is Closed.
func (*Reader) ReadAt ¶
ReadAt lets you Read from specific offsets in the Stream. ReadAt blocks while waiting for the requested section of the Stream to be written, unless the Stream is closed in which case it will always return immediately.
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream is used to concurrently Write and Read from a File.
func NewStream ¶
func NewStream(name string, fs FileSystem) (*Stream, error)
NewStream creates a new Stream with Name "name" in FileSystem fs.
func (*Stream) Close ¶
Close will close the active stream. This will cause Readers to return EOF once they have read the entire stream.
func (*Stream) NextReader ¶
NextReader will return a concurrent-safe Reader for this stream. Each Reader will see a complete and independent view of the stream, and can Read will the stream is written to.