0.2.10 • Published 2 years ago

safe-readable-stream v0.2.10

Weekly downloads
10
License
MIT
Repository
github
Last release
2 years ago

Wrapper on Node.js stream.Readable().

Promise based work with stream.Readable() for safe pushing data into the stream.

E.g. you can use:

const rStream = require('safe-readable-stream');

const outStream = rStream.createSafeReadableStream({
  logger,
  objectMode: false,
});

// Good, await will wait until stream will be ready to read next chunks.
await outStream.pushArray(['A', 'B', 'C']);

// Pushing next chunk.
// But without wait. Not good.
// Next push can return rejected promise
// if underlying push will require next event loop tick.
outStream.push('B');

// Promise can be rejected.
// Because it is not safe to push data outside _read call.
await outStream.finish();

Catching an error sent by outStream.error(msg):

It is useful when you are reading some data from some source by chunks and at some soment you got error from the source. So you should pass the error to the receiving part.

So for receiving part you can use such code:

const rStream = require('safe-readable-stream');

response.on('data', (data) => {
  const errStr = rStream.checkErrorString(data);
  if (errStr) {
    // Error was sent.
    l.println(`Checked error string: ${errStr}`);
  }
});
0.2.10

2 years ago

0.2.9

4 years ago

0.2.8

4 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago