From bddfe2fe074a1d9689e7233deea81e9806ed02a6 Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Sun, 16 Jan 2022 14:18:17 +0200 Subject: [PATCH] Use native Readable.from Also remove readable-stream as a dependency (assuming non EoL Node.js) --- index.js | 37 +++---------------------------------- 1 file changed, 3 insertions(+), 34 deletions(-) diff --git a/index.js b/index.js index ca1d730..44dde26 100644 --- a/index.js +++ b/index.js @@ -1,46 +1,15 @@ 'use strict' -var Readable = require('readable-stream').Readable -; - -/** - * Create a new instance of StreamArray - * - * @access private - * @param {Array} list - */ -function StreamArray(list) { - if (!Array.isArray(list)) - throw new TypeError('First argument must be an Array'); - - Readable.call(this, {objectMode:true}); - - this._i = 0; - this._l = list.length; - this._list = list; -} - -StreamArray.prototype = Object.create(Readable.prototype, {constructor: {value: StreamArray}}); - -/** - * Read the next item from the source Array and push into NodeJS stream - - * @access protected - * @desc Read the next item from the source Array and push into NodeJS stream - * @param {number} size The amount of data to read (ignored) - */ -StreamArray.prototype._read = function(size) { - this.push(this._i < this._l ? this._list[this._i++] : null); -}; +const Readable = require('stream'); /** * Create a new instance of StreamArray * * @module stream-array - * @desc Push Array elements through a NodeJS stream + * @desc Push Array elements through a Node.js stream * @type {function} * @param {Array} list An Array of objects, strings, numbers, etc */ module.exports = function(list) { - return new StreamArray(list); + return Readable.from(list); };