Gathering detailed insights and metrics for promise-stream-reader
Gathering detailed insights and metrics for promise-stream-reader
Gathering detailed insights and metrics for promise-stream-reader
Gathering detailed insights and metrics for promise-stream-reader
Consume readable streams in Node.js using promises
npm install promise-stream-reader
Typescript
Module System
Min. Node Version
Node Version
NPM Version
90.3
Supply Chain
93.9
Quality
75.1
Maintenance
100
Vulnerability
100
License
TypeScript (100%)
Total Downloads
1,354,270
Last Day
2,220
Last Week
12,257
Last Month
52,867
Last Year
361,430
MIT License
2 Stars
10 Commits
1 Watchers
1 Branches
1 Contributors
Updated on May 14, 2021
Minified
Minified + Gzipped
Latest Version
1.0.1
Package Id
promise-stream-reader@1.0.1
Unpacked Size
24.18 kB
Size
8.11 kB
File Count
11
NPM Version
5.6.0
Node Version
8.11.1
Cumulative downloads
Total Downloads
Last Day
61.2%
2,220
Compared to previous day
Last Week
-9.3%
12,257
Compared to previous week
Last Month
6.7%
52,867
Compared to previous month
Last Year
73.1%
361,430
Compared to previous year
Consume data from Node.js readable streams using promises and async/await to control flow.
npm install promise-stream-reader
The base export is a function that returns a writable stream to which you can pipe your readable/duplex stream.
1const promiseStream = require('promise-stream-reader'); 2 3async function readStream(readableStream) { 4 const reader = promiseStream(); 5 readableStream.pipe(reader); 6 7 // Read 4 bytes of data from the stream 8 const part1 = await reader.read(4); 9 10 // Skip 10 bytes of data 11 await reader.skip(10); 12 13 // You can also have multiple read/skip calls pending at the same time. They 14 // will be filled with data in the order they were initially requested. 15 const [part2, part3] = await Promise.all([ 16 reader.read(6), 17 reader.read(8) 18 ]); 19 20 // When you're all done, you can close up the streams 21 readableStream.unpipe(reader); 22 reader.destroy(); 23 readableStream.destroy(); 24} 25 26readStream(/* some readable stream */) 27 .catch(err => { /* don't forget to handle rejected promises */ });
NOTE: If you're using Typescript, the base exported function is available under the default export.
There are two modes for reading data from a readable stream in Node.js, but each has limitations that can be frustrating for a final consumer:
on('data')
(flowing) allows you to deal with data as
it comes in, but you have to take care of packaging the data up into the
chunks appropriate for your use case. You will also continue to receive data
as fast as it comes in by default, even if you're not really ready for it.
read()
(paused) allows you to explicitly request data but
has no mechanism for asynchronous retrieval. As a result, it will return null
if there is no data available yet, forcing you to poll until you get the data
you want. You can combine this with listening to the 'readable'
event, but
then you're using two patterns and still have to wrap it if you want to use
promises.
This solution aims to strike a balance between the two, allowing you to request the data you want when you need it and have the stream provide it to you as soon as it's available. You get to process the data quickly without extra manipulation or control flow required and can proceed at your own pace.
Want to contribute to the project? Go check out the Contribution Guide for instructions to set up your development environment, open an issue and create a pull request.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/10 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
76 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-05-05
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More