stream-from-iterator
v1.0.1
Published
Create streams from ES2015 iterators
Downloads
45
Maintainers
Readme
stream-from-iterator
Create streams from ECMAScript® 2015 Iterators.
Install
npm install stream-from-iterator --save
Usage
import StreamFromIterator from 'stream-from-iterator';
function * strRange(start, end) {
for (var i = start; i <= end; i++) {
yield String(i);
}
}
new StreamFromIterator(strRange(0, 9))
.pipe(process.stdout); // output: 0123456789
Stream iterating over String | Buffer
s
import StreamFromIterator from 'stream-from-iterator';
new StreamFromIterator(['some', ' ', 'strings'].values())
.pipe(process.stdout); // output: some strings
new StreamFromIterator([new Buffer('some'), ' mixed ', new Buffer('strings')].values())
.pipe(process.stdout); // output: some mixed strings
Stream iterating over (arbitrary) Javascript Values
import StreamFromIterator from 'stream-from-iterator';
var i = 0;
StreamFromIterator.obj(['some', 42, 'mixed', 'array', () => {}].values())
.on('data', data => {
console.log(i++ + ': ' + typeof data);
/* outputs:
0: string
1: number
2: string
3: string
4: function
*/
});
API
Class: StreamFromIterator
StreamFromIterators are Readable streams.
new StreamFromIterator(iterator, [options])
- iterator
Iterator
ES2015 Iterator iterating over arbitrary Javascript values like numbers, strings, objects, functions, ... - options
Object
passed through new Readable([options])
Note: The new
operator can be omitted.
StreamFromIterator#obj(iterator, [options])
A convenience wrapper for new StreamFromIterator(iterator, {objectMode: true, ...})
.
Related
- stream-from: Create streams from promises, iterators, factories and arbitrary Javascript values like functions, arrays, etc.
License
MIT © Michael Mayer