Documentation ¶
Overview ¶
Package pipe is a simple stream processing library that works like Unix pipes. This library has no external dependencies and is fully asynchronous. Create a Pipe from a Reader, add some transformation functions and get the result on an io.Writer.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pipe ¶
type Pipe struct { // Total number of bytes read at the origin of the Pipe. TotalIn int64 // Total number of bytes written at the end of the Pipe. TotalOut int64 // contains filtered or unexported fields }
Pipe object
Example ¶
package main import ( "compress/gzip" "github.com/hyperboloide/pipe" "io" "log" "os" ) func main() { // some Filter transformation function var zip = func(r io.Reader, w io.Writer) error { gzw, err := gzip.NewWriterLevel(w, gzip.BestSpeed) if err != nil { return err } defer gzw.Close() _, err = io.Copy(gzw, r) return err } // pipe input in, err := os.Open("test.txt") if err != nil { log.Fatal(err) } defer in.Close() // create a new pipe with a io.Reader p := pipe.New(in) // Pushing transformation function p.Push(zip) // pipe output out, err := os.Create("test.txt.tgz") if err != nil { log.Fatal(err) } defer out.Close() // Set pipe output io.Writer p.To(out) // Wait for pipe process to complete if err := p.Exec(); err != nil { log.Fatal(err) } }
Output:
func (*Pipe) Exec ¶
Exec waits for the Pipe to complete and returns an error if any of the functions failed.
func (*Pipe) Push ¶
Push appends a function to the Pipe. Note that you can add as many functions as you like at once or separatly. They will be processed in order.
Click to show internal directories.
Click to hide internal directories.