readable-stream
Advanced tools
Comparing version 3.6.1 to 3.6.2
@@ -38,10 +38,10 @@ // Copyright Joyent, Inc. and other Node contributors. | ||
module.exports = Duplex; | ||
const Readable = require('./_stream_readable'); | ||
const Writable = require('./_stream_writable'); | ||
var Readable = require('./_stream_readable'); | ||
var Writable = require('./_stream_writable'); | ||
require('inherits')(Duplex, Readable); | ||
{ | ||
// Allow the keys array to be GC'ed. | ||
const keys = objectKeys(Writable.prototype); | ||
var keys = objectKeys(Writable.prototype); | ||
for (var v = 0; v < keys.length; v++) { | ||
const method = keys[v]; | ||
var method = keys[v]; | ||
if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method]; | ||
@@ -69,3 +69,3 @@ } | ||
enumerable: false, | ||
get() { | ||
get: function get() { | ||
return this._writableState.highWaterMark; | ||
@@ -88,3 +88,3 @@ } | ||
enumerable: false, | ||
get() { | ||
get: function get() { | ||
return this._writableState.length; | ||
@@ -111,3 +111,3 @@ } | ||
enumerable: false, | ||
get() { | ||
get: function get() { | ||
if (this._readableState === undefined || this._writableState === undefined) { | ||
@@ -118,3 +118,3 @@ return false; | ||
}, | ||
set(value) { | ||
set: function set(value) { | ||
// we ignore the value if the stream | ||
@@ -121,0 +121,0 @@ // has not been initialized yet |
@@ -29,3 +29,3 @@ // Copyright Joyent, Inc. and other Node contributors. | ||
module.exports = PassThrough; | ||
const Transform = require('./_stream_transform'); | ||
var Transform = require('./_stream_transform'); | ||
require('inherits')(PassThrough, Transform); | ||
@@ -32,0 +32,0 @@ function PassThrough(options) { |
@@ -33,3 +33,3 @@ // Copyright Joyent, Inc. and other Node contributors. | ||
/*<replacement>*/ | ||
const EE = require('events').EventEmitter; | ||
var EE = require('events').EventEmitter; | ||
var EElistenerCount = function EElistenerCount(emitter, type) { | ||
@@ -44,4 +44,4 @@ return emitter.listeners(type).length; | ||
const Buffer = require('buffer').Buffer; | ||
const OurUint8Array = (typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {}).Uint8Array || function () {}; | ||
var Buffer = require('buffer').Buffer; | ||
var OurUint8Array = (typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {}).Uint8Array || function () {}; | ||
function _uint8ArrayToBuffer(chunk) { | ||
@@ -55,4 +55,4 @@ return Buffer.from(chunk); | ||
/*<replacement>*/ | ||
const debugUtil = require('util'); | ||
let debug; | ||
var debugUtil = require('util'); | ||
var debug; | ||
if (debugUtil && debugUtil.debuglog) { | ||
@@ -65,7 +65,7 @@ debug = debugUtil.debuglog('stream'); | ||
const BufferList = require('./internal/streams/buffer_list'); | ||
const destroyImpl = require('./internal/streams/destroy'); | ||
const _require = require('./internal/streams/state'), | ||
var BufferList = require('./internal/streams/buffer_list'); | ||
var destroyImpl = require('./internal/streams/destroy'); | ||
var _require = require('./internal/streams/state'), | ||
getHighWaterMark = _require.getHighWaterMark; | ||
const _require$codes = require('../errors').codes, | ||
var _require$codes = require('../errors').codes, | ||
ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE, | ||
@@ -77,8 +77,8 @@ ERR_STREAM_PUSH_AFTER_EOF = _require$codes.ERR_STREAM_PUSH_AFTER_EOF, | ||
// Lazy loaded to improve the startup performance. | ||
let StringDecoder; | ||
let createReadableStreamAsyncIterator; | ||
let from; | ||
var StringDecoder; | ||
var createReadableStreamAsyncIterator; | ||
var from; | ||
require('inherits')(Readable, Stream); | ||
const errorOrDestroy = destroyImpl.errorOrDestroy; | ||
const kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume']; | ||
var errorOrDestroy = destroyImpl.errorOrDestroy; | ||
var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume']; | ||
function prependListener(emitter, event, fn) { | ||
@@ -174,3 +174,3 @@ // Sadly this is not cacheable as some libraries bundle their own | ||
// the ReadableState constructor, at least with V8 6.5 | ||
const isDuplex = this instanceof Duplex; | ||
var isDuplex = this instanceof Duplex; | ||
this._readableState = new ReadableState(options, this, isDuplex); | ||
@@ -191,3 +191,3 @@ | ||
enumerable: false, | ||
get() { | ||
get: function get() { | ||
if (this._readableState === undefined) { | ||
@@ -198,3 +198,3 @@ return false; | ||
}, | ||
set(value) { | ||
set: function set(value) { | ||
// we ignore the value if the stream | ||
@@ -310,3 +310,3 @@ // has not been initialized yet | ||
if (!StringDecoder) StringDecoder = require('string_decoder/').StringDecoder; | ||
const decoder = new StringDecoder(enc); | ||
var decoder = new StringDecoder(enc); | ||
this._readableState.decoder = decoder; | ||
@@ -317,4 +317,4 @@ // If setEncoding(null), decoder.encoding equals utf8 | ||
// Iterate over current buffer to convert already stored Buffers: | ||
let p = this._readableState.buffer.head; | ||
let content = ''; | ||
var p = this._readableState.buffer.head; | ||
var content = ''; | ||
while (p !== null) { | ||
@@ -331,3 +331,3 @@ content += decoder.write(p.data); | ||
// Don't raise the hwm > 1GB | ||
const MAX_HWM = 0x40000000; | ||
var MAX_HWM = 0x40000000; | ||
function computeNewHighWaterMark(n) { | ||
@@ -559,3 +559,3 @@ if (n >= MAX_HWM) { | ||
while (!state.reading && !state.ended && (state.length < state.highWaterMark || state.flowing && state.length === 0)) { | ||
const len = state.length; | ||
var len = state.length; | ||
debug('maybeReadMore read 0'); | ||
@@ -757,4 +757,4 @@ stream.read(0); | ||
Readable.prototype.on = function (ev, fn) { | ||
const res = Stream.prototype.on.call(this, ev, fn); | ||
const state = this._readableState; | ||
var res = Stream.prototype.on.call(this, ev, fn); | ||
var state = this._readableState; | ||
if (ev === 'data') { | ||
@@ -784,3 +784,3 @@ // update readableListening so that resume() may be a no-op | ||
Readable.prototype.removeListener = function (ev, fn) { | ||
const res = Stream.prototype.removeListener.call(this, ev, fn); | ||
var res = Stream.prototype.removeListener.call(this, ev, fn); | ||
if (ev === 'readable') { | ||
@@ -798,3 +798,3 @@ // We need to check if there is someone still listening to | ||
Readable.prototype.removeAllListeners = function (ev) { | ||
const res = Stream.prototype.removeAllListeners.apply(this, arguments); | ||
var res = Stream.prototype.removeAllListeners.apply(this, arguments); | ||
if (ev === 'readable' || ev === undefined) { | ||
@@ -812,3 +812,3 @@ // We need to check if there is someone still listening to | ||
function updateReadableListening(self) { | ||
const state = self._readableState; | ||
var state = self._readableState; | ||
state.readableListening = self.listenerCount('readable') > 0; | ||
@@ -872,3 +872,3 @@ if (state.resumeScheduled && !state.paused) { | ||
function flow(stream) { | ||
const state = stream._readableState; | ||
var state = stream._readableState; | ||
debug('flow', state.flowing); | ||
@@ -882,13 +882,14 @@ while (state.flowing && stream.read() !== null); | ||
Readable.prototype.wrap = function (stream) { | ||
var _this = this; | ||
var state = this._readableState; | ||
var paused = false; | ||
stream.on('end', () => { | ||
stream.on('end', function () { | ||
debug('wrapped end'); | ||
if (state.decoder && !state.ended) { | ||
var chunk = state.decoder.end(); | ||
if (chunk && chunk.length) this.push(chunk); | ||
if (chunk && chunk.length) _this.push(chunk); | ||
} | ||
this.push(null); | ||
_this.push(null); | ||
}); | ||
stream.on('data', chunk => { | ||
stream.on('data', function (chunk) { | ||
debug('wrapped data'); | ||
@@ -899,3 +900,3 @@ if (state.decoder) chunk = state.decoder.write(chunk); | ||
if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return; | ||
var ret = this.push(chunk); | ||
var ret = _this.push(chunk); | ||
if (!ret) { | ||
@@ -926,3 +927,3 @@ paused = true; | ||
// underlying stream. | ||
this._read = n => { | ||
this._read = function (n) { | ||
debug('wrapped _read', n); | ||
@@ -984,3 +985,3 @@ if (paused) { | ||
enumerable: false, | ||
get() { | ||
get: function get() { | ||
return this._readableState.length; | ||
@@ -1027,3 +1028,3 @@ } | ||
// if the writable side is ready for autoDestroy as well | ||
const wState = stream._writableState; | ||
var wState = stream._writableState; | ||
if (!wState || wState.autoDestroy && wState.finished) { | ||
@@ -1030,0 +1031,0 @@ stream.destroy(); |
@@ -67,3 +67,3 @@ // Copyright Joyent, Inc. and other Node contributors. | ||
module.exports = Transform; | ||
const _require$codes = require('../errors').codes, | ||
var _require$codes = require('../errors').codes, | ||
ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED, | ||
@@ -73,3 +73,3 @@ ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK, | ||
ERR_TRANSFORM_WITH_LENGTH_0 = _require$codes.ERR_TRANSFORM_WITH_LENGTH_0; | ||
const Duplex = require('./_stream_duplex'); | ||
var Duplex = require('./_stream_duplex'); | ||
require('inherits')(Transform, Duplex); | ||
@@ -123,5 +123,6 @@ function afterTransform(er, data) { | ||
function prefinish() { | ||
var _this = this; | ||
if (typeof this._flush === 'function' && !this._readableState.destroyed) { | ||
this._flush((er, data) => { | ||
done(this, er, data); | ||
this._flush(function (er, data) { | ||
done(_this, er, data); | ||
}); | ||
@@ -176,3 +177,3 @@ } else { | ||
Transform.prototype._destroy = function (err, cb) { | ||
Duplex.prototype._destroy.call(this, err, err2 => { | ||
Duplex.prototype._destroy.call(this, err, function (err2) { | ||
cb(err2); | ||
@@ -179,0 +180,0 @@ }); |
@@ -41,6 +41,7 @@ // Copyright Joyent, Inc. and other Node contributors. | ||
function CorkedRequest(state) { | ||
var _this = this; | ||
this.next = null; | ||
this.entry = null; | ||
this.finish = () => { | ||
onCorkedFinish(this, state); | ||
this.finish = function () { | ||
onCorkedFinish(_this, state); | ||
}; | ||
@@ -57,3 +58,3 @@ } | ||
/*<replacement>*/ | ||
const internalUtil = { | ||
var internalUtil = { | ||
deprecate: require('util-deprecate') | ||
@@ -67,4 +68,4 @@ }; | ||
const Buffer = require('buffer').Buffer; | ||
const OurUint8Array = (typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {}).Uint8Array || function () {}; | ||
var Buffer = require('buffer').Buffer; | ||
var OurUint8Array = (typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {}).Uint8Array || function () {}; | ||
function _uint8ArrayToBuffer(chunk) { | ||
@@ -76,6 +77,6 @@ return Buffer.from(chunk); | ||
} | ||
const destroyImpl = require('./internal/streams/destroy'); | ||
const _require = require('./internal/streams/state'), | ||
var destroyImpl = require('./internal/streams/destroy'); | ||
var _require = require('./internal/streams/state'), | ||
getHighWaterMark = _require.getHighWaterMark; | ||
const _require$codes = require('../errors').codes, | ||
var _require$codes = require('../errors').codes, | ||
ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE, | ||
@@ -89,3 +90,3 @@ ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED, | ||
ERR_UNKNOWN_ENCODING = _require$codes.ERR_UNKNOWN_ENCODING; | ||
const errorOrDestroy = destroyImpl.errorOrDestroy; | ||
var errorOrDestroy = destroyImpl.errorOrDestroy; | ||
require('inherits')(Writable, Stream); | ||
@@ -248,3 +249,3 @@ function nop() {} | ||
// the WritableState constructor, at least with V8 6.5 | ||
const isDuplex = this instanceof Duplex; | ||
var isDuplex = this instanceof Duplex; | ||
if (!isDuplex && !realHasInstance.call(Writable, this)) return new Writable(options); | ||
@@ -373,5 +374,5 @@ this._writableState = new WritableState(options, this, isDuplex); | ||
state.lastBufferedRequest = { | ||
chunk, | ||
encoding, | ||
isBuf, | ||
chunk: chunk, | ||
encoding: encoding, | ||
isBuf: isBuf, | ||
callback: cb, | ||
@@ -549,3 +550,3 @@ next: null | ||
enumerable: false, | ||
get() { | ||
get: function get() { | ||
return this._writableState.length; | ||
@@ -558,3 +559,3 @@ } | ||
function callFinal(stream, state) { | ||
stream._final(err => { | ||
stream._final(function (err) { | ||
state.pendingcb--; | ||
@@ -591,3 +592,3 @@ if (err) { | ||
// if the readable side is ready for autoDestroy as well | ||
const rState = stream._readableState; | ||
var rState = stream._readableState; | ||
if (!rState || rState.autoDestroy && rState.endEmitted) { | ||
@@ -628,3 +629,3 @@ stream.destroy(); | ||
enumerable: false, | ||
get() { | ||
get: function get() { | ||
if (this._writableState === undefined) { | ||
@@ -635,3 +636,3 @@ return false; | ||
}, | ||
set(value) { | ||
set: function set(value) { | ||
// we ignore the value if the stream | ||
@@ -638,0 +639,0 @@ // has not been initialized yet |
'use strict'; | ||
const finished = require('./end-of-stream'); | ||
const kLastResolve = Symbol('lastResolve'); | ||
const kLastReject = Symbol('lastReject'); | ||
const kError = Symbol('error'); | ||
const kEnded = Symbol('ended'); | ||
const kLastPromise = Symbol('lastPromise'); | ||
const kHandlePromise = Symbol('handlePromise'); | ||
const kStream = Symbol('stream'); | ||
var _Object$setPrototypeO; | ||
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } | ||
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } | ||
var finished = require('./end-of-stream'); | ||
var kLastResolve = Symbol('lastResolve'); | ||
var kLastReject = Symbol('lastReject'); | ||
var kError = Symbol('error'); | ||
var kEnded = Symbol('ended'); | ||
var kLastPromise = Symbol('lastPromise'); | ||
var kHandlePromise = Symbol('handlePromise'); | ||
var kStream = Symbol('stream'); | ||
function createIterResult(value, done) { | ||
return { | ||
value, | ||
done | ||
value: value, | ||
done: done | ||
}; | ||
} | ||
function readAndResolve(iter) { | ||
const resolve = iter[kLastResolve]; | ||
var resolve = iter[kLastResolve]; | ||
if (resolve !== null) { | ||
const data = iter[kStream].read(); | ||
var data = iter[kStream].read(); | ||
// we defer if data is null | ||
@@ -38,4 +42,4 @@ // we can be expecting either 'end' or | ||
function wrapForNext(lastPromise, iter) { | ||
return (resolve, reject) => { | ||
lastPromise.then(() => { | ||
return function (resolve, reject) { | ||
lastPromise.then(function () { | ||
if (iter[kEnded]) { | ||
@@ -49,11 +53,12 @@ resolve(createIterResult(undefined, true)); | ||
} | ||
const AsyncIteratorPrototype = Object.getPrototypeOf(function () {}); | ||
const ReadableStreamAsyncIteratorPrototype = Object.setPrototypeOf({ | ||
var AsyncIteratorPrototype = Object.getPrototypeOf(function () {}); | ||
var ReadableStreamAsyncIteratorPrototype = Object.setPrototypeOf((_Object$setPrototypeO = { | ||
get stream() { | ||
return this[kStream]; | ||
}, | ||
next() { | ||
next: function next() { | ||
var _this = this; | ||
// if we have detected an error in the meanwhile | ||
// reject straight away | ||
const error = this[kError]; | ||
var error = this[kError]; | ||
if (error !== null) { | ||
@@ -70,6 +75,6 @@ return Promise.reject(error); | ||
// waiting to be emitted. | ||
return new Promise((resolve, reject) => { | ||
process.nextTick(() => { | ||
if (this[kError]) { | ||
reject(this[kError]); | ||
return new Promise(function (resolve, reject) { | ||
process.nextTick(function () { | ||
if (_this[kError]) { | ||
reject(_this[kError]); | ||
} else { | ||
@@ -86,4 +91,4 @@ resolve(createIterResult(undefined, true)); | ||
// where next() is only called once at a time | ||
const lastPromise = this[kLastPromise]; | ||
let promise; | ||
var lastPromise = this[kLastPromise]; | ||
var promise; | ||
if (lastPromise) { | ||
@@ -94,3 +99,3 @@ promise = new Promise(wrapForNext(lastPromise, this)); | ||
// without triggering the next() queue | ||
const data = this[kStream].read(); | ||
var data = this[kStream].read(); | ||
if (data !== null) { | ||
@@ -103,66 +108,56 @@ return Promise.resolve(createIterResult(data, false)); | ||
return promise; | ||
}, | ||
[Symbol.asyncIterator]() { | ||
return this; | ||
}, | ||
return() { | ||
// destroy(err, cb) is a private API | ||
// we can guarantee we have that here, because we control the | ||
// Readable class this is attached to | ||
return new Promise((resolve, reject) => { | ||
this[kStream].destroy(null, err => { | ||
if (err) { | ||
reject(err); | ||
return; | ||
} | ||
resolve(createIterResult(undefined, true)); | ||
}); | ||
} | ||
}, _defineProperty(_Object$setPrototypeO, Symbol.asyncIterator, function () { | ||
return this; | ||
}), _defineProperty(_Object$setPrototypeO, "return", function _return() { | ||
var _this2 = this; | ||
// destroy(err, cb) is a private API | ||
// we can guarantee we have that here, because we control the | ||
// Readable class this is attached to | ||
return new Promise(function (resolve, reject) { | ||
_this2[kStream].destroy(null, function (err) { | ||
if (err) { | ||
reject(err); | ||
return; | ||
} | ||
resolve(createIterResult(undefined, true)); | ||
}); | ||
} | ||
}, AsyncIteratorPrototype); | ||
const createReadableStreamAsyncIterator = stream => { | ||
const iterator = Object.create(ReadableStreamAsyncIteratorPrototype, { | ||
[kStream]: { | ||
value: stream, | ||
writable: true | ||
}); | ||
}), _Object$setPrototypeO), AsyncIteratorPrototype); | ||
var createReadableStreamAsyncIterator = function createReadableStreamAsyncIterator(stream) { | ||
var _Object$create; | ||
var iterator = Object.create(ReadableStreamAsyncIteratorPrototype, (_Object$create = {}, _defineProperty(_Object$create, kStream, { | ||
value: stream, | ||
writable: true | ||
}), _defineProperty(_Object$create, kLastResolve, { | ||
value: null, | ||
writable: true | ||
}), _defineProperty(_Object$create, kLastReject, { | ||
value: null, | ||
writable: true | ||
}), _defineProperty(_Object$create, kError, { | ||
value: null, | ||
writable: true | ||
}), _defineProperty(_Object$create, kEnded, { | ||
value: stream._readableState.endEmitted, | ||
writable: true | ||
}), _defineProperty(_Object$create, kHandlePromise, { | ||
value: function value(resolve, reject) { | ||
var data = iterator[kStream].read(); | ||
if (data) { | ||
iterator[kLastPromise] = null; | ||
iterator[kLastResolve] = null; | ||
iterator[kLastReject] = null; | ||
resolve(createIterResult(data, false)); | ||
} else { | ||
iterator[kLastResolve] = resolve; | ||
iterator[kLastReject] = reject; | ||
} | ||
}, | ||
[kLastResolve]: { | ||
value: null, | ||
writable: true | ||
}, | ||
[kLastReject]: { | ||
value: null, | ||
writable: true | ||
}, | ||
[kError]: { | ||
value: null, | ||
writable: true | ||
}, | ||
[kEnded]: { | ||
value: stream._readableState.endEmitted, | ||
writable: true | ||
}, | ||
// the function passed to new Promise | ||
// is cached so we avoid allocating a new | ||
// closure at every run | ||
[kHandlePromise]: { | ||
value: (resolve, reject) => { | ||
const data = iterator[kStream].read(); | ||
if (data) { | ||
iterator[kLastPromise] = null; | ||
iterator[kLastResolve] = null; | ||
iterator[kLastReject] = null; | ||
resolve(createIterResult(data, false)); | ||
} else { | ||
iterator[kLastResolve] = resolve; | ||
iterator[kLastReject] = reject; | ||
} | ||
}, | ||
writable: true | ||
} | ||
}); | ||
writable: true | ||
}), _Object$create)); | ||
iterator[kLastPromise] = null; | ||
finished(stream, err => { | ||
finished(stream, function (err) { | ||
if (err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE') { | ||
const reject = iterator[kLastReject]; | ||
var reject = iterator[kLastReject]; | ||
// reject if we are waiting for data in the Promise | ||
@@ -179,3 +174,3 @@ // returned by next() and store the error | ||
} | ||
const resolve = iterator[kLastResolve]; | ||
var resolve = iterator[kLastResolve]; | ||
if (resolve !== null) { | ||
@@ -182,0 +177,0 @@ iterator[kLastPromise] = null; |
@@ -6,14 +6,18 @@ 'use strict'; | ||
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } | ||
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } | ||
const _require = require('buffer'), | ||
var _require = require('buffer'), | ||
Buffer = _require.Buffer; | ||
const _require2 = require('util'), | ||
var _require2 = require('util'), | ||
inspect = _require2.inspect; | ||
const custom = inspect && inspect.custom || 'inspect'; | ||
var custom = inspect && inspect.custom || 'inspect'; | ||
function copyBuffer(src, target, offset) { | ||
Buffer.prototype.copy.call(src, target, offset); | ||
} | ||
module.exports = class BufferList { | ||
constructor() { | ||
module.exports = /*#__PURE__*/function () { | ||
function BufferList() { | ||
_classCallCheck(this, BufferList); | ||
this.head = null; | ||
@@ -23,135 +27,159 @@ this.tail = null; | ||
} | ||
push(v) { | ||
const entry = { | ||
data: v, | ||
next: null | ||
}; | ||
if (this.length > 0) this.tail.next = entry;else this.head = entry; | ||
this.tail = entry; | ||
++this.length; | ||
} | ||
unshift(v) { | ||
const entry = { | ||
data: v, | ||
next: this.head | ||
}; | ||
if (this.length === 0) this.tail = entry; | ||
this.head = entry; | ||
++this.length; | ||
} | ||
shift() { | ||
if (this.length === 0) return; | ||
const ret = this.head.data; | ||
if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next; | ||
--this.length; | ||
return ret; | ||
} | ||
clear() { | ||
this.head = this.tail = null; | ||
this.length = 0; | ||
} | ||
join(s) { | ||
if (this.length === 0) return ''; | ||
var p = this.head; | ||
var ret = '' + p.data; | ||
while (p = p.next) ret += s + p.data; | ||
return ret; | ||
} | ||
concat(n) { | ||
if (this.length === 0) return Buffer.alloc(0); | ||
const ret = Buffer.allocUnsafe(n >>> 0); | ||
var p = this.head; | ||
var i = 0; | ||
while (p) { | ||
copyBuffer(p.data, ret, i); | ||
i += p.data.length; | ||
p = p.next; | ||
_createClass(BufferList, [{ | ||
key: "push", | ||
value: function push(v) { | ||
var entry = { | ||
data: v, | ||
next: null | ||
}; | ||
if (this.length > 0) this.tail.next = entry;else this.head = entry; | ||
this.tail = entry; | ||
++this.length; | ||
} | ||
return ret; | ||
} | ||
}, { | ||
key: "unshift", | ||
value: function unshift(v) { | ||
var entry = { | ||
data: v, | ||
next: this.head | ||
}; | ||
if (this.length === 0) this.tail = entry; | ||
this.head = entry; | ||
++this.length; | ||
} | ||
}, { | ||
key: "shift", | ||
value: function shift() { | ||
if (this.length === 0) return; | ||
var ret = this.head.data; | ||
if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next; | ||
--this.length; | ||
return ret; | ||
} | ||
}, { | ||
key: "clear", | ||
value: function clear() { | ||
this.head = this.tail = null; | ||
this.length = 0; | ||
} | ||
}, { | ||
key: "join", | ||
value: function join(s) { | ||
if (this.length === 0) return ''; | ||
var p = this.head; | ||
var ret = '' + p.data; | ||
while (p = p.next) ret += s + p.data; | ||
return ret; | ||
} | ||
}, { | ||
key: "concat", | ||
value: function concat(n) { | ||
if (this.length === 0) return Buffer.alloc(0); | ||
var ret = Buffer.allocUnsafe(n >>> 0); | ||
var p = this.head; | ||
var i = 0; | ||
while (p) { | ||
copyBuffer(p.data, ret, i); | ||
i += p.data.length; | ||
p = p.next; | ||
} | ||
return ret; | ||
} | ||
// Consumes a specified amount of bytes or characters from the buffered data. | ||
consume(n, hasStrings) { | ||
var ret; | ||
if (n < this.head.data.length) { | ||
// `slice` is the same for buffers and strings. | ||
ret = this.head.data.slice(0, n); | ||
this.head.data = this.head.data.slice(n); | ||
} else if (n === this.head.data.length) { | ||
// First chunk is a perfect match. | ||
ret = this.shift(); | ||
} else { | ||
// Result spans more than one buffer. | ||
ret = hasStrings ? this._getString(n) : this._getBuffer(n); | ||
// Consumes a specified amount of bytes or characters from the buffered data. | ||
}, { | ||
key: "consume", | ||
value: function consume(n, hasStrings) { | ||
var ret; | ||
if (n < this.head.data.length) { | ||
// `slice` is the same for buffers and strings. | ||
ret = this.head.data.slice(0, n); | ||
this.head.data = this.head.data.slice(n); | ||
} else if (n === this.head.data.length) { | ||
// First chunk is a perfect match. | ||
ret = this.shift(); | ||
} else { | ||
// Result spans more than one buffer. | ||
ret = hasStrings ? this._getString(n) : this._getBuffer(n); | ||
} | ||
return ret; | ||
} | ||
return ret; | ||
} | ||
first() { | ||
return this.head.data; | ||
} | ||
}, { | ||
key: "first", | ||
value: function first() { | ||
return this.head.data; | ||
} | ||
// Consumes a specified amount of characters from the buffered data. | ||
_getString(n) { | ||
var p = this.head; | ||
var c = 1; | ||
var ret = p.data; | ||
n -= ret.length; | ||
while (p = p.next) { | ||
const str = p.data; | ||
const nb = n > str.length ? str.length : n; | ||
if (nb === str.length) ret += str;else ret += str.slice(0, n); | ||
n -= nb; | ||
if (n === 0) { | ||
if (nb === str.length) { | ||
++c; | ||
if (p.next) this.head = p.next;else this.head = this.tail = null; | ||
} else { | ||
this.head = p; | ||
p.data = str.slice(nb); | ||
// Consumes a specified amount of characters from the buffered data. | ||
}, { | ||
key: "_getString", | ||
value: function _getString(n) { | ||
var p = this.head; | ||
var c = 1; | ||
var ret = p.data; | ||
n -= ret.length; | ||
while (p = p.next) { | ||
var str = p.data; | ||
var nb = n > str.length ? str.length : n; | ||
if (nb === str.length) ret += str;else ret += str.slice(0, n); | ||
n -= nb; | ||
if (n === 0) { | ||
if (nb === str.length) { | ||
++c; | ||
if (p.next) this.head = p.next;else this.head = this.tail = null; | ||
} else { | ||
this.head = p; | ||
p.data = str.slice(nb); | ||
} | ||
break; | ||
} | ||
break; | ||
++c; | ||
} | ||
++c; | ||
this.length -= c; | ||
return ret; | ||
} | ||
this.length -= c; | ||
return ret; | ||
} | ||
// Consumes a specified amount of bytes from the buffered data. | ||
_getBuffer(n) { | ||
const ret = Buffer.allocUnsafe(n); | ||
var p = this.head; | ||
var c = 1; | ||
p.data.copy(ret); | ||
n -= p.data.length; | ||
while (p = p.next) { | ||
const buf = p.data; | ||
const nb = n > buf.length ? buf.length : n; | ||
buf.copy(ret, ret.length - n, 0, nb); | ||
n -= nb; | ||
if (n === 0) { | ||
if (nb === buf.length) { | ||
++c; | ||
if (p.next) this.head = p.next;else this.head = this.tail = null; | ||
} else { | ||
this.head = p; | ||
p.data = buf.slice(nb); | ||
// Consumes a specified amount of bytes from the buffered data. | ||
}, { | ||
key: "_getBuffer", | ||
value: function _getBuffer(n) { | ||
var ret = Buffer.allocUnsafe(n); | ||
var p = this.head; | ||
var c = 1; | ||
p.data.copy(ret); | ||
n -= p.data.length; | ||
while (p = p.next) { | ||
var buf = p.data; | ||
var nb = n > buf.length ? buf.length : n; | ||
buf.copy(ret, ret.length - n, 0, nb); | ||
n -= nb; | ||
if (n === 0) { | ||
if (nb === buf.length) { | ||
++c; | ||
if (p.next) this.head = p.next;else this.head = this.tail = null; | ||
} else { | ||
this.head = p; | ||
p.data = buf.slice(nb); | ||
} | ||
break; | ||
} | ||
break; | ||
++c; | ||
} | ||
++c; | ||
this.length -= c; | ||
return ret; | ||
} | ||
this.length -= c; | ||
return ret; | ||
} | ||
// Make sure the linked list only shows the minimal necessary information. | ||
[custom](_, options) { | ||
return inspect(this, _objectSpread(_objectSpread({}, options), {}, { | ||
// Only inspect one level. | ||
depth: 0, | ||
// It should not recurse. | ||
customInspect: false | ||
})); | ||
} | ||
}; | ||
// Make sure the linked list only shows the minimal necessary information. | ||
}, { | ||
key: custom, | ||
value: function value(_, options) { | ||
return inspect(this, _objectSpread(_objectSpread({}, options), {}, { | ||
// Only inspect one level. | ||
depth: 0, | ||
// It should not recurse. | ||
customInspect: false | ||
})); | ||
} | ||
}]); | ||
return BufferList; | ||
}(); |
@@ -5,4 +5,5 @@ 'use strict'; | ||
function destroy(err, cb) { | ||
const readableDestroyed = this._readableState && this._readableState.destroyed; | ||
const writableDestroyed = this._writableState && this._writableState.destroyed; | ||
var _this = this; | ||
var readableDestroyed = this._readableState && this._readableState.destroyed; | ||
var writableDestroyed = this._writableState && this._writableState.destroyed; | ||
if (readableDestroyed || writableDestroyed) { | ||
@@ -33,17 +34,17 @@ if (cb) { | ||
} | ||
this._destroy(err || null, err => { | ||
this._destroy(err || null, function (err) { | ||
if (!cb && err) { | ||
if (!this._writableState) { | ||
process.nextTick(emitErrorAndCloseNT, this, err); | ||
} else if (!this._writableState.errorEmitted) { | ||
this._writableState.errorEmitted = true; | ||
process.nextTick(emitErrorAndCloseNT, this, err); | ||
if (!_this._writableState) { | ||
process.nextTick(emitErrorAndCloseNT, _this, err); | ||
} else if (!_this._writableState.errorEmitted) { | ||
_this._writableState.errorEmitted = true; | ||
process.nextTick(emitErrorAndCloseNT, _this, err); | ||
} else { | ||
process.nextTick(emitCloseNT, this); | ||
process.nextTick(emitCloseNT, _this); | ||
} | ||
} else if (cb) { | ||
process.nextTick(emitCloseNT, this); | ||
process.nextTick(emitCloseNT, _this); | ||
cb(err); | ||
} else { | ||
process.nextTick(emitCloseNT, this); | ||
process.nextTick(emitCloseNT, _this); | ||
} | ||
@@ -89,10 +90,10 @@ }); | ||
const rState = stream._readableState; | ||
const wState = stream._writableState; | ||
var rState = stream._readableState; | ||
var wState = stream._writableState; | ||
if (rState && rState.autoDestroy || wState && wState.autoDestroy) stream.destroy(err);else stream.emit('error', err); | ||
} | ||
module.exports = { | ||
destroy, | ||
undestroy, | ||
errorOrDestroy | ||
destroy: destroy, | ||
undestroy: undestroy, | ||
errorOrDestroy: errorOrDestroy | ||
}; |
@@ -6,5 +6,5 @@ // Ported from https://github.com/mafintosh/end-of-stream with | ||
const ERR_STREAM_PREMATURE_CLOSE = require('../../../errors').codes.ERR_STREAM_PREMATURE_CLOSE; | ||
var ERR_STREAM_PREMATURE_CLOSE = require('../../../errors').codes.ERR_STREAM_PREMATURE_CLOSE; | ||
function once(callback) { | ||
let called = false; | ||
var called = false; | ||
return function () { | ||
@@ -27,9 +27,9 @@ if (called) return; | ||
callback = once(callback || noop); | ||
let readable = opts.readable || opts.readable !== false && stream.readable; | ||
let writable = opts.writable || opts.writable !== false && stream.writable; | ||
const onlegacyfinish = () => { | ||
var readable = opts.readable || opts.readable !== false && stream.readable; | ||
var writable = opts.writable || opts.writable !== false && stream.writable; | ||
var onlegacyfinish = function onlegacyfinish() { | ||
if (!stream.writable) onfinish(); | ||
}; | ||
var writableEnded = stream._writableState && stream._writableState.finished; | ||
const onfinish = () => { | ||
var onfinish = function onfinish() { | ||
writable = false; | ||
@@ -40,3 +40,3 @@ writableEnded = true; | ||
var readableEnded = stream._readableState && stream._readableState.endEmitted; | ||
const onend = () => { | ||
var onend = function onend() { | ||
readable = false; | ||
@@ -46,7 +46,7 @@ readableEnded = true; | ||
}; | ||
const onerror = err => { | ||
var onerror = function onerror(err) { | ||
callback.call(stream, err); | ||
}; | ||
const onclose = () => { | ||
let err; | ||
var onclose = function onclose() { | ||
var err; | ||
if (readable && !readableEnded) { | ||
@@ -61,3 +61,3 @@ if (!stream._readableState || !stream._readableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE(); | ||
}; | ||
const onrequest = () => { | ||
var onrequest = function onrequest() { | ||
stream.req.on('finish', onfinish); | ||
@@ -64,0 +64,0 @@ }; |
@@ -10,9 +10,9 @@ 'use strict'; | ||
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } | ||
const ERR_INVALID_ARG_TYPE = require('../../../errors').codes.ERR_INVALID_ARG_TYPE; | ||
var ERR_INVALID_ARG_TYPE = require('../../../errors').codes.ERR_INVALID_ARG_TYPE; | ||
function from(Readable, iterable, opts) { | ||
let iterator; | ||
var iterator; | ||
if (iterable && typeof iterable.next === 'function') { | ||
iterator = iterable; | ||
} else if (iterable && iterable[Symbol.asyncIterator]) iterator = iterable[Symbol.asyncIterator]();else if (iterable && iterable[Symbol.iterator]) iterator = iterable[Symbol.iterator]();else throw new ERR_INVALID_ARG_TYPE('iterable', ['Iterable'], iterable); | ||
const readable = new Readable(_objectSpread({ | ||
var readable = new Readable(_objectSpread({ | ||
objectMode: true | ||
@@ -22,3 +22,3 @@ }, opts)); | ||
// being called before last iteration completion. | ||
let reading = false; | ||
var reading = false; | ||
readable._read = function () { | ||
@@ -36,3 +36,3 @@ if (!reading) { | ||
try { | ||
const _yield$iterator$next = yield iterator.next(), | ||
var _yield$iterator$next = yield iterator.next(), | ||
value = _yield$iterator$next.value, | ||
@@ -55,2 +55,2 @@ done = _yield$iterator$next.done; | ||
} | ||
module.exports = from; | ||
module.exports = from; |
@@ -6,12 +6,12 @@ // Ported from https://github.com/mafintosh/pump with | ||
let eos; | ||
var eos; | ||
function once(callback) { | ||
let called = false; | ||
var called = false; | ||
return function () { | ||
if (called) return; | ||
called = true; | ||
callback(...arguments); | ||
callback.apply(void 0, arguments); | ||
}; | ||
} | ||
const _require$codes = require('../../../errors').codes, | ||
var _require$codes = require('../../../errors').codes, | ||
ERR_MISSING_ARGS = _require$codes.ERR_MISSING_ARGS, | ||
@@ -28,4 +28,4 @@ ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED; | ||
callback = once(callback); | ||
let closed = false; | ||
stream.on('close', () => { | ||
var closed = false; | ||
stream.on('close', function () { | ||
closed = true; | ||
@@ -37,3 +37,3 @@ }); | ||
writable: writing | ||
}, err => { | ||
}, function (err) { | ||
if (err) return callback(err); | ||
@@ -43,4 +43,4 @@ closed = true; | ||
}); | ||
let destroyed = false; | ||
return err => { | ||
var destroyed = false; | ||
return function (err) { | ||
if (closed) return; | ||
@@ -71,3 +71,3 @@ if (destroyed) return; | ||
} | ||
const callback = popCallback(streams); | ||
var callback = popCallback(streams); | ||
if (Array.isArray(streams[0])) streams = streams[0]; | ||
@@ -77,6 +77,6 @@ if (streams.length < 2) { | ||
} | ||
let error; | ||
const destroys = streams.map(function (stream, i) { | ||
const reading = i < streams.length - 1; | ||
const writing = i > 0; | ||
var error; | ||
var destroys = streams.map(function (stream, i) { | ||
var reading = i < streams.length - 1; | ||
var writing = i > 0; | ||
return destroyer(stream, reading, writing, function (err) { | ||
@@ -83,0 +83,0 @@ if (!error) error = err; |
'use strict'; | ||
const ERR_INVALID_OPT_VALUE = require('../../../errors').codes.ERR_INVALID_OPT_VALUE; | ||
var ERR_INVALID_OPT_VALUE = require('../../../errors').codes.ERR_INVALID_OPT_VALUE; | ||
function highWaterMarkFrom(options, isDuplex, duplexKey) { | ||
@@ -8,6 +8,6 @@ return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null; | ||
function getHighWaterMark(state, options, duplexKey, isDuplex) { | ||
const hwm = highWaterMarkFrom(options, isDuplex, duplexKey); | ||
var hwm = highWaterMarkFrom(options, isDuplex, duplexKey); | ||
if (hwm != null) { | ||
if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) { | ||
const name = isDuplex ? duplexKey : 'highWaterMark'; | ||
var name = isDuplex ? duplexKey : 'highWaterMark'; | ||
throw new ERR_INVALID_OPT_VALUE(name, hwm); | ||
@@ -22,3 +22,3 @@ } | ||
module.exports = { | ||
getHighWaterMark | ||
getHighWaterMark: getHighWaterMark | ||
}; |
{ | ||
"name": "readable-stream", | ||
"version": "3.6.1", | ||
"version": "3.6.2", | ||
"description": "Streams3, a user-land copy of the stream library from Node.js", | ||
@@ -5,0 +5,0 @@ "main": "readable.js", |
123971
2815