MCPcopy
hub / github.com/bitfield/script / Filter

Method Filter

script.go:536–551  ·  view source on GitHub ↗

Filter sends the contents of the pipe to the function filter and produces the result. filter takes an [io.Reader] to read its input from and an [io.Writer] to write its output to, and returns an error, which will be set on the pipe. filter runs concurrently, so its goroutine will not exit until the

(filter func(io.Reader, io.Writer) error)

Source from the content-addressed store, hash-verified

534// been fully read. Use [Pipe.Wait] to wait for all concurrent filters to
535// complete.
536func (p *Pipe) Filter(filter func(io.Reader, io.Writer) error) *Pipe {
537 if p.Error() != nil {
538 return p
539 }
540 pr, pw := io.Pipe()
541 origReader := p.Reader
542 p = p.WithReader(pr)
543 go func() {
544 defer pw.Close()
545 err := filter(origReader, pw)
546 if err != nil {
547 p.SetError(err)
548 }
549 }()
550 return p
551}
552
553// FilterLine sends the contents of the pipe to the function filter, a line at
554// a time, and produces the result. filter takes each line as a string and

Callers 15

DecodeBase64Method · 0.95
DoMethod · 0.95
EachLineMethod · 0.95
EncodeBase64Method · 0.95
ExecMethod · 0.95
ExecForEachMethod · 0.95
FilterScanMethod · 0.95
FirstMethod · 0.95
FreqMethod · 0.95
JoinMethod · 0.95
JQMethod · 0.95
LastMethod · 0.95

Calls 4

ErrorMethod · 0.95
WithReaderMethod · 0.95
SetErrorMethod · 0.95
CloseMethod · 0.45