mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-28 06:53:42 +08:00
isarray, safe-buffer, process-nextick-args, inherits and util-deprecate evaluate to a Node builtin on Node 24 at their checked major versions, so a require of one compiles as that builtin expression at the require's position: from an opted-in package's files (the installed version where Node's resolution finds it), from the program's own CommonJS files, and through an esbuild __commonJS chunk whose pnpm path key names the package and its version. The package's files never join the program. readable-stream 2.x and 4.x compile as node:stream, the package's own READABLE_STREAM=disable behavior (a documented divergence). A use of the entry's export picks the builtin module (member reads of the carried classes) or stream.Readable (value uses); a mixture keeps the package. 3.x stays as is: its disable branch throws on Node 24. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2116 lines
69 KiB
JavaScript
2116 lines
69 KiB
JavaScript
"use strict";
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __commonJS = (cb, mod) => function __require() {
|
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
};
|
|
|
|
// node_modules/.pnpm/isarray@1.0.0/node_modules/isarray/index.js
|
|
var require_isarray = __commonJS({
|
|
"node_modules/.pnpm/isarray@1.0.0/node_modules/isarray/index.js"(exports2, module2) {
|
|
var toString = {}.toString;
|
|
module2.exports = Array.isArray || function(arr) {
|
|
return toString.call(arr) == "[object Array]";
|
|
};
|
|
}
|
|
});
|
|
|
|
// node_modules/.pnpm/safe-buffer@5.2.1/node_modules/safe-buffer/index.js
|
|
var require_safe_buffer = __commonJS({
|
|
"node_modules/.pnpm/safe-buffer@5.2.1/node_modules/safe-buffer/index.js"(exports2, module2) {
|
|
var buffer = require("buffer");
|
|
var Buffer3 = buffer.Buffer;
|
|
function copyProps(src, dst) {
|
|
for (var key in src) {
|
|
dst[key] = src[key];
|
|
}
|
|
}
|
|
if (Buffer3.from && Buffer3.alloc && Buffer3.allocUnsafe && Buffer3.allocUnsafeSlow) {
|
|
module2.exports = buffer;
|
|
} else {
|
|
copyProps(buffer, exports2);
|
|
exports2.Buffer = SafeBuffer;
|
|
}
|
|
function SafeBuffer(arg, encodingOrOffset, length) {
|
|
return Buffer3(arg, encodingOrOffset, length);
|
|
}
|
|
SafeBuffer.prototype = Object.create(Buffer3.prototype);
|
|
copyProps(Buffer3, SafeBuffer);
|
|
SafeBuffer.from = function(arg, encodingOrOffset, length) {
|
|
if (typeof arg === "number") {
|
|
throw new TypeError("Argument must not be a number");
|
|
}
|
|
return Buffer3(arg, encodingOrOffset, length);
|
|
};
|
|
SafeBuffer.alloc = function(size, fill, encoding) {
|
|
if (typeof size !== "number") {
|
|
throw new TypeError("Argument must be a number");
|
|
}
|
|
var buf = Buffer3(size);
|
|
if (fill !== void 0) {
|
|
if (typeof encoding === "string") {
|
|
buf.fill(fill, encoding);
|
|
} else {
|
|
buf.fill(fill);
|
|
}
|
|
} else {
|
|
buf.fill(0);
|
|
}
|
|
return buf;
|
|
};
|
|
SafeBuffer.allocUnsafe = function(size) {
|
|
if (typeof size !== "number") {
|
|
throw new TypeError("Argument must be a number");
|
|
}
|
|
return Buffer3(size);
|
|
};
|
|
SafeBuffer.allocUnsafeSlow = function(size) {
|
|
if (typeof size !== "number") {
|
|
throw new TypeError("Argument must be a number");
|
|
}
|
|
return buffer.SlowBuffer(size);
|
|
};
|
|
}
|
|
});
|
|
|
|
// node_modules/.pnpm/process-nextick-args@2.0.1/node_modules/process-nextick-args/index.js
|
|
var require_process_nextick_args = __commonJS({
|
|
"node_modules/.pnpm/process-nextick-args@2.0.1/node_modules/process-nextick-args/index.js"(exports2, module2) {
|
|
"use strict";
|
|
if (typeof process === "undefined" || !process.version || process.version.indexOf("v0.") === 0 || process.version.indexOf("v1.") === 0 && process.version.indexOf("v1.8.") !== 0) {
|
|
module2.exports = { nextTick };
|
|
} else {
|
|
module2.exports = process;
|
|
}
|
|
function nextTick(fn, arg1, arg2, arg3) {
|
|
if (typeof fn !== "function") {
|
|
throw new TypeError('"callback" argument must be a function');
|
|
}
|
|
var len = arguments.length;
|
|
var args, i;
|
|
switch (len) {
|
|
case 0:
|
|
case 1:
|
|
return process.nextTick(fn);
|
|
case 2:
|
|
return process.nextTick(function afterTickOne() {
|
|
fn.call(null, arg1);
|
|
});
|
|
case 3:
|
|
return process.nextTick(function afterTickTwo() {
|
|
fn.call(null, arg1, arg2);
|
|
});
|
|
case 4:
|
|
return process.nextTick(function afterTickThree() {
|
|
fn.call(null, arg1, arg2, arg3);
|
|
});
|
|
default:
|
|
args = new Array(len - 1);
|
|
i = 0;
|
|
while (i < args.length) {
|
|
args[i++] = arguments[i];
|
|
}
|
|
return process.nextTick(function afterTick() {
|
|
fn.apply(null, args);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
// node_modules/.pnpm/inherits@2.0.4/node_modules/inherits/inherits_browser.js
|
|
var require_inherits_browser = __commonJS({
|
|
"node_modules/.pnpm/inherits@2.0.4/node_modules/inherits/inherits_browser.js"(exports2, module2) {
|
|
if (typeof Object.create === "function") {
|
|
module2.exports = function inherits2(ctor, superCtor) {
|
|
if (superCtor) {
|
|
ctor.super_ = superCtor;
|
|
ctor.prototype = Object.create(superCtor.prototype, {
|
|
constructor: {
|
|
value: ctor,
|
|
enumerable: false,
|
|
writable: true,
|
|
configurable: true
|
|
}
|
|
});
|
|
}
|
|
};
|
|
} else {
|
|
module2.exports = function inherits2(ctor, superCtor) {
|
|
if (superCtor) {
|
|
ctor.super_ = superCtor;
|
|
var TempCtor = function() {
|
|
};
|
|
TempCtor.prototype = superCtor.prototype;
|
|
ctor.prototype = new TempCtor();
|
|
ctor.prototype.constructor = ctor;
|
|
}
|
|
};
|
|
}
|
|
}
|
|
});
|
|
|
|
// node_modules/.pnpm/inherits@2.0.4/node_modules/inherits/inherits.js
|
|
var require_inherits = __commonJS({
|
|
"node_modules/.pnpm/inherits@2.0.4/node_modules/inherits/inherits.js"(exports2, module2) {
|
|
try {
|
|
util = require("util");
|
|
if (typeof util.inherits !== "function") throw "";
|
|
module2.exports = util.inherits;
|
|
} catch (e) {
|
|
module2.exports = require_inherits_browser();
|
|
}
|
|
var util;
|
|
}
|
|
});
|
|
|
|
// node_modules/.pnpm/util-deprecate@1.0.2/node_modules/util-deprecate/node.js
|
|
var require_node = __commonJS({
|
|
"node_modules/.pnpm/util-deprecate@1.0.2/node_modules/util-deprecate/node.js"(exports2, module2) {
|
|
module2.exports = require("util").deprecate;
|
|
}
|
|
});
|
|
|
|
// node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/internal/streams/stream.js
|
|
var require_stream = __commonJS({
|
|
"node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/internal/streams/stream.js"(exports2, module2) {
|
|
module2.exports = require("stream");
|
|
}
|
|
});
|
|
|
|
// node_modules/.pnpm/safe-buffer@5.1.2/node_modules/safe-buffer/index.js
|
|
var require_safe_buffer2 = __commonJS({
|
|
"node_modules/.pnpm/safe-buffer@5.1.2/node_modules/safe-buffer/index.js"(exports2, module2) {
|
|
var buffer = require("buffer");
|
|
var Buffer3 = buffer.Buffer;
|
|
function copyProps(src, dst) {
|
|
for (var key in src) {
|
|
dst[key] = src[key];
|
|
}
|
|
}
|
|
if (Buffer3.from && Buffer3.alloc && Buffer3.allocUnsafe && Buffer3.allocUnsafeSlow) {
|
|
module2.exports = buffer;
|
|
} else {
|
|
copyProps(buffer, exports2);
|
|
exports2.Buffer = SafeBuffer;
|
|
}
|
|
function SafeBuffer(arg, encodingOrOffset, length) {
|
|
return Buffer3(arg, encodingOrOffset, length);
|
|
}
|
|
copyProps(Buffer3, SafeBuffer);
|
|
SafeBuffer.from = function(arg, encodingOrOffset, length) {
|
|
if (typeof arg === "number") {
|
|
throw new TypeError("Argument must not be a number");
|
|
}
|
|
return Buffer3(arg, encodingOrOffset, length);
|
|
};
|
|
SafeBuffer.alloc = function(size, fill, encoding) {
|
|
if (typeof size !== "number") {
|
|
throw new TypeError("Argument must be a number");
|
|
}
|
|
var buf = Buffer3(size);
|
|
if (fill !== void 0) {
|
|
if (typeof encoding === "string") {
|
|
buf.fill(fill, encoding);
|
|
} else {
|
|
buf.fill(fill);
|
|
}
|
|
} else {
|
|
buf.fill(0);
|
|
}
|
|
return buf;
|
|
};
|
|
SafeBuffer.allocUnsafe = function(size) {
|
|
if (typeof size !== "number") {
|
|
throw new TypeError("Argument must be a number");
|
|
}
|
|
return Buffer3(size);
|
|
};
|
|
SafeBuffer.allocUnsafeSlow = function(size) {
|
|
if (typeof size !== "number") {
|
|
throw new TypeError("Argument must be a number");
|
|
}
|
|
return buffer.SlowBuffer(size);
|
|
};
|
|
}
|
|
});
|
|
|
|
// node_modules/.pnpm/core-util-is@1.0.3/node_modules/core-util-is/lib/util.js
|
|
var require_util = __commonJS({
|
|
"node_modules/.pnpm/core-util-is@1.0.3/node_modules/core-util-is/lib/util.js"(exports2) {
|
|
function isArray2(arg) {
|
|
if (Array.isArray) {
|
|
return Array.isArray(arg);
|
|
}
|
|
return objectToString(arg) === "[object Array]";
|
|
}
|
|
exports2.isArray = isArray2;
|
|
function isBoolean(arg) {
|
|
return typeof arg === "boolean";
|
|
}
|
|
exports2.isBoolean = isBoolean;
|
|
function isNull(arg) {
|
|
return arg === null;
|
|
}
|
|
exports2.isNull = isNull;
|
|
function isNullOrUndefined(arg) {
|
|
return arg == null;
|
|
}
|
|
exports2.isNullOrUndefined = isNullOrUndefined;
|
|
function isNumber(arg) {
|
|
return typeof arg === "number";
|
|
}
|
|
exports2.isNumber = isNumber;
|
|
function isString(arg) {
|
|
return typeof arg === "string";
|
|
}
|
|
exports2.isString = isString;
|
|
function isSymbol(arg) {
|
|
return typeof arg === "symbol";
|
|
}
|
|
exports2.isSymbol = isSymbol;
|
|
function isUndefined(arg) {
|
|
return arg === void 0;
|
|
}
|
|
exports2.isUndefined = isUndefined;
|
|
function isRegExp(re) {
|
|
return objectToString(re) === "[object RegExp]";
|
|
}
|
|
exports2.isRegExp = isRegExp;
|
|
function isObject(arg) {
|
|
return typeof arg === "object" && arg !== null;
|
|
}
|
|
exports2.isObject = isObject;
|
|
function isDate(d) {
|
|
return objectToString(d) === "[object Date]";
|
|
}
|
|
exports2.isDate = isDate;
|
|
function isError(e) {
|
|
return objectToString(e) === "[object Error]" || e instanceof Error;
|
|
}
|
|
exports2.isError = isError;
|
|
function isFunction(arg) {
|
|
return typeof arg === "function";
|
|
}
|
|
exports2.isFunction = isFunction;
|
|
function isPrimitive(arg) {
|
|
return arg === null || typeof arg === "boolean" || typeof arg === "number" || typeof arg === "string" || typeof arg === "symbol" || // ES6 symbol
|
|
typeof arg === "undefined";
|
|
}
|
|
exports2.isPrimitive = isPrimitive;
|
|
exports2.isBuffer = require("buffer").Buffer.isBuffer;
|
|
function objectToString(o) {
|
|
return Object.prototype.toString.call(o);
|
|
}
|
|
}
|
|
});
|
|
|
|
// node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/internal/streams/BufferList.js
|
|
var require_BufferList = __commonJS({
|
|
"node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/internal/streams/BufferList.js"(exports2, module2) {
|
|
"use strict";
|
|
function _classCallCheck(instance, Constructor) {
|
|
if (!(instance instanceof Constructor)) {
|
|
throw new TypeError("Cannot call a class as a function");
|
|
}
|
|
}
|
|
var Buffer3 = require_safe_buffer2().Buffer;
|
|
var util = require("util");
|
|
function copyBuffer(src, target, offset) {
|
|
src.copy(target, offset);
|
|
}
|
|
module2.exports = (function() {
|
|
function BufferList() {
|
|
_classCallCheck(this, BufferList);
|
|
this.head = null;
|
|
this.tail = null;
|
|
this.length = 0;
|
|
}
|
|
BufferList.prototype.push = 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;
|
|
};
|
|
BufferList.prototype.unshift = function unshift(v) {
|
|
var entry = { data: v, next: this.head };
|
|
if (this.length === 0) this.tail = entry;
|
|
this.head = entry;
|
|
++this.length;
|
|
};
|
|
BufferList.prototype.shift = 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;
|
|
};
|
|
BufferList.prototype.clear = function clear() {
|
|
this.head = this.tail = null;
|
|
this.length = 0;
|
|
};
|
|
BufferList.prototype.join = 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;
|
|
};
|
|
BufferList.prototype.concat = function concat(n) {
|
|
if (this.length === 0) return Buffer3.alloc(0);
|
|
var ret = Buffer3.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;
|
|
};
|
|
return BufferList;
|
|
})();
|
|
if (util && util.inspect && util.inspect.custom) {
|
|
module2.exports.prototype[util.inspect.custom] = function() {
|
|
var obj = util.inspect({ length: this.length });
|
|
return this.constructor.name + " " + obj;
|
|
};
|
|
}
|
|
}
|
|
});
|
|
|
|
// node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/internal/streams/destroy.js
|
|
var require_destroy = __commonJS({
|
|
"node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/internal/streams/destroy.js"(exports2, module2) {
|
|
"use strict";
|
|
var pna2 = require_process_nextick_args();
|
|
function destroy(err, cb) {
|
|
var _this = this;
|
|
var readableDestroyed = this._readableState && this._readableState.destroyed;
|
|
var writableDestroyed = this._writableState && this._writableState.destroyed;
|
|
if (readableDestroyed || writableDestroyed) {
|
|
if (cb) {
|
|
cb(err);
|
|
} else if (err) {
|
|
if (!this._writableState) {
|
|
pna2.nextTick(emitErrorNT, this, err);
|
|
} else if (!this._writableState.errorEmitted) {
|
|
this._writableState.errorEmitted = true;
|
|
pna2.nextTick(emitErrorNT, this, err);
|
|
}
|
|
}
|
|
return this;
|
|
}
|
|
if (this._readableState) {
|
|
this._readableState.destroyed = true;
|
|
}
|
|
if (this._writableState) {
|
|
this._writableState.destroyed = true;
|
|
}
|
|
this._destroy(err || null, function(err2) {
|
|
if (!cb && err2) {
|
|
if (!_this._writableState) {
|
|
pna2.nextTick(emitErrorNT, _this, err2);
|
|
} else if (!_this._writableState.errorEmitted) {
|
|
_this._writableState.errorEmitted = true;
|
|
pna2.nextTick(emitErrorNT, _this, err2);
|
|
}
|
|
} else if (cb) {
|
|
cb(err2);
|
|
}
|
|
});
|
|
return this;
|
|
}
|
|
function undestroy() {
|
|
if (this._readableState) {
|
|
this._readableState.destroyed = false;
|
|
this._readableState.reading = false;
|
|
this._readableState.ended = false;
|
|
this._readableState.endEmitted = false;
|
|
}
|
|
if (this._writableState) {
|
|
this._writableState.destroyed = false;
|
|
this._writableState.ended = false;
|
|
this._writableState.ending = false;
|
|
this._writableState.finalCalled = false;
|
|
this._writableState.prefinished = false;
|
|
this._writableState.finished = false;
|
|
this._writableState.errorEmitted = false;
|
|
}
|
|
}
|
|
function emitErrorNT(self2, err) {
|
|
self2.emit("error", err);
|
|
}
|
|
module2.exports = {
|
|
destroy,
|
|
undestroy
|
|
};
|
|
}
|
|
});
|
|
|
|
// node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/_stream_writable.js
|
|
var require_stream_writable = __commonJS({
|
|
"node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/_stream_writable.js"(exports2, module2) {
|
|
"use strict";
|
|
var pna2 = require_process_nextick_args();
|
|
module2.exports = Writable;
|
|
function CorkedRequest(state) {
|
|
var _this = this;
|
|
this.next = null;
|
|
this.entry = null;
|
|
this.finish = function() {
|
|
onCorkedFinish(_this, state);
|
|
};
|
|
}
|
|
var asyncWrite = !process.browser && ["v0.10", "v0.9."].indexOf(process.version.slice(0, 5)) > -1 ? setImmediate : pna2.nextTick;
|
|
var Duplex;
|
|
Writable.WritableState = WritableState;
|
|
var util = Object.create(require_util());
|
|
util.inherits = require_inherits();
|
|
var internalUtil = {
|
|
deprecate: require_node()
|
|
};
|
|
var Stream = require_stream();
|
|
var Buffer3 = require_safe_buffer2().Buffer;
|
|
var OurUint8Array = (typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : typeof self !== "undefined" ? self : {}).Uint8Array || function() {
|
|
};
|
|
function _uint8ArrayToBuffer(chunk) {
|
|
return Buffer3.from(chunk);
|
|
}
|
|
function _isUint8Array(obj) {
|
|
return Buffer3.isBuffer(obj) || obj instanceof OurUint8Array;
|
|
}
|
|
var destroyImpl = require_destroy();
|
|
util.inherits(Writable, Stream);
|
|
function nop() {
|
|
}
|
|
function WritableState(options, stream2) {
|
|
Duplex = Duplex || require_stream_duplex();
|
|
options = options || {};
|
|
var isDuplex = stream2 instanceof Duplex;
|
|
this.objectMode = !!options.objectMode;
|
|
if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
|
|
var hwm = options.highWaterMark;
|
|
var writableHwm = options.writableHighWaterMark;
|
|
var defaultHwm = this.objectMode ? 16 : 16 * 1024;
|
|
if (hwm || hwm === 0) this.highWaterMark = hwm;
|
|
else if (isDuplex && (writableHwm || writableHwm === 0)) this.highWaterMark = writableHwm;
|
|
else this.highWaterMark = defaultHwm;
|
|
this.highWaterMark = Math.floor(this.highWaterMark);
|
|
this.finalCalled = false;
|
|
this.needDrain = false;
|
|
this.ending = false;
|
|
this.ended = false;
|
|
this.finished = false;
|
|
this.destroyed = false;
|
|
var noDecode = options.decodeStrings === false;
|
|
this.decodeStrings = !noDecode;
|
|
this.defaultEncoding = options.defaultEncoding || "utf8";
|
|
this.length = 0;
|
|
this.writing = false;
|
|
this.corked = 0;
|
|
this.sync = true;
|
|
this.bufferProcessing = false;
|
|
this.onwrite = function(er) {
|
|
onwrite(stream2, er);
|
|
};
|
|
this.writecb = null;
|
|
this.writelen = 0;
|
|
this.bufferedRequest = null;
|
|
this.lastBufferedRequest = null;
|
|
this.pendingcb = 0;
|
|
this.prefinished = false;
|
|
this.errorEmitted = false;
|
|
this.bufferedRequestCount = 0;
|
|
this.corkedRequestsFree = new CorkedRequest(this);
|
|
}
|
|
WritableState.prototype.getBuffer = function getBuffer() {
|
|
var current = this.bufferedRequest;
|
|
var out = [];
|
|
while (current) {
|
|
out.push(current);
|
|
current = current.next;
|
|
}
|
|
return out;
|
|
};
|
|
(function() {
|
|
try {
|
|
Object.defineProperty(WritableState.prototype, "buffer", {
|
|
get: internalUtil.deprecate(function() {
|
|
return this.getBuffer();
|
|
}, "_writableState.buffer is deprecated. Use _writableState.getBuffer instead.", "DEP0003")
|
|
});
|
|
} catch (_) {
|
|
}
|
|
})();
|
|
var realHasInstance;
|
|
if (typeof Symbol === "function" && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === "function") {
|
|
realHasInstance = Function.prototype[Symbol.hasInstance];
|
|
Object.defineProperty(Writable, Symbol.hasInstance, {
|
|
value: function(object) {
|
|
if (realHasInstance.call(this, object)) return true;
|
|
if (this !== Writable) return false;
|
|
return object && object._writableState instanceof WritableState;
|
|
}
|
|
});
|
|
} else {
|
|
realHasInstance = function(object) {
|
|
return object instanceof this;
|
|
};
|
|
}
|
|
function Writable(options) {
|
|
Duplex = Duplex || require_stream_duplex();
|
|
if (!realHasInstance.call(Writable, this) && !(this instanceof Duplex)) {
|
|
return new Writable(options);
|
|
}
|
|
this._writableState = new WritableState(options, this);
|
|
this.writable = true;
|
|
if (options) {
|
|
if (typeof options.write === "function") this._write = options.write;
|
|
if (typeof options.writev === "function") this._writev = options.writev;
|
|
if (typeof options.destroy === "function") this._destroy = options.destroy;
|
|
if (typeof options.final === "function") this._final = options.final;
|
|
}
|
|
Stream.call(this);
|
|
}
|
|
Writable.prototype.pipe = function() {
|
|
this.emit("error", new Error("Cannot pipe, not readable"));
|
|
};
|
|
function writeAfterEnd(stream2, cb) {
|
|
var er = new Error("write after end");
|
|
stream2.emit("error", er);
|
|
pna2.nextTick(cb, er);
|
|
}
|
|
function validChunk(stream2, state, chunk, cb) {
|
|
var valid = true;
|
|
var er = false;
|
|
if (chunk === null) {
|
|
er = new TypeError("May not write null values to stream");
|
|
} else if (typeof chunk !== "string" && chunk !== void 0 && !state.objectMode) {
|
|
er = new TypeError("Invalid non-string/buffer chunk");
|
|
}
|
|
if (er) {
|
|
stream2.emit("error", er);
|
|
pna2.nextTick(cb, er);
|
|
valid = false;
|
|
}
|
|
return valid;
|
|
}
|
|
Writable.prototype.write = function(chunk, encoding, cb) {
|
|
var state = this._writableState;
|
|
var ret = false;
|
|
var isBuf = !state.objectMode && _isUint8Array(chunk);
|
|
if (isBuf && !Buffer3.isBuffer(chunk)) {
|
|
chunk = _uint8ArrayToBuffer(chunk);
|
|
}
|
|
if (typeof encoding === "function") {
|
|
cb = encoding;
|
|
encoding = null;
|
|
}
|
|
if (isBuf) encoding = "buffer";
|
|
else if (!encoding) encoding = state.defaultEncoding;
|
|
if (typeof cb !== "function") cb = nop;
|
|
if (state.ended) writeAfterEnd(this, cb);
|
|
else if (isBuf || validChunk(this, state, chunk, cb)) {
|
|
state.pendingcb++;
|
|
ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
|
|
}
|
|
return ret;
|
|
};
|
|
Writable.prototype.cork = function() {
|
|
var state = this._writableState;
|
|
state.corked++;
|
|
};
|
|
Writable.prototype.uncork = function() {
|
|
var state = this._writableState;
|
|
if (state.corked) {
|
|
state.corked--;
|
|
if (!state.writing && !state.corked && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
|
|
}
|
|
};
|
|
Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
|
|
if (typeof encoding === "string") encoding = encoding.toLowerCase();
|
|
if (!(["hex", "utf8", "utf-8", "ascii", "binary", "base64", "ucs2", "ucs-2", "utf16le", "utf-16le", "raw"].indexOf((encoding + "").toLowerCase()) > -1)) throw new TypeError("Unknown encoding: " + encoding);
|
|
this._writableState.defaultEncoding = encoding;
|
|
return this;
|
|
};
|
|
function decodeChunk(state, chunk, encoding) {
|
|
if (!state.objectMode && state.decodeStrings !== false && typeof chunk === "string") {
|
|
chunk = Buffer3.from(chunk, encoding);
|
|
}
|
|
return chunk;
|
|
}
|
|
Object.defineProperty(Writable.prototype, "writableHighWaterMark", {
|
|
// making it explicit this property is not enumerable
|
|
// because otherwise some prototype manipulation in
|
|
// userland will fail
|
|
enumerable: false,
|
|
get: function() {
|
|
return this._writableState.highWaterMark;
|
|
}
|
|
});
|
|
function writeOrBuffer(stream2, state, isBuf, chunk, encoding, cb) {
|
|
if (!isBuf) {
|
|
var newChunk = decodeChunk(state, chunk, encoding);
|
|
if (chunk !== newChunk) {
|
|
isBuf = true;
|
|
encoding = "buffer";
|
|
chunk = newChunk;
|
|
}
|
|
}
|
|
var len = state.objectMode ? 1 : chunk.length;
|
|
state.length += len;
|
|
var ret = state.length < state.highWaterMark;
|
|
if (!ret) state.needDrain = true;
|
|
if (state.writing || state.corked) {
|
|
var last = state.lastBufferedRequest;
|
|
state.lastBufferedRequest = {
|
|
chunk,
|
|
encoding,
|
|
isBuf,
|
|
callback: cb,
|
|
next: null
|
|
};
|
|
if (last) {
|
|
last.next = state.lastBufferedRequest;
|
|
} else {
|
|
state.bufferedRequest = state.lastBufferedRequest;
|
|
}
|
|
state.bufferedRequestCount += 1;
|
|
} else {
|
|
doWrite(stream2, state, false, len, chunk, encoding, cb);
|
|
}
|
|
return ret;
|
|
}
|
|
function doWrite(stream2, state, writev, len, chunk, encoding, cb) {
|
|
state.writelen = len;
|
|
state.writecb = cb;
|
|
state.writing = true;
|
|
state.sync = true;
|
|
if (writev) stream2._writev(chunk, state.onwrite);
|
|
else stream2._write(chunk, encoding, state.onwrite);
|
|
state.sync = false;
|
|
}
|
|
function onwriteError(stream2, state, sync, er, cb) {
|
|
--state.pendingcb;
|
|
if (sync) {
|
|
pna2.nextTick(cb, er);
|
|
pna2.nextTick(finishMaybe, stream2, state);
|
|
stream2._writableState.errorEmitted = true;
|
|
stream2.emit("error", er);
|
|
} else {
|
|
cb(er);
|
|
stream2._writableState.errorEmitted = true;
|
|
stream2.emit("error", er);
|
|
finishMaybe(stream2, state);
|
|
}
|
|
}
|
|
function onwriteStateUpdate(state) {
|
|
state.writing = false;
|
|
state.writecb = null;
|
|
state.length -= state.writelen;
|
|
state.writelen = 0;
|
|
}
|
|
function onwrite(stream2, er) {
|
|
var state = stream2._writableState;
|
|
var sync = state.sync;
|
|
var cb = state.writecb;
|
|
onwriteStateUpdate(state);
|
|
if (er) onwriteError(stream2, state, sync, er, cb);
|
|
else {
|
|
var finished = needFinish(state);
|
|
if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
|
|
clearBuffer(stream2, state);
|
|
}
|
|
if (sync) {
|
|
asyncWrite(afterWrite, stream2, state, finished, cb);
|
|
} else {
|
|
afterWrite(stream2, state, finished, cb);
|
|
}
|
|
}
|
|
}
|
|
function afterWrite(stream2, state, finished, cb) {
|
|
if (!finished) onwriteDrain(stream2, state);
|
|
state.pendingcb--;
|
|
cb();
|
|
finishMaybe(stream2, state);
|
|
}
|
|
function onwriteDrain(stream2, state) {
|
|
if (state.length === 0 && state.needDrain) {
|
|
state.needDrain = false;
|
|
stream2.emit("drain");
|
|
}
|
|
}
|
|
function clearBuffer(stream2, state) {
|
|
state.bufferProcessing = true;
|
|
var entry = state.bufferedRequest;
|
|
if (stream2._writev && entry && entry.next) {
|
|
var l = state.bufferedRequestCount;
|
|
var buffer = new Array(l);
|
|
var holder = state.corkedRequestsFree;
|
|
holder.entry = entry;
|
|
var count = 0;
|
|
var allBuffers = true;
|
|
while (entry) {
|
|
buffer[count] = entry;
|
|
if (!entry.isBuf) allBuffers = false;
|
|
entry = entry.next;
|
|
count += 1;
|
|
}
|
|
buffer.allBuffers = allBuffers;
|
|
doWrite(stream2, state, true, state.length, buffer, "", holder.finish);
|
|
state.pendingcb++;
|
|
state.lastBufferedRequest = null;
|
|
if (holder.next) {
|
|
state.corkedRequestsFree = holder.next;
|
|
holder.next = null;
|
|
} else {
|
|
state.corkedRequestsFree = new CorkedRequest(state);
|
|
}
|
|
state.bufferedRequestCount = 0;
|
|
} else {
|
|
while (entry) {
|
|
var chunk = entry.chunk;
|
|
var encoding = entry.encoding;
|
|
var cb = entry.callback;
|
|
var len = state.objectMode ? 1 : chunk.length;
|
|
doWrite(stream2, state, false, len, chunk, encoding, cb);
|
|
entry = entry.next;
|
|
state.bufferedRequestCount--;
|
|
if (state.writing) {
|
|
break;
|
|
}
|
|
}
|
|
if (entry === null) state.lastBufferedRequest = null;
|
|
}
|
|
state.bufferedRequest = entry;
|
|
state.bufferProcessing = false;
|
|
}
|
|
Writable.prototype._write = function(chunk, encoding, cb) {
|
|
cb(new Error("_write() is not implemented"));
|
|
};
|
|
Writable.prototype._writev = null;
|
|
Writable.prototype.end = function(chunk, encoding, cb) {
|
|
var state = this._writableState;
|
|
if (typeof chunk === "function") {
|
|
cb = chunk;
|
|
chunk = null;
|
|
encoding = null;
|
|
} else if (typeof encoding === "function") {
|
|
cb = encoding;
|
|
encoding = null;
|
|
}
|
|
if (chunk !== null && chunk !== void 0) this.write(chunk, encoding);
|
|
if (state.corked) {
|
|
state.corked = 1;
|
|
this.uncork();
|
|
}
|
|
if (!state.ending) endWritable(this, state, cb);
|
|
};
|
|
function needFinish(state) {
|
|
return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
|
|
}
|
|
function callFinal(stream2, state) {
|
|
stream2._final(function(err) {
|
|
state.pendingcb--;
|
|
if (err) {
|
|
stream2.emit("error", err);
|
|
}
|
|
state.prefinished = true;
|
|
stream2.emit("prefinish");
|
|
finishMaybe(stream2, state);
|
|
});
|
|
}
|
|
function prefinish(stream2, state) {
|
|
if (!state.prefinished && !state.finalCalled) {
|
|
if (typeof stream2._final === "function") {
|
|
state.pendingcb++;
|
|
state.finalCalled = true;
|
|
pna2.nextTick(callFinal, stream2, state);
|
|
} else {
|
|
state.prefinished = true;
|
|
stream2.emit("prefinish");
|
|
}
|
|
}
|
|
}
|
|
function finishMaybe(stream2, state) {
|
|
var need = needFinish(state);
|
|
if (need) {
|
|
prefinish(stream2, state);
|
|
if (state.pendingcb === 0) {
|
|
state.finished = true;
|
|
stream2.emit("finish");
|
|
}
|
|
}
|
|
return need;
|
|
}
|
|
function endWritable(stream2, state, cb) {
|
|
state.ending = true;
|
|
finishMaybe(stream2, state);
|
|
if (cb) {
|
|
if (state.finished) pna2.nextTick(cb);
|
|
else stream2.once("finish", cb);
|
|
}
|
|
state.ended = true;
|
|
stream2.writable = false;
|
|
}
|
|
function onCorkedFinish(corkReq, state, err) {
|
|
var entry = corkReq.entry;
|
|
corkReq.entry = null;
|
|
while (entry) {
|
|
var cb = entry.callback;
|
|
state.pendingcb--;
|
|
cb(err);
|
|
entry = entry.next;
|
|
}
|
|
state.corkedRequestsFree.next = corkReq;
|
|
}
|
|
Object.defineProperty(Writable.prototype, "destroyed", {
|
|
get: function() {
|
|
if (this._writableState === void 0) {
|
|
return false;
|
|
}
|
|
return this._writableState.destroyed;
|
|
},
|
|
set: function(value) {
|
|
if (!this._writableState) {
|
|
return;
|
|
}
|
|
this._writableState.destroyed = value;
|
|
}
|
|
});
|
|
Writable.prototype.destroy = destroyImpl.destroy;
|
|
Writable.prototype._undestroy = destroyImpl.undestroy;
|
|
Writable.prototype._destroy = function(err, cb) {
|
|
this.end();
|
|
cb(err);
|
|
};
|
|
}
|
|
});
|
|
|
|
// node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/_stream_duplex.js
|
|
var require_stream_duplex = __commonJS({
|
|
"node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/_stream_duplex.js"(exports2, module2) {
|
|
"use strict";
|
|
var pna2 = require_process_nextick_args();
|
|
var objectKeys = Object.keys || function(obj) {
|
|
var keys2 = [];
|
|
for (var key in obj) {
|
|
keys2.push(key);
|
|
}
|
|
return keys2;
|
|
};
|
|
module2.exports = Duplex;
|
|
var util = Object.create(require_util());
|
|
util.inherits = require_inherits();
|
|
var Readable = require_stream_readable();
|
|
var Writable = require_stream_writable();
|
|
util.inherits(Duplex, Readable);
|
|
{
|
|
keys = objectKeys(Writable.prototype);
|
|
for (v = 0; v < keys.length; v++) {
|
|
method = keys[v];
|
|
if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
|
|
}
|
|
}
|
|
var keys;
|
|
var method;
|
|
var v;
|
|
function Duplex(options) {
|
|
if (!(this instanceof Duplex)) return new Duplex(options);
|
|
Readable.call(this, options);
|
|
Writable.call(this, options);
|
|
if (options && options.readable === false) this.readable = false;
|
|
if (options && options.writable === false) this.writable = false;
|
|
this.allowHalfOpen = true;
|
|
if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
|
|
this.once("end", onend);
|
|
}
|
|
Object.defineProperty(Duplex.prototype, "writableHighWaterMark", {
|
|
// making it explicit this property is not enumerable
|
|
// because otherwise some prototype manipulation in
|
|
// userland will fail
|
|
enumerable: false,
|
|
get: function() {
|
|
return this._writableState.highWaterMark;
|
|
}
|
|
});
|
|
function onend() {
|
|
if (this.allowHalfOpen || this._writableState.ended) return;
|
|
pna2.nextTick(onEndNT, this);
|
|
}
|
|
function onEndNT(self2) {
|
|
self2.end();
|
|
}
|
|
Object.defineProperty(Duplex.prototype, "destroyed", {
|
|
get: function() {
|
|
if (this._readableState === void 0 || this._writableState === void 0) {
|
|
return false;
|
|
}
|
|
return this._readableState.destroyed && this._writableState.destroyed;
|
|
},
|
|
set: function(value) {
|
|
if (this._readableState === void 0 || this._writableState === void 0) {
|
|
return;
|
|
}
|
|
this._readableState.destroyed = value;
|
|
this._writableState.destroyed = value;
|
|
}
|
|
});
|
|
Duplex.prototype._destroy = function(err, cb) {
|
|
this.push(null);
|
|
this.end();
|
|
pna2.nextTick(cb, err);
|
|
};
|
|
}
|
|
});
|
|
|
|
// node_modules/.pnpm/string_decoder@1.1.1/node_modules/string_decoder/lib/string_decoder.js
|
|
var require_string_decoder = __commonJS({
|
|
"node_modules/.pnpm/string_decoder@1.1.1/node_modules/string_decoder/lib/string_decoder.js"(exports2) {
|
|
"use strict";
|
|
var Buffer3 = require_safe_buffer2().Buffer;
|
|
var isEncoding = Buffer3.isEncoding || function(encoding) {
|
|
encoding = "" + encoding;
|
|
switch (encoding && encoding.toLowerCase()) {
|
|
case "hex":
|
|
case "utf8":
|
|
case "utf-8":
|
|
case "ascii":
|
|
case "binary":
|
|
case "base64":
|
|
case "ucs2":
|
|
case "ucs-2":
|
|
case "utf16le":
|
|
case "utf-16le":
|
|
case "raw":
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
};
|
|
function _normalizeEncoding(enc) {
|
|
if (!enc) return "utf8";
|
|
var retried;
|
|
while (true) {
|
|
switch (enc) {
|
|
case "utf8":
|
|
case "utf-8":
|
|
return "utf8";
|
|
case "ucs2":
|
|
case "ucs-2":
|
|
case "utf16le":
|
|
case "utf-16le":
|
|
return "utf16le";
|
|
case "latin1":
|
|
case "binary":
|
|
return "latin1";
|
|
case "base64":
|
|
case "ascii":
|
|
case "hex":
|
|
return enc;
|
|
default:
|
|
if (retried) return;
|
|
enc = ("" + enc).toLowerCase();
|
|
retried = true;
|
|
}
|
|
}
|
|
}
|
|
function normalizeEncoding(enc) {
|
|
var nenc = _normalizeEncoding(enc);
|
|
if (typeof nenc !== "string" && (Buffer3.isEncoding === isEncoding || !isEncoding(enc))) throw new Error("Unknown encoding: " + enc);
|
|
return nenc || enc;
|
|
}
|
|
exports2.StringDecoder = StringDecoder;
|
|
function StringDecoder(encoding) {
|
|
this.encoding = normalizeEncoding(encoding);
|
|
var nb;
|
|
switch (this.encoding) {
|
|
case "utf16le":
|
|
this.text = utf16Text;
|
|
this.end = utf16End;
|
|
nb = 4;
|
|
break;
|
|
case "utf8":
|
|
this.fillLast = utf8FillLast;
|
|
nb = 4;
|
|
break;
|
|
case "base64":
|
|
this.text = base64Text;
|
|
this.end = base64End;
|
|
nb = 3;
|
|
break;
|
|
default:
|
|
this.write = simpleWrite;
|
|
this.end = simpleEnd;
|
|
return;
|
|
}
|
|
this.lastNeed = 0;
|
|
this.lastTotal = 0;
|
|
this.lastChar = Buffer3.allocUnsafe(nb);
|
|
}
|
|
StringDecoder.prototype.write = function(buf) {
|
|
if (buf.length === 0) return "";
|
|
var r;
|
|
var i;
|
|
if (this.lastNeed) {
|
|
r = this.fillLast(buf);
|
|
if (r === void 0) return "";
|
|
i = this.lastNeed;
|
|
this.lastNeed = 0;
|
|
} else {
|
|
i = 0;
|
|
}
|
|
if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
|
|
return r || "";
|
|
};
|
|
StringDecoder.prototype.end = utf8End;
|
|
StringDecoder.prototype.text = utf8Text;
|
|
StringDecoder.prototype.fillLast = function(buf) {
|
|
if (this.lastNeed <= buf.length) {
|
|
buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
|
|
return this.lastChar.toString(this.encoding, 0, this.lastTotal);
|
|
}
|
|
buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
|
|
this.lastNeed -= buf.length;
|
|
};
|
|
function utf8CheckByte(byte) {
|
|
if (byte <= 127) return 0;
|
|
else if (byte >> 5 === 6) return 2;
|
|
else if (byte >> 4 === 14) return 3;
|
|
else if (byte >> 3 === 30) return 4;
|
|
return byte >> 6 === 2 ? -1 : -2;
|
|
}
|
|
function utf8CheckIncomplete(self2, buf, i) {
|
|
var j = buf.length - 1;
|
|
if (j < i) return 0;
|
|
var nb = utf8CheckByte(buf[j]);
|
|
if (nb >= 0) {
|
|
if (nb > 0) self2.lastNeed = nb - 1;
|
|
return nb;
|
|
}
|
|
if (--j < i || nb === -2) return 0;
|
|
nb = utf8CheckByte(buf[j]);
|
|
if (nb >= 0) {
|
|
if (nb > 0) self2.lastNeed = nb - 2;
|
|
return nb;
|
|
}
|
|
if (--j < i || nb === -2) return 0;
|
|
nb = utf8CheckByte(buf[j]);
|
|
if (nb >= 0) {
|
|
if (nb > 0) {
|
|
if (nb === 2) nb = 0;
|
|
else self2.lastNeed = nb - 3;
|
|
}
|
|
return nb;
|
|
}
|
|
return 0;
|
|
}
|
|
function utf8CheckExtraBytes(self2, buf, p) {
|
|
if ((buf[0] & 192) !== 128) {
|
|
self2.lastNeed = 0;
|
|
return "\uFFFD";
|
|
}
|
|
if (self2.lastNeed > 1 && buf.length > 1) {
|
|
if ((buf[1] & 192) !== 128) {
|
|
self2.lastNeed = 1;
|
|
return "\uFFFD";
|
|
}
|
|
if (self2.lastNeed > 2 && buf.length > 2) {
|
|
if ((buf[2] & 192) !== 128) {
|
|
self2.lastNeed = 2;
|
|
return "\uFFFD";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
function utf8FillLast(buf) {
|
|
var p = this.lastTotal - this.lastNeed;
|
|
var r = utf8CheckExtraBytes(this, buf, p);
|
|
if (r !== void 0) return r;
|
|
if (this.lastNeed <= buf.length) {
|
|
buf.copy(this.lastChar, p, 0, this.lastNeed);
|
|
return this.lastChar.toString(this.encoding, 0, this.lastTotal);
|
|
}
|
|
buf.copy(this.lastChar, p, 0, buf.length);
|
|
this.lastNeed -= buf.length;
|
|
}
|
|
function utf8Text(buf, i) {
|
|
var total = utf8CheckIncomplete(this, buf, i);
|
|
if (!this.lastNeed) return buf.toString("utf8", i);
|
|
this.lastTotal = total;
|
|
var end = buf.length - (total - this.lastNeed);
|
|
buf.copy(this.lastChar, 0, end);
|
|
return buf.toString("utf8", i, end);
|
|
}
|
|
function utf8End(buf) {
|
|
var r = buf && buf.length ? this.write(buf) : "";
|
|
if (this.lastNeed) return r + "\uFFFD";
|
|
return r;
|
|
}
|
|
function utf16Text(buf, i) {
|
|
if ((buf.length - i) % 2 === 0) {
|
|
var r = buf.toString("utf16le", i);
|
|
if (r) {
|
|
var c = r.charCodeAt(r.length - 1);
|
|
if (c >= 55296 && c <= 56319) {
|
|
this.lastNeed = 2;
|
|
this.lastTotal = 4;
|
|
this.lastChar[0] = buf[buf.length - 2];
|
|
this.lastChar[1] = buf[buf.length - 1];
|
|
return r.slice(0, -1);
|
|
}
|
|
}
|
|
return r;
|
|
}
|
|
this.lastNeed = 1;
|
|
this.lastTotal = 2;
|
|
this.lastChar[0] = buf[buf.length - 1];
|
|
return buf.toString("utf16le", i, buf.length - 1);
|
|
}
|
|
function utf16End(buf) {
|
|
var r = buf && buf.length ? this.write(buf) : "";
|
|
if (this.lastNeed) {
|
|
var end = this.lastTotal - this.lastNeed;
|
|
return r + this.lastChar.toString("utf16le", 0, end);
|
|
}
|
|
return r;
|
|
}
|
|
function base64Text(buf, i) {
|
|
var n = (buf.length - i) % 3;
|
|
if (n === 0) return buf.toString("base64", i);
|
|
this.lastNeed = 3 - n;
|
|
this.lastTotal = 3;
|
|
if (n === 1) {
|
|
this.lastChar[0] = buf[buf.length - 1];
|
|
} else {
|
|
this.lastChar[0] = buf[buf.length - 2];
|
|
this.lastChar[1] = buf[buf.length - 1];
|
|
}
|
|
return buf.toString("base64", i, buf.length - n);
|
|
}
|
|
function base64End(buf) {
|
|
var r = buf && buf.length ? this.write(buf) : "";
|
|
if (this.lastNeed) return r + this.lastChar.toString("base64", 0, 3 - this.lastNeed);
|
|
return r;
|
|
}
|
|
function simpleWrite(buf) {
|
|
return buf.toString(this.encoding);
|
|
}
|
|
function simpleEnd(buf) {
|
|
return buf && buf.length ? this.write(buf) : "";
|
|
}
|
|
}
|
|
});
|
|
|
|
// node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/_stream_readable.js
|
|
var require_stream_readable = __commonJS({
|
|
"node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/_stream_readable.js"(exports2, module2) {
|
|
"use strict";
|
|
var pna2 = require_process_nextick_args();
|
|
module2.exports = Readable;
|
|
var isArray2 = require_isarray();
|
|
var Duplex;
|
|
Readable.ReadableState = ReadableState;
|
|
var EE = require("events").EventEmitter;
|
|
var EElistenerCount = function(emitter, type) {
|
|
return emitter.listeners(type).length;
|
|
};
|
|
var Stream = require_stream();
|
|
var Buffer3 = require_safe_buffer2().Buffer;
|
|
var OurUint8Array = (typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : typeof self !== "undefined" ? self : {}).Uint8Array || function() {
|
|
};
|
|
function _uint8ArrayToBuffer(chunk) {
|
|
return Buffer3.from(chunk);
|
|
}
|
|
function _isUint8Array(obj) {
|
|
return Buffer3.isBuffer(obj) || obj instanceof OurUint8Array;
|
|
}
|
|
var util = Object.create(require_util());
|
|
util.inherits = require_inherits();
|
|
var debugUtil = require("util");
|
|
var debug = void 0;
|
|
if (debugUtil && debugUtil.debuglog) {
|
|
debug = debugUtil.debuglog("stream");
|
|
} else {
|
|
debug = function() {
|
|
};
|
|
}
|
|
var BufferList = require_BufferList();
|
|
var destroyImpl = require_destroy();
|
|
var StringDecoder;
|
|
util.inherits(Readable, Stream);
|
|
var kProxyEvents = ["error", "close", "destroy", "pause", "resume"];
|
|
function prependListener(emitter, event, fn) {
|
|
if (typeof emitter.prependListener === "function") return emitter.prependListener(event, fn);
|
|
if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);
|
|
else if (isArray2(emitter._events[event])) emitter._events[event].unshift(fn);
|
|
else emitter._events[event] = [fn, emitter._events[event]];
|
|
}
|
|
function ReadableState(options, stream2) {
|
|
Duplex = Duplex || require_stream_duplex();
|
|
options = options || {};
|
|
var isDuplex = stream2 instanceof Duplex;
|
|
this.objectMode = !!options.objectMode;
|
|
if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode;
|
|
var hwm = options.highWaterMark;
|
|
var readableHwm = options.readableHighWaterMark;
|
|
var defaultHwm = this.objectMode ? 16 : 16 * 1024;
|
|
if (hwm || hwm === 0) this.highWaterMark = hwm;
|
|
else if (isDuplex && (readableHwm || readableHwm === 0)) this.highWaterMark = readableHwm;
|
|
else this.highWaterMark = defaultHwm;
|
|
this.highWaterMark = Math.floor(this.highWaterMark);
|
|
this.buffer = new BufferList();
|
|
this.length = 0;
|
|
this.pipes = null;
|
|
this.pipesCount = 0;
|
|
this.flowing = null;
|
|
this.ended = false;
|
|
this.endEmitted = false;
|
|
this.reading = false;
|
|
this.sync = true;
|
|
this.needReadable = false;
|
|
this.emittedReadable = false;
|
|
this.readableListening = false;
|
|
this.resumeScheduled = false;
|
|
this.destroyed = false;
|
|
this.defaultEncoding = options.defaultEncoding || "utf8";
|
|
this.awaitDrain = 0;
|
|
this.readingMore = false;
|
|
this.decoder = null;
|
|
this.encoding = null;
|
|
if (options.encoding) {
|
|
if (!StringDecoder) StringDecoder = require_string_decoder().StringDecoder;
|
|
this.decoder = new StringDecoder(options.encoding);
|
|
this.encoding = options.encoding;
|
|
}
|
|
}
|
|
function Readable(options) {
|
|
Duplex = Duplex || require_stream_duplex();
|
|
if (!(this instanceof Readable)) return new Readable(options);
|
|
this._readableState = new ReadableState(options, this);
|
|
this.readable = true;
|
|
if (options) {
|
|
if (typeof options.read === "function") this._read = options.read;
|
|
if (typeof options.destroy === "function") this._destroy = options.destroy;
|
|
}
|
|
Stream.call(this);
|
|
}
|
|
Object.defineProperty(Readable.prototype, "destroyed", {
|
|
get: function() {
|
|
if (this._readableState === void 0) {
|
|
return false;
|
|
}
|
|
return this._readableState.destroyed;
|
|
},
|
|
set: function(value) {
|
|
if (!this._readableState) {
|
|
return;
|
|
}
|
|
this._readableState.destroyed = value;
|
|
}
|
|
});
|
|
Readable.prototype.destroy = destroyImpl.destroy;
|
|
Readable.prototype._undestroy = destroyImpl.undestroy;
|
|
Readable.prototype._destroy = function(err, cb) {
|
|
this.push(null);
|
|
cb(err);
|
|
};
|
|
Readable.prototype.push = function(chunk, encoding) {
|
|
var state = this._readableState;
|
|
var skipChunkCheck;
|
|
if (!state.objectMode) {
|
|
if (typeof chunk === "string") {
|
|
encoding = encoding || state.defaultEncoding;
|
|
if (encoding !== state.encoding) {
|
|
chunk = Buffer3.from(chunk, encoding);
|
|
encoding = "";
|
|
}
|
|
skipChunkCheck = true;
|
|
}
|
|
} else {
|
|
skipChunkCheck = true;
|
|
}
|
|
return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
|
|
};
|
|
Readable.prototype.unshift = function(chunk) {
|
|
return readableAddChunk(this, chunk, null, true, false);
|
|
};
|
|
function readableAddChunk(stream2, chunk, encoding, addToFront, skipChunkCheck) {
|
|
var state = stream2._readableState;
|
|
if (chunk === null) {
|
|
state.reading = false;
|
|
onEofChunk(stream2, state);
|
|
} else {
|
|
var er;
|
|
if (!skipChunkCheck) er = chunkInvalid(state, chunk);
|
|
if (er) {
|
|
stream2.emit("error", er);
|
|
} else if (state.objectMode || chunk && chunk.length > 0) {
|
|
if (typeof chunk !== "string" && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer3.prototype) {
|
|
chunk = _uint8ArrayToBuffer(chunk);
|
|
}
|
|
if (addToFront) {
|
|
if (state.endEmitted) stream2.emit("error", new Error("stream.unshift() after end event"));
|
|
else addChunk(stream2, state, chunk, true);
|
|
} else if (state.ended) {
|
|
stream2.emit("error", new Error("stream.push() after EOF"));
|
|
} else {
|
|
state.reading = false;
|
|
if (state.decoder && !encoding) {
|
|
chunk = state.decoder.write(chunk);
|
|
if (state.objectMode || chunk.length !== 0) addChunk(stream2, state, chunk, false);
|
|
else maybeReadMore(stream2, state);
|
|
} else {
|
|
addChunk(stream2, state, chunk, false);
|
|
}
|
|
}
|
|
} else if (!addToFront) {
|
|
state.reading = false;
|
|
}
|
|
}
|
|
return needMoreData(state);
|
|
}
|
|
function addChunk(stream2, state, chunk, addToFront) {
|
|
if (state.flowing && state.length === 0 && !state.sync) {
|
|
stream2.emit("data", chunk);
|
|
stream2.read(0);
|
|
} else {
|
|
state.length += state.objectMode ? 1 : chunk.length;
|
|
if (addToFront) state.buffer.unshift(chunk);
|
|
else state.buffer.push(chunk);
|
|
if (state.needReadable) emitReadable(stream2);
|
|
}
|
|
maybeReadMore(stream2, state);
|
|
}
|
|
function chunkInvalid(state, chunk) {
|
|
var er;
|
|
if (!_isUint8Array(chunk) && typeof chunk !== "string" && chunk !== void 0 && !state.objectMode) {
|
|
er = new TypeError("Invalid non-string/buffer chunk");
|
|
}
|
|
return er;
|
|
}
|
|
function needMoreData(state) {
|
|
return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0);
|
|
}
|
|
Readable.prototype.isPaused = function() {
|
|
return this._readableState.flowing === false;
|
|
};
|
|
Readable.prototype.setEncoding = function(enc) {
|
|
if (!StringDecoder) StringDecoder = require_string_decoder().StringDecoder;
|
|
this._readableState.decoder = new StringDecoder(enc);
|
|
this._readableState.encoding = enc;
|
|
return this;
|
|
};
|
|
var MAX_HWM = 8388608;
|
|
function computeNewHighWaterMark(n) {
|
|
if (n >= MAX_HWM) {
|
|
n = MAX_HWM;
|
|
} else {
|
|
n--;
|
|
n |= n >>> 1;
|
|
n |= n >>> 2;
|
|
n |= n >>> 4;
|
|
n |= n >>> 8;
|
|
n |= n >>> 16;
|
|
n++;
|
|
}
|
|
return n;
|
|
}
|
|
function howMuchToRead(n, state) {
|
|
if (n <= 0 || state.length === 0 && state.ended) return 0;
|
|
if (state.objectMode) return 1;
|
|
if (n !== n) {
|
|
if (state.flowing && state.length) return state.buffer.head.data.length;
|
|
else return state.length;
|
|
}
|
|
if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
|
|
if (n <= state.length) return n;
|
|
if (!state.ended) {
|
|
state.needReadable = true;
|
|
return 0;
|
|
}
|
|
return state.length;
|
|
}
|
|
Readable.prototype.read = function(n) {
|
|
debug("read", n);
|
|
n = parseInt(n, 10);
|
|
var state = this._readableState;
|
|
var nOrig = n;
|
|
if (n !== 0) state.emittedReadable = false;
|
|
if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) {
|
|
debug("read: emitReadable", state.length, state.ended);
|
|
if (state.length === 0 && state.ended) endReadable(this);
|
|
else emitReadable(this);
|
|
return null;
|
|
}
|
|
n = howMuchToRead(n, state);
|
|
if (n === 0 && state.ended) {
|
|
if (state.length === 0) endReadable(this);
|
|
return null;
|
|
}
|
|
var doRead = state.needReadable;
|
|
debug("need readable", doRead);
|
|
if (state.length === 0 || state.length - n < state.highWaterMark) {
|
|
doRead = true;
|
|
debug("length less than watermark", doRead);
|
|
}
|
|
if (state.ended || state.reading) {
|
|
doRead = false;
|
|
debug("reading or ended", doRead);
|
|
} else if (doRead) {
|
|
debug("do read");
|
|
state.reading = true;
|
|
state.sync = true;
|
|
if (state.length === 0) state.needReadable = true;
|
|
this._read(state.highWaterMark);
|
|
state.sync = false;
|
|
if (!state.reading) n = howMuchToRead(nOrig, state);
|
|
}
|
|
var ret;
|
|
if (n > 0) ret = fromList(n, state);
|
|
else ret = null;
|
|
if (ret === null) {
|
|
state.needReadable = true;
|
|
n = 0;
|
|
} else {
|
|
state.length -= n;
|
|
}
|
|
if (state.length === 0) {
|
|
if (!state.ended) state.needReadable = true;
|
|
if (nOrig !== n && state.ended) endReadable(this);
|
|
}
|
|
if (ret !== null) this.emit("data", ret);
|
|
return ret;
|
|
};
|
|
function onEofChunk(stream2, state) {
|
|
if (state.ended) return;
|
|
if (state.decoder) {
|
|
var chunk = state.decoder.end();
|
|
if (chunk && chunk.length) {
|
|
state.buffer.push(chunk);
|
|
state.length += state.objectMode ? 1 : chunk.length;
|
|
}
|
|
}
|
|
state.ended = true;
|
|
emitReadable(stream2);
|
|
}
|
|
function emitReadable(stream2) {
|
|
var state = stream2._readableState;
|
|
state.needReadable = false;
|
|
if (!state.emittedReadable) {
|
|
debug("emitReadable", state.flowing);
|
|
state.emittedReadable = true;
|
|
if (state.sync) pna2.nextTick(emitReadable_, stream2);
|
|
else emitReadable_(stream2);
|
|
}
|
|
}
|
|
function emitReadable_(stream2) {
|
|
debug("emit readable");
|
|
stream2.emit("readable");
|
|
flow(stream2);
|
|
}
|
|
function maybeReadMore(stream2, state) {
|
|
if (!state.readingMore) {
|
|
state.readingMore = true;
|
|
pna2.nextTick(maybeReadMore_, stream2, state);
|
|
}
|
|
}
|
|
function maybeReadMore_(stream2, state) {
|
|
var len = state.length;
|
|
while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
|
|
debug("maybeReadMore read 0");
|
|
stream2.read(0);
|
|
if (len === state.length)
|
|
break;
|
|
else len = state.length;
|
|
}
|
|
state.readingMore = false;
|
|
}
|
|
Readable.prototype._read = function(n) {
|
|
this.emit("error", new Error("_read() is not implemented"));
|
|
};
|
|
Readable.prototype.pipe = function(dest, pipeOpts) {
|
|
var src = this;
|
|
var state = this._readableState;
|
|
switch (state.pipesCount) {
|
|
case 0:
|
|
state.pipes = dest;
|
|
break;
|
|
case 1:
|
|
state.pipes = [state.pipes, dest];
|
|
break;
|
|
default:
|
|
state.pipes.push(dest);
|
|
break;
|
|
}
|
|
state.pipesCount += 1;
|
|
debug("pipe count=%d opts=%j", state.pipesCount, pipeOpts);
|
|
var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr;
|
|
var endFn = doEnd ? onend : unpipe;
|
|
if (state.endEmitted) pna2.nextTick(endFn);
|
|
else src.once("end", endFn);
|
|
dest.on("unpipe", onunpipe);
|
|
function onunpipe(readable, unpipeInfo) {
|
|
debug("onunpipe");
|
|
if (readable === src) {
|
|
if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
|
|
unpipeInfo.hasUnpiped = true;
|
|
cleanup();
|
|
}
|
|
}
|
|
}
|
|
function onend() {
|
|
debug("onend");
|
|
dest.end();
|
|
}
|
|
var ondrain = pipeOnDrain(src);
|
|
dest.on("drain", ondrain);
|
|
var cleanedUp = false;
|
|
function cleanup() {
|
|
debug("cleanup");
|
|
dest.removeListener("close", onclose);
|
|
dest.removeListener("finish", onfinish);
|
|
dest.removeListener("drain", ondrain);
|
|
dest.removeListener("error", onerror);
|
|
dest.removeListener("unpipe", onunpipe);
|
|
src.removeListener("end", onend);
|
|
src.removeListener("end", unpipe);
|
|
src.removeListener("data", ondata);
|
|
cleanedUp = true;
|
|
if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
|
|
}
|
|
var increasedAwaitDrain = false;
|
|
src.on("data", ondata);
|
|
function ondata(chunk) {
|
|
debug("ondata");
|
|
increasedAwaitDrain = false;
|
|
var ret = dest.write(chunk);
|
|
if (false === ret && !increasedAwaitDrain) {
|
|
if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
|
|
debug("false write response, pause", state.awaitDrain);
|
|
state.awaitDrain++;
|
|
increasedAwaitDrain = true;
|
|
}
|
|
src.pause();
|
|
}
|
|
}
|
|
function onerror(er) {
|
|
debug("onerror", er);
|
|
unpipe();
|
|
dest.removeListener("error", onerror);
|
|
if (EElistenerCount(dest, "error") === 0) dest.emit("error", er);
|
|
}
|
|
prependListener(dest, "error", onerror);
|
|
function onclose() {
|
|
dest.removeListener("finish", onfinish);
|
|
unpipe();
|
|
}
|
|
dest.once("close", onclose);
|
|
function onfinish() {
|
|
debug("onfinish");
|
|
dest.removeListener("close", onclose);
|
|
unpipe();
|
|
}
|
|
dest.once("finish", onfinish);
|
|
function unpipe() {
|
|
debug("unpipe");
|
|
src.unpipe(dest);
|
|
}
|
|
dest.emit("pipe", src);
|
|
if (!state.flowing) {
|
|
debug("pipe resume");
|
|
src.resume();
|
|
}
|
|
return dest;
|
|
};
|
|
function pipeOnDrain(src) {
|
|
return function() {
|
|
var state = src._readableState;
|
|
debug("pipeOnDrain", state.awaitDrain);
|
|
if (state.awaitDrain) state.awaitDrain--;
|
|
if (state.awaitDrain === 0 && EElistenerCount(src, "data")) {
|
|
state.flowing = true;
|
|
flow(src);
|
|
}
|
|
};
|
|
}
|
|
Readable.prototype.unpipe = function(dest) {
|
|
var state = this._readableState;
|
|
var unpipeInfo = { hasUnpiped: false };
|
|
if (state.pipesCount === 0) return this;
|
|
if (state.pipesCount === 1) {
|
|
if (dest && dest !== state.pipes) return this;
|
|
if (!dest) dest = state.pipes;
|
|
state.pipes = null;
|
|
state.pipesCount = 0;
|
|
state.flowing = false;
|
|
if (dest) dest.emit("unpipe", this, unpipeInfo);
|
|
return this;
|
|
}
|
|
if (!dest) {
|
|
var dests = state.pipes;
|
|
var len = state.pipesCount;
|
|
state.pipes = null;
|
|
state.pipesCount = 0;
|
|
state.flowing = false;
|
|
for (var i = 0; i < len; i++) {
|
|
dests[i].emit("unpipe", this, { hasUnpiped: false });
|
|
}
|
|
return this;
|
|
}
|
|
var index = indexOf(state.pipes, dest);
|
|
if (index === -1) return this;
|
|
state.pipes.splice(index, 1);
|
|
state.pipesCount -= 1;
|
|
if (state.pipesCount === 1) state.pipes = state.pipes[0];
|
|
dest.emit("unpipe", this, unpipeInfo);
|
|
return this;
|
|
};
|
|
Readable.prototype.on = function(ev, fn) {
|
|
var res = Stream.prototype.on.call(this, ev, fn);
|
|
if (ev === "data") {
|
|
if (this._readableState.flowing !== false) this.resume();
|
|
} else if (ev === "readable") {
|
|
var state = this._readableState;
|
|
if (!state.endEmitted && !state.readableListening) {
|
|
state.readableListening = state.needReadable = true;
|
|
state.emittedReadable = false;
|
|
if (!state.reading) {
|
|
pna2.nextTick(nReadingNextTick, this);
|
|
} else if (state.length) {
|
|
emitReadable(this);
|
|
}
|
|
}
|
|
}
|
|
return res;
|
|
};
|
|
Readable.prototype.addListener = Readable.prototype.on;
|
|
function nReadingNextTick(self2) {
|
|
debug("readable nexttick read 0");
|
|
self2.read(0);
|
|
}
|
|
Readable.prototype.resume = function() {
|
|
var state = this._readableState;
|
|
if (!state.flowing) {
|
|
debug("resume");
|
|
state.flowing = true;
|
|
resume(this, state);
|
|
}
|
|
return this;
|
|
};
|
|
function resume(stream2, state) {
|
|
if (!state.resumeScheduled) {
|
|
state.resumeScheduled = true;
|
|
pna2.nextTick(resume_, stream2, state);
|
|
}
|
|
}
|
|
function resume_(stream2, state) {
|
|
if (!state.reading) {
|
|
debug("resume read 0");
|
|
stream2.read(0);
|
|
}
|
|
state.resumeScheduled = false;
|
|
state.awaitDrain = 0;
|
|
stream2.emit("resume");
|
|
flow(stream2);
|
|
if (state.flowing && !state.reading) stream2.read(0);
|
|
}
|
|
Readable.prototype.pause = function() {
|
|
debug("call pause flowing=%j", this._readableState.flowing);
|
|
if (false !== this._readableState.flowing) {
|
|
debug("pause");
|
|
this._readableState.flowing = false;
|
|
this.emit("pause");
|
|
}
|
|
return this;
|
|
};
|
|
function flow(stream2) {
|
|
var state = stream2._readableState;
|
|
debug("flow", state.flowing);
|
|
while (state.flowing && stream2.read() !== null) {
|
|
}
|
|
}
|
|
Readable.prototype.wrap = function(stream2) {
|
|
var _this = this;
|
|
var state = this._readableState;
|
|
var paused = false;
|
|
stream2.on("end", function() {
|
|
debug("wrapped end");
|
|
if (state.decoder && !state.ended) {
|
|
var chunk = state.decoder.end();
|
|
if (chunk && chunk.length) _this.push(chunk);
|
|
}
|
|
_this.push(null);
|
|
});
|
|
stream2.on("data", function(chunk) {
|
|
debug("wrapped data");
|
|
if (state.decoder) chunk = state.decoder.write(chunk);
|
|
if (state.objectMode && (chunk === null || chunk === void 0)) return;
|
|
else if (!state.objectMode && (!chunk || !chunk.length)) return;
|
|
var ret = _this.push(chunk);
|
|
if (!ret) {
|
|
paused = true;
|
|
stream2.pause();
|
|
}
|
|
});
|
|
for (var i in stream2) {
|
|
if (this[i] === void 0 && typeof stream2[i] === "function") {
|
|
this[i] = /* @__PURE__ */ (function(method) {
|
|
return function() {
|
|
return stream2[method].apply(stream2, arguments);
|
|
};
|
|
})(i);
|
|
}
|
|
}
|
|
for (var n = 0; n < kProxyEvents.length; n++) {
|
|
stream2.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n]));
|
|
}
|
|
this._read = function(n2) {
|
|
debug("wrapped _read", n2);
|
|
if (paused) {
|
|
paused = false;
|
|
stream2.resume();
|
|
}
|
|
};
|
|
return this;
|
|
};
|
|
Object.defineProperty(Readable.prototype, "readableHighWaterMark", {
|
|
// making it explicit this property is not enumerable
|
|
// because otherwise some prototype manipulation in
|
|
// userland will fail
|
|
enumerable: false,
|
|
get: function() {
|
|
return this._readableState.highWaterMark;
|
|
}
|
|
});
|
|
Readable._fromList = fromList;
|
|
function fromList(n, state) {
|
|
if (state.length === 0) return null;
|
|
var ret;
|
|
if (state.objectMode) ret = state.buffer.shift();
|
|
else if (!n || n >= state.length) {
|
|
if (state.decoder) ret = state.buffer.join("");
|
|
else if (state.buffer.length === 1) ret = state.buffer.head.data;
|
|
else ret = state.buffer.concat(state.length);
|
|
state.buffer.clear();
|
|
} else {
|
|
ret = fromListPartial(n, state.buffer, state.decoder);
|
|
}
|
|
return ret;
|
|
}
|
|
function fromListPartial(n, list, hasStrings) {
|
|
var ret;
|
|
if (n < list.head.data.length) {
|
|
ret = list.head.data.slice(0, n);
|
|
list.head.data = list.head.data.slice(n);
|
|
} else if (n === list.head.data.length) {
|
|
ret = list.shift();
|
|
} else {
|
|
ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list);
|
|
}
|
|
return ret;
|
|
}
|
|
function copyFromBufferString(n, list) {
|
|
var p = list.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) list.head = p.next;
|
|
else list.head = list.tail = null;
|
|
} else {
|
|
list.head = p;
|
|
p.data = str.slice(nb);
|
|
}
|
|
break;
|
|
}
|
|
++c;
|
|
}
|
|
list.length -= c;
|
|
return ret;
|
|
}
|
|
function copyFromBuffer(n, list) {
|
|
var ret = Buffer3.allocUnsafe(n);
|
|
var p = list.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) list.head = p.next;
|
|
else list.head = list.tail = null;
|
|
} else {
|
|
list.head = p;
|
|
p.data = buf.slice(nb);
|
|
}
|
|
break;
|
|
}
|
|
++c;
|
|
}
|
|
list.length -= c;
|
|
return ret;
|
|
}
|
|
function endReadable(stream2) {
|
|
var state = stream2._readableState;
|
|
if (state.length > 0) throw new Error('"endReadable()" called on non-empty stream');
|
|
if (!state.endEmitted) {
|
|
state.ended = true;
|
|
pna2.nextTick(endReadableNT, state, stream2);
|
|
}
|
|
}
|
|
function endReadableNT(state, stream2) {
|
|
if (!state.endEmitted && state.length === 0) {
|
|
state.endEmitted = true;
|
|
stream2.readable = false;
|
|
stream2.emit("end");
|
|
}
|
|
}
|
|
function indexOf(xs, x) {
|
|
for (var i = 0, l = xs.length; i < l; i++) {
|
|
if (xs[i] === x) return i;
|
|
}
|
|
return -1;
|
|
}
|
|
}
|
|
});
|
|
|
|
// node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/_stream_transform.js
|
|
var require_stream_transform = __commonJS({
|
|
"node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/_stream_transform.js"(exports2, module2) {
|
|
"use strict";
|
|
module2.exports = Transform2;
|
|
var Duplex = require_stream_duplex();
|
|
var util = Object.create(require_util());
|
|
util.inherits = require_inherits();
|
|
util.inherits(Transform2, Duplex);
|
|
function afterTransform(er, data) {
|
|
var ts = this._transformState;
|
|
ts.transforming = false;
|
|
var cb = ts.writecb;
|
|
if (!cb) {
|
|
return this.emit("error", new Error("write callback called multiple times"));
|
|
}
|
|
ts.writechunk = null;
|
|
ts.writecb = null;
|
|
if (data != null)
|
|
this.push(data);
|
|
cb(er);
|
|
var rs = this._readableState;
|
|
rs.reading = false;
|
|
if (rs.needReadable || rs.length < rs.highWaterMark) {
|
|
this._read(rs.highWaterMark);
|
|
}
|
|
}
|
|
function Transform2(options) {
|
|
if (!(this instanceof Transform2)) return new Transform2(options);
|
|
Duplex.call(this, options);
|
|
this._transformState = {
|
|
afterTransform: afterTransform.bind(this),
|
|
needTransform: false,
|
|
transforming: false,
|
|
writecb: null,
|
|
writechunk: null,
|
|
writeencoding: null
|
|
};
|
|
this._readableState.needReadable = true;
|
|
this._readableState.sync = false;
|
|
if (options) {
|
|
if (typeof options.transform === "function") this._transform = options.transform;
|
|
if (typeof options.flush === "function") this._flush = options.flush;
|
|
}
|
|
this.on("prefinish", prefinish);
|
|
}
|
|
function prefinish() {
|
|
var _this = this;
|
|
if (typeof this._flush === "function") {
|
|
this._flush(function(er, data) {
|
|
done(_this, er, data);
|
|
});
|
|
} else {
|
|
done(this, null, null);
|
|
}
|
|
}
|
|
Transform2.prototype.push = function(chunk, encoding) {
|
|
this._transformState.needTransform = false;
|
|
return Duplex.prototype.push.call(this, chunk, encoding);
|
|
};
|
|
Transform2.prototype._transform = function(chunk, encoding, cb) {
|
|
throw new Error("_transform() is not implemented");
|
|
};
|
|
Transform2.prototype._write = function(chunk, encoding, cb) {
|
|
var ts = this._transformState;
|
|
ts.writecb = cb;
|
|
ts.writechunk = chunk;
|
|
ts.writeencoding = encoding;
|
|
if (!ts.transforming) {
|
|
var rs = this._readableState;
|
|
if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
|
|
}
|
|
};
|
|
Transform2.prototype._read = function(n) {
|
|
var ts = this._transformState;
|
|
if (ts.writechunk !== null && ts.writecb && !ts.transforming) {
|
|
ts.transforming = true;
|
|
this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
|
|
} else {
|
|
ts.needTransform = true;
|
|
}
|
|
};
|
|
Transform2.prototype._destroy = function(err, cb) {
|
|
var _this2 = this;
|
|
Duplex.prototype._destroy.call(this, err, function(err2) {
|
|
cb(err2);
|
|
_this2.emit("close");
|
|
});
|
|
};
|
|
function done(stream2, er, data) {
|
|
if (er) return stream2.emit("error", er);
|
|
if (data != null)
|
|
stream2.push(data);
|
|
if (stream2._writableState.length) throw new Error("Calling transform done when ws.length != 0");
|
|
if (stream2._transformState.transforming) throw new Error("Calling transform done when still transforming");
|
|
return stream2.push(null);
|
|
}
|
|
}
|
|
});
|
|
|
|
// node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/_stream_passthrough.js
|
|
var require_stream_passthrough = __commonJS({
|
|
"node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/_stream_passthrough.js"(exports2, module2) {
|
|
"use strict";
|
|
module2.exports = PassThrough;
|
|
var Transform2 = require_stream_transform();
|
|
var util = Object.create(require_util());
|
|
util.inherits = require_inherits();
|
|
util.inherits(PassThrough, Transform2);
|
|
function PassThrough(options) {
|
|
if (!(this instanceof PassThrough)) return new PassThrough(options);
|
|
Transform2.call(this, options);
|
|
}
|
|
PassThrough.prototype._transform = function(chunk, encoding, cb) {
|
|
cb(null, chunk);
|
|
};
|
|
}
|
|
});
|
|
|
|
// node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/readable.js
|
|
var require_readable = __commonJS({
|
|
"node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/readable.js"(exports2, module2) {
|
|
var Stream = require("stream");
|
|
if (process.env.READABLE_STREAM === "disable" && Stream) {
|
|
module2.exports = Stream;
|
|
exports2 = module2.exports = Stream.Readable;
|
|
exports2.Readable = Stream.Readable;
|
|
exports2.Writable = Stream.Writable;
|
|
exports2.Duplex = Stream.Duplex;
|
|
exports2.Transform = Stream.Transform;
|
|
exports2.PassThrough = Stream.PassThrough;
|
|
exports2.Stream = Stream;
|
|
} else {
|
|
exports2 = module2.exports = require_stream_readable();
|
|
exports2.Stream = Stream || exports2;
|
|
exports2.Readable = exports2;
|
|
exports2.Writable = require_stream_writable();
|
|
exports2.Duplex = require_stream_duplex();
|
|
exports2.Transform = require_stream_transform();
|
|
exports2.PassThrough = require_stream_passthrough();
|
|
}
|
|
}
|
|
});
|
|
|
|
// node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/transform.js
|
|
var require_transform = __commonJS({
|
|
"node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/transform.js"(exports2, module2) {
|
|
module2.exports = require_readable().Transform;
|
|
}
|
|
});
|
|
|
|
// src/index.js
|
|
var isArray = require_isarray();
|
|
var Buffer2 = require_safe_buffer().Buffer;
|
|
var pna = require_process_nextick_args();
|
|
var inherits = require_inherits();
|
|
var deprecate = require_node();
|
|
var stream = require_readable();
|
|
var Transform = require_transform();
|
|
function Shape(name) {
|
|
this.name = name;
|
|
}
|
|
Shape.prototype.describe = function() {
|
|
return "shape " + this.name;
|
|
};
|
|
function Square(side) {
|
|
Shape.call(this, "square");
|
|
this.side = side;
|
|
}
|
|
inherits(Square, Shape);
|
|
Square.prototype.area = function() {
|
|
return this.side * this.side;
|
|
};
|
|
exports.kinds = function(values) {
|
|
return values.map(function(v) {
|
|
return isArray(v) ? "array" : typeof v;
|
|
}).join(",");
|
|
};
|
|
exports.encode = function(text) {
|
|
return Buffer2.from(text, "utf8").toString("hex") + " " + Buffer2.byteLength(text);
|
|
};
|
|
exports.later = function(label, done) {
|
|
pna.nextTick(function(a, b) {
|
|
done(label + ":" + a + "+" + b);
|
|
}, 1, 2);
|
|
};
|
|
exports.square = function(side) {
|
|
var s = new Square(side);
|
|
return s.describe() + " " + s.area() + " " + (Square.super_ === Shape);
|
|
};
|
|
exports.oldArea = deprecate(function(side) {
|
|
return side * side;
|
|
}, "oldArea() is deprecated");
|
|
exports.shout = function(words, done) {
|
|
var source = new stream.Readable({ read: function() {
|
|
} });
|
|
var seen = [];
|
|
const sink = new stream.Writable({
|
|
write: function(chunk, encoding, callback) {
|
|
seen.push(String(chunk));
|
|
callback();
|
|
}
|
|
});
|
|
sink.on("finish", function() {
|
|
done(seen.join("|"));
|
|
});
|
|
source.pipe(new Transform({
|
|
transform: function(chunk, encoding, callback) {
|
|
callback(null, String(chunk).toUpperCase());
|
|
}
|
|
})).pipe(new stream.PassThrough()).pipe(sink);
|
|
words.forEach(function(w) {
|
|
source.push(w);
|
|
});
|
|
source.push(null);
|
|
};
|
|
/*! Bundled license information:
|
|
|
|
safe-buffer/index.js:
|
|
(*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> *)
|
|
*/
|