Skip to content

Streams convention

Dima Yv edited this page Aug 29, 2016 · 12 revisions

From the realtime streams discussion.

Audio components provide functional factory as main export, ./stream.js for stream interface and ./pull.js for pull-stream interface.

Source/readables:

// sync source
module.exports = function (options) {
  return function () {
    //return null to end
    return buffer
  }
}

// async source
module.exports = function (options) {
  return function (cb) {
    //cb(null, null) to end
    //cb(error) to throw error
    cb(null, buffer)
  }
}

Through/map:

// sync through
module.exports = function (options) {
  return function (buffer) {
    //return null to end
    return buffer
  }
}

// async through
module.exports = function (options) {
  return function (buffer, cb) {
    //cb(null, null) to end
    //cb(error) to throw error
    cb(null, buffer)
  }
}

Sink/destination/writable:

// sync sink
module.exports = function (options) {
  return function (buffer) {
    // do stuff
    // throw error
    // or return null to end
  }
}

// async sink
module.exports = function (options) {
  return function (buffer, cb) {
    // do stuff
    // how do we end or throw error here?
  }
}
Clone this wiki locally