Introduced in 4.3.0

Stability: 1 - Experimental

const Stream = require('kado/lib/Stream')

class Stream

The stream class is an exposure of the Node.js core Stream class. This provides convenience as we overlay common Stream manipulation mechanisms on to the core functionality.

class Stream.HeaderParser

Parse header pairs from a readable stream.

Stream.HeaderParser.constructor(cfg = {})


class Stream.StreamChain

Extends Stream.Readable

StreamChain provides the ability to add various streams into a heap and have a single output stream result.


const fs = require('kado/lib/FileSystem')
const Stream = require('kado/lib/Stream')
const StreamChain = Stream.StreamChain
const stream1 = fs.createReadStream(fs.path.resolve('testfile.text'))
const stream2 = Buffer.from('some string')
const stream3 = fs.createReadStream(fs.path.resolve(__dirname, 'somephoto.jpg'))
const output = fs.createWriteStream(fs.path.resolve(__dirname, 'newfile.pack'))
const chain = new StreamChain()
Stream.pipeline(chain, output, (err) => {
  let code = 0
  if (err) {
    console.log('Stream had errors', err)
  } else {
    console.log('Stream chain complete')

Stream.StreamChain.constructor(options = {})


class Stream.StreamChunk

Extends Stream.Readable

This is a mirror stream that exports input data to a readable export.

The StreamChunk class implements a header-aware Stream interface.

StreamChunk Events

.on('header', (header) => {…})

class Stream.StreamSearch

Extends EventEmitter

Stream search lives up to its name and provides need searching within a flowing stream.



Stream.StreamSearch Property List.

Useful properties maintained by the search.

class Stream.StreamSlicer

Extends Stream.Writable

StreamSlicer takes a boundary needle and divides the stream into chunks based on that needle. It will call the part even as it finds sections of the stream which allows your program to handle the different data regions appropriately.



Sets the boundary to use for parsing and performs some initialization needed for parsing. You should only need to use this if you set headerFirst to true in the constructor and are parsing the boundary from the preamble header.

StreamSlicer Events

.on('finish', () => {…})

Emitted when all parts have been parsed, and the instance has been ended.

.on('part', (stream) => {…})

Emitted when a new part has been found.

.on('preamble', (stream) => {…})

Emitted for preamble if you should happen to need it (can usually be ignored).

.on('trailer', (data) => {…})

Emitted when trailing data was found after the terminating boundary (as with the preamble, this can usually be ignored too).