@@ -18,25 +18,22 @@ Installation of the [npm package](https://npmjs.org/package/async-iterator-to-st
1818## Usage
1919
2020``` js
21- const asyncIteratorToStream = require (' async-iterator-to-stream' )
21+ const asyncIteratorToStream = require (" async-iterator-to-stream" );
2222
2323// sync/async iterators
24- asyncIteratorToStream (new Set ([' foo' , ' bar' ]).values ())
25- .pipe (output)
24+ asyncIteratorToStream (new Set ([" foo" , " bar" ]).values ()).pipe (output);
2625
2726// sync/async iterables
28- asyncIteratorToStream .obj ([1 , 2 , 3 ])
29- .pipe (output)
27+ asyncIteratorToStream .obj ([1 , 2 , 3 ]).pipe (output);
3028
3129// if you pass a sync/async generator, it will return a factory instead of a
3230// stream
33- const createRangeStream = asyncIteratorToStream .obj (function * (n ) {
31+ const createRangeStream = asyncIteratorToStream .obj (function * (n ) {
3432 for (let i = 0 ; i < n; ++ i) {
35- yield i
33+ yield i;
3634 }
37- })
38- createRangeStream (10 )
39- .pipe (output)
35+ });
36+ createRangeStream (10 ).pipe (output);
4037```
4138
4239## Example
@@ -45,30 +42,30 @@ Let's implement a simpler `fs.createReadStream` to illustrate the usage of this
4542library.
4643
4744``` js
48- const asyncIteratorToStream = require (' async-iterator-to-stream' )
45+ const asyncIteratorToStream = require (" async-iterator-to-stream" );
4946
5047// promisified fs
51- const fs = require (' mz/fs' )
48+ const fs = require (" mz/fs" );
5249
53- const createReadStream = asyncIteratorToStream (async function * (file ) {
54- const fd = await fs .open (file, ' r ' )
50+ const createReadStream = asyncIteratorToStream (async function * (file ) {
51+ const fd = await fs .open (file, " r " );
5552 try {
56- let size = yield
53+ let size = yield ;
5754 while (true ) {
58- const buf = Buffer .alloc (size)
59- const [n ] = await fs .read (fd, buf, 0 , size, null )
55+ const buf = Buffer .alloc (size);
56+ const [n ] = await fs .read (fd, buf, 0 , size, null );
6057 if (n < size) {
61- yield buf .slice (0 , n)
62- return
58+ yield buf .slice (0 , n);
59+ return ;
6360 }
64- size = yield buf
61+ size = yield buf;
6562 }
6663 } finally {
67- await fs .close (fd)
64+ await fs .close (fd);
6865 }
69- })
66+ });
7067
71- createReadStream (' foo.txt' ).pipe (process .stdout )
68+ createReadStream (" foo.txt" ).pipe (process .stdout );
7269```
7370
7471> If your environment does not support async generators, you may use a sync
@@ -95,7 +92,7 @@ createReadStream('foo.txt').pipe(process.stdout)
9592
9693## Contributions
9794
98- Contributions are * very * welcomed, either on the documentation or on
95+ Contributions are _ very _ welcomed, either on the documentation or on
9996the code.
10097
10198You may:
0 commit comments