API · Formats

split()

Decode chunks incrementally and emit lines or tokens separated by a custom regular expression.

Examples

const lines = exstream(response.body).split()
const utf16Lines = exstream(chunks).split('utf16le')
const nullDelimitedRecords = exstream(chunks).split(/\0/, 'utf8')

Parameters

encoding

Type stringDefault 'utf8'

When passed as the only argument, selects the decoder encoding while retaining the default /\r?\n/ line separator.

separator

Type RegExpOptional

A custom pattern passed to String.prototype.split. When present, an optional second string argument selects the encoding.

Streaming behavior

Without a separator, split() uses /\r?\n/ for Unix and Windows line endings. A custom separator may span chunk boundaries, and multibyte characters are preserved by the incremental decoder. Delimiters are removed; capturing groups follow native String.prototype.split semantics and may appear in the output.

Completed tokens are emitted immediately in order. The incomplete suffix is retained between chunks and is always emitted when input ends, including an empty string after a trailing separator and for empty decoded input. Memory is proportional to the longest segment without a separator.

Choose a separator that cannot match the empty string, because empty matches can produce surprising native split output. Order and record context are preserved. Existing record errors pass through without clearing the buffered suffix.

Errors

Unsupported encodings throw at operator creation. Invalid chunks or decoder failures become processing errors according to the runtime codec. Use parser-specific size limits when accepting untrusted records.

Forms

stream.split()
stream.split('utf16le')
stream.split(/\0/, 'utf8')

exstream.pipeline().split(/\0/)

Signature

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

decode(), csv(), jsonl()