func BenchmarkPipingLineReverse(b *testing.B) { b.SetBytes(benchmarkPipingSize) fpath, err := mkRandFile(benchmarkPipingSize) if err != nil { b.Fatalf("temporary file: %v", err) } defer os.Remove(fpath) p := nxpipe.Line( nxpipe.Func(func(s *nxpipe.Session) error { f, err := os.Open(fpath) if err != nil { return err } defer f.Close() _, err = io.Copy(s.Stdout, f) return err }), nxpipe.Exec("cat"), ) b.ResetTimer() for i := 0; i < b.N; i++ { err := nxpipe.Run(p) if err != nil { b.Fatalf("exec: %v", err) } } b.StopTimer() }
func BenchmarkPipingLine(b *testing.B) { b.SetBytes(benchmarkPipingSize) fpath, err := mkRandFile(benchmarkPipingSize) if err != nil { b.Fatalf("temporary file: %v", err) } defer os.Remove(fpath) p := nxpipe.Line( nxpipe.Exec("cat", fpath), nxpipe.Func(func(s *nxpipe.Session) error { _, err := io.Copy(ioutil.Discard, s.Stdin) return err }), ) b.ResetTimer() for i := 0; i < b.N; i++ { err := nxpipe.Run(p) if err != nil { b.Fatalf("exec: %v", err) } } b.StopTimer() }
func Example() { p, err := nxpipe.Output(nxpipe.Line( nxpipe.Script( nxpipe.Exec("echo", "-n", "hello"), nxpipe.Exec("echo", " world"), ), nxpipe.Exec("sed", `s/o/O/g`), )) if err != nil { fmt.Printf("error: %v", err) return } fmt.Printf("%s\n", p) // Output: hellO wOrld }