API · Core

data() and nil

Disambiguate domain data from Exstream's error and end control records.

Signature

function data<T>(value: T): DataValue<T>
const nil: unique symbol

Error values as data

write(error) interprets an Error as a record error. Wrap it to preserve it as domain data:

source.write(exstream.data(new Error('stored failure')))
// equivalent at a writable boundary:
source.writeData(new Error('stored failure'))

The wrapper is consumed at the write boundary; downstream receives the original value, not { value }. data() is useful inside iterables too, where each item passes through write() classification.

End marker

exstream.nil is the unique protocol value meaning end. Custom generators finish with write(exstream.nil), and low-level consumers receive/forward it. Do not use it as ordinary payload. High-level source adapters call end() for you.

write(), writeData(), consume(), end()