| 1234567891011121314151617181920212223 |
- 'use strict';
- const {Readable, Writable} = require('stream');
- const streamFromArray = array =>
- new Readable({
- objectMode: true,
- read() {
- if (isNaN(this.index)) this.index = 0;
- this.push(this.index < array.length ? array[this.index++] : null);
- }
- });
- const streamToArray = array =>
- new Writable({
- objectMode: true,
- write(chunk, encoding, callback) {
- array.push(chunk);
- callback(null);
- }
- });
- module.exports = {streamFromArray, streamToArray};
|