API · Formats

splitBy()

Decode chunks incrementally and split the resulting text with a regular expression.

Signature

splitBy(separator: RegExp, encoding?: string): Exstream<string, C>

Example

const records = exstream(chunks).splitBy(/\0/, 'utf8')

Parameters

separator

Type RegExpRequired

Pattern passed to String.prototype.split for the accumulated decoded text. Capturing groups follow native split semantics and can appear in output.

encoding

Type stringDefault 'utf8'

Encoding supported by the active runtime decoder.

Streaming

The incomplete suffix is retained between chunks, allowing separators and multibyte characters to cross boundaries. Completed tokens are emitted immediately in order. On end, the remaining suffix is emitted even when empty. Memory is proportional to the longest segment without a separator.

Choose a separator that cannot match the empty string; empty matches can create surprising native split() output. Context follows emitted tokens from their current input boundary. Existing record errors pass through.

Forms

stream.splitBy(/\0/, 'utf8')
exstream.pipeline().splitBy(/\0/)
exstream.splitBy(/\0/, 'utf8', stream)
stream.through(exstream.splitBy(/\0/))

split(), decode(), jsonl()