JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 192242
  • Score
    100M100P100Q157837F
  • License BSD-3-Clause

Read binary streams in chunks, on demand, with promises.

Package Exports

  • stream-source

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (stream-source) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

stream-source

A readable stream default reader implementation on top of a Node readable stream. This library allows you to write code that takes a reader as input, and can work with either native readable streams or Node streams. For example, to pipe stdin to stdout:

var stream = require("stream-source");

var source = stream.source(process.stdin);

function read() {
  return source.read().then((result) => {
    if (result.done) return;
    process.stdout.write(result.value);
    return read();
  });
}

read().catch((error) => console.error(error.stack));

API Reference

# stream.source(stream) <>

Returns a source for the specified node stream.

# source.read() <>

Returns a Promise for the next chunk of data from the underlying stream. The yielded result is an object with the following properties:

  • value - a Uint8Array (a Buffer), or undefined if the stream ended
  • done - a boolean which is true if the stream ended

# source.cancel() <>

Returns a Promise which is resolved when the underlying stream has been destroyed.