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))
| 351 | // Deprecated: use [Pipe.FilterLine] or [Pipe.FilterScan] instead, which run |
| 352 | // concurrently and don't do unnecessary reads on the input. |
| 353 | func (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. |