diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-04-03 15:43:32 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-04-03 15:45:57 +0200 |
commit | 71e285b94c7edaa43aa8115965cf5a36b8e0f80a (patch) | |
tree | 7d4aa9d0d5aff686b106cd5da72ba77960c4af43 /deps/node/deps/npm/node_modules/sorted-union-stream/node_modules/from2/index.js | |
parent | 7dadf9356b4f3f4137ce982ea5bb960283116e9a (diff) | |
download | akono-71e285b94c7edaa43aa8115965cf5a36b8e0f80a.tar.gz akono-71e285b94c7edaa43aa8115965cf5a36b8e0f80a.tar.bz2 akono-71e285b94c7edaa43aa8115965cf5a36b8e0f80a.zip |
Node.js v11.13.0
Diffstat (limited to 'deps/node/deps/npm/node_modules/sorted-union-stream/node_modules/from2/index.js')
-rw-r--r-- | deps/node/deps/npm/node_modules/sorted-union-stream/node_modules/from2/index.js | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/deps/node/deps/npm/node_modules/sorted-union-stream/node_modules/from2/index.js b/deps/node/deps/npm/node_modules/sorted-union-stream/node_modules/from2/index.js new file mode 100644 index 00000000..d83be0b5 --- /dev/null +++ b/deps/node/deps/npm/node_modules/sorted-union-stream/node_modules/from2/index.js @@ -0,0 +1,93 @@ +var Readable = require('readable-stream').Readable +var inherits = require('inherits') + +module.exports = from2 + +from2.ctor = ctor +from2.obj = obj + +var Proto = ctor() + +function toFunction(list) { + list = list.slice() + return function (_, cb) { + cb(null, list.length ? list.shift() : null) + } +} + +function from2(opts, read) { + if (typeof opts !== 'object' || Array.isArray(opts)) { + read = opts + opts = {} + } + + if (Array.isArray(read)) read = toFunction(read) + + var rs = new Proto(opts) + rs._from = read + return rs +} + +function ctor(opts, read) { + if (typeof opts === 'function') { + read = opts + opts = {} + } + + opts = defaults(opts) + + inherits(Class, Readable) + function Class(override) { + if (!(this instanceof Class)) return new Class(override) + this._reading = false + this.destroyed = false + Readable.call(this, override || opts) + } + + Class.prototype._from = read + Class.prototype._read = function(size) { + var self = this + + if (this._reading || this.destroyed) return + this._reading = true + this._from(size, check) + function check(err, data) { + if (self.destroyed) return + if (err) return self.destroy(err) + if (data === null) return self.push(null) + self._reading = false + if (self.push(data)) self._read() + } + } + + Class.prototype.destroy = function(err) { + if (this.destroyed) return + this.destroyed = true + + var self = this + process.nextTick(function() { + if (err) self.emit('error', err) + self.emit('close') + }) + } + + return Class +} + +function obj(opts, read) { + if (typeof opts === 'function' || Array.isArray(opts)) { + read = opts + opts = {} + } + + opts = defaults(opts) + opts.objectMode = true + opts.highWaterMark = 16 + + return from2(opts, read) +} + +function defaults(opts) { + opts = opts || {} + return opts +} |