Gathering detailed insights and metrics for async-iterator-to-stream
Gathering detailed insights and metrics for async-iterator-to-stream
Gathering detailed insights and metrics for async-iterator-to-stream
Gathering detailed insights and metrics for async-iterator-to-stream
Convert an async iterator/iterable to a readable stream
npm install async-iterator-to-stream
Typescript
Module System
Min. Node Version
Node Version
NPM Version
70.6
Supply Chain
99.2
Quality
78.6
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
720,537
Last Day
95
Last Week
796
Last Month
3,670
Last Year
54,955
ISC License
7 Stars
30 Commits
2 Watchers
13 Branches
1 Contributors
Updated on Apr 13, 2023
Minified
Minified + Gzipped
Latest Version
1.2.0
Package Id
async-iterator-to-stream@1.2.0
Size
5.70 kB
NPM Version
6.14.4
Node Version
12.16.1
Published on
Apr 10, 2020
Cumulative downloads
Total Downloads
Last Day
-30.1%
95
Compared to previous day
Last Week
-13.4%
796
Compared to previous week
Last Month
-13.8%
3,670
Compared to previous month
Last Year
-64.2%
54,955
Compared to previous year
Convert an async iterator/iterable to a readable stream
Even though this library is dedicated to async iterators, it is fully compatible with synchronous ones.
Furthermore, generators can be used to create readable stream factories!
Installation of the npm package:
> npm install --save async-iterator-to-stream
1const asyncIteratorToStream = require("async-iterator-to-stream"); 2 3// sync/async iterators 4asyncIteratorToStream(new Set(["foo", "bar"]).values()).pipe(output); 5 6// sync/async iterables 7asyncIteratorToStream.obj([1, 2, 3]).pipe(output); 8 9// if you pass a sync/async generator, it will return a factory instead of a 10// stream 11const createRangeStream = asyncIteratorToStream.obj(function*(n) { 12 for (let i = 0; i < n; ++i) { 13 yield i; 14 } 15}); 16createRangeStream(10).pipe(output);
Let's implement a simpler fs.createReadStream
to illustrate the usage of this
library.
1const asyncIteratorToStream = require("async-iterator-to-stream"); 2 3// promisified fs 4const fs = require("mz/fs"); 5 6const createReadStream = asyncIteratorToStream(async function*(file) { 7 const fd = await fs.open(file, "r"); 8 try { 9 let size = yield; 10 while (true) { 11 const buf = Buffer.alloc(size); 12 const [n] = await fs.read(fd, buf, 0, size, null); 13 if (n < size) { 14 yield buf.slice(0, n); 15 return; 16 } 17 size = yield buf; 18 } 19 } finally { 20 await fs.close(fd); 21 } 22}); 23 24createReadStream("foo.txt").pipe(process.stdout);
If your environment does not support async generators, you may use a sync generator instead and
yield
promises to wait for them.
# Install dependencies
> npm
# Run the tests
> npm test
# Continuously compile
> npm run dev
# Continuously run the tests
> npm run dev-test
# Build for production
> npm run build
Contributions are very welcomed, either on the documentation or on the code.
You may:
ISC © Julien Fontanet
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
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
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
37 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