go-stream
A collection of io.Reader
and io.Writer
for working with big amounts of data.
The collection aims for read-once solutions, without the need for buffering.
Installation
go get github.com/elgohr/go-stream
Example on steroids
w := stream.NewSizeWriter()
content := "content"
splitter := stream.NewSuffixSplitter(strings.NewReader(content), 3)
_, err := io.Copy(os.Stderr, io.TeeReader(splitter, w))
if err != nil {
log.Fatalln(err)
}
originalBufferSize := w.Size()
_, err = io.Copy(os.Stdout, splitter.Suffix())
if err != nil {
log.Fatalln(err)
}
Outputs:
- "ent" (suffix) to os.Stdout
- "cont" to os.Stderr
- 7 as originalBufferSize
Usage
Please see examples.