child_process/line_buffer

Types

A buffer for accumulating partial line data from a port.

Use this when processing data from a child process via streams and you want line-by-line processing.

pub opaque type LineBuffer

Values

pub fn feed(
  buffer: LineBuffer,
  data: BitArray,
) -> #(List(String), LineBuffer)

Feed data into the line buffer.

Returns a list of complete lines (including their newline characters) and the updated buffer containing any partial line data.

Example

let buffer = line_buffer.new()
let #(lines, buffer) = line_buffer.feed(buffer, <<"hello\nworld">>)
// lines = ["hello\n"]
// buffer still contains "world"
pub fn flush(buffer: LineBuffer) -> option.Option(String)

Flush any remaining data in the buffer.

Call this when the process exits to get any final partial line that didn’t end with a newline.

pub fn new() -> LineBuffer

Create a new line buffer.

Search Document