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

Method EachLine

script.go:353–363  ·  view source on GitHub ↗

EachLine calls the function process on each line of input, passing it the line as a string, and a [*strings.Builder] to write its output to. Deprecated: use [Pipe.FilterLine] or [Pipe.FilterScan] instead, which run concurrently and don't do unnecessary reads on the input.

(process func(string, *strings.Builder))

Source from the content-addressed store, hash-verified

351// Deprecated: use [Pipe.FilterLine] or [Pipe.FilterScan] instead, which run
352// concurrently and don't do unnecessary reads on the input.
353func (p *Pipe) EachLine(process func(string, *strings.Builder)) *Pipe {
354 return p.Filter(func(r io.Reader, w io.Writer) error {
355 scanner := newScanner(r)
356 output := new(strings.Builder)
357 for scanner.Scan() {
358 process(scanner.Text(), output)
359 }
360 fmt.Fprint(w, output.String())
361 return scanner.Err()
362 })
363}
364
365// Echo sets the pipe's reader to one that produces the string s, detaching any
366// existing reader without draining or closing it.

Calls 3

FilterMethod · 0.95
newScannerFunction · 0.85
StringMethod · 0.80