LogoPear Docs
ReferencesBareModules

bare-stream

Reference for bare-stream: streaming data for Bare—Node-style Readable/Writable/Duplex/Transform streams, stream utilities, and the WHATWG streams API.

stable

bare-stream provides streaming data types for Bare. It follows the Node.js stream module and also exposes the WHATWG streams API. It's pure JavaScript and underpins much of the bare-* ecosystem—bare-fs, bare-tcp, and others return its streams.

npm i bare-stream

Usage

const { Readable } = require('bare-stream')

const stream = new Readable({
  read () {
    this.push('hello')
    this.push('world')
    this.push(null) // end
  }
})

stream.on('data', (data) => console.log(data))

API

Node-style streams

const stream = new Readable([options])

A readable stream. stream.push(data[, encoding]) and stream.unshift(data[, encoding]) feed it; Readable.from(data[, options]) builds one from an iterable. Helpers: Readable.isBackpressured(stream), Readable.isPaused(stream), Readable.fromWeb(...), Readable.toWeb(...).

const stream = new Writable([options])

A writable stream. Write with stream.write(data[, encoding][, cb]) and finish with stream.end([data][, encoding][, cb]). Helpers: Writable.isBackpressured(stream), Writable.drained(stream), Writable.fromWeb(...), Writable.toWeb(...).

const stream = new Duplex([options]) · new Transform([options]) · new PassThrough([options])

Bidirectional, transforming, and pass-through streams. const [a, b] = duplexPair([options]) creates a connected pair.

Utilities

stream.pipeline(...streams[, cb]) · const stream = await pipeline(...streams)

Pipe a series of streams together, with callback or promise completion.

stream.finished(stream[, options], cb) · stream.addAbortSignal(signal, stream)

Observe stream completion, or wire an AbortSignal to a stream.

State predicates

isStream, isEnding, isEnded, isFinishing, isFinished, isDisturbed, isErrored, isReadable, isWritable, and getStreamError(stream[, options]).

WHATWG streams

new ReadableStream(...) · new WritableStream(...) · new TransformStream(...)

The web streams, with their readers, writers, controllers, and the CountQueuingStrategy / ByteLengthQueuingStrategy queuing strategies. Predicates: isReadableStream, isWritableStream, isTransformStream, and friends. Use fromWeb / toWeb on the Node-style classes to convert between the two worlds.

See also

On this page