chaite
Version:
core for chatgpt-plugin and karin-plugin-chatgpt
1,543 lines (1,533 loc) • 277 kB
JavaScript
import { i as __require, t as __commonJS } from "../../rolldown-runtime-DVriDoez.mjs";
import { t as require_isarray } from "../isarray/index.mjs-DaT02uUW.mjs";
import { t as require_util } from "../core-util-is/index.mjs-C0h_2dGX.mjs";
import { p as require_inherits } from "../body-parser/index.mjs-Bj6nfRGh.mjs";
import { t as require_lib$2 } from "../immediate/index.mjs-CkWjI_b-.mjs";
//#region node_modules/.pnpm/process-nextick-args@2.0.1/node_modules/process-nextick-args/index.js
var require_process_nextick_args = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/process-nextick-args@2.0.1/node_modules/process-nextick-args/index.js": ((exports, module) => {
if (typeof process === "undefined" || !process.version || process.version.indexOf("v0.") === 0 || process.version.indexOf("v1.") === 0 && process.version.indexOf("v1.8.") !== 0) module.exports = { nextTick };
else module.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$2;
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$2 = 0;
while (i$2 < args.length) args[i$2++] = arguments[i$2];
return process.nextTick(function afterTick() {
fn.apply(null, args);
});
}
}
}) });
//#endregion
//#region node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/internal/streams/stream.js
var require_stream = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/internal/streams/stream.js": ((exports, module) => {
module.exports = __require("stream");
}) });
//#endregion
//#region node_modules/.pnpm/safe-buffer@5.1.2/node_modules/safe-buffer/index.js
var require_safe_buffer = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/safe-buffer@5.1.2/node_modules/safe-buffer/index.js": ((exports, module) => {
var buffer$1 = __require("buffer");
var Buffer$5 = buffer$1.Buffer;
function copyProps(src, dst) {
for (var key in src) dst[key] = src[key];
}
if (Buffer$5.from && Buffer$5.alloc && Buffer$5.allocUnsafe && Buffer$5.allocUnsafeSlow) module.exports = buffer$1;
else {
copyProps(buffer$1, exports);
exports.Buffer = SafeBuffer;
}
function SafeBuffer(arg, encodingOrOffset, length) {
return Buffer$5(arg, encodingOrOffset, length);
}
copyProps(Buffer$5, SafeBuffer);
SafeBuffer.from = function(arg, encodingOrOffset, length) {
if (typeof arg === "number") throw new TypeError("Argument must not be a number");
return Buffer$5(arg, encodingOrOffset, length);
};
SafeBuffer.alloc = function(size, fill, encoding) {
if (typeof size !== "number") throw new TypeError("Argument must be a number");
var buf = Buffer$5(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 Buffer$5(size);
};
SafeBuffer.allocUnsafeSlow = function(size) {
if (typeof size !== "number") throw new TypeError("Argument must be a number");
return buffer$1.SlowBuffer(size);
};
}) });
//#endregion
//#region node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/internal/streams/BufferList.js
var require_BufferList = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/internal/streams/BufferList.js": ((exports, module) => {
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
}
var Buffer$4 = require_safe_buffer().Buffer;
var util$5 = __require("util");
function copyBuffer(src, target, offset) {
src.copy(target, offset);
}
module.exports = function() {
function BufferList$1() {
_classCallCheck(this, BufferList$1);
this.head = null;
this.tail = null;
this.length = 0;
}
BufferList$1.prototype.push = function push(v$1) {
var entry = {
data: v$1,
next: null
};
if (this.length > 0) this.tail.next = entry;
else this.head = entry;
this.tail = entry;
++this.length;
};
BufferList$1.prototype.unshift = function unshift(v$1) {
var entry = {
data: v$1,
next: this.head
};
if (this.length === 0) this.tail = entry;
this.head = entry;
++this.length;
};
BufferList$1.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$1.prototype.clear = function clear() {
this.head = this.tail = null;
this.length = 0;
};
BufferList$1.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$1.prototype.concat = function concat$1(n) {
if (this.length === 0) return Buffer$4.alloc(0);
var ret = Buffer$4.allocUnsafe(n >>> 0);
var p = this.head;
var i$2 = 0;
while (p) {
copyBuffer(p.data, ret, i$2);
i$2 += p.data.length;
p = p.next;
}
return ret;
};
return BufferList$1;
}();
if (util$5 && util$5.inspect && util$5.inspect.custom) module.exports.prototype[util$5.inspect.custom] = function() {
var obj = util$5.inspect({ length: this.length });
return this.constructor.name + " " + obj;
};
}) });
//#endregion
//#region node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/internal/streams/destroy.js
var require_destroy = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/internal/streams/destroy.js": ((exports, module) => {
var pna$3 = require_process_nextick_args();
function destroy(err$1, 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$1);
else if (err$1) {
if (!this._writableState) pna$3.nextTick(emitErrorNT, this, err$1);
else if (!this._writableState.errorEmitted) {
this._writableState.errorEmitted = true;
pna$3.nextTick(emitErrorNT, this, err$1);
}
}
return this;
}
if (this._readableState) this._readableState.destroyed = true;
if (this._writableState) this._writableState.destroyed = true;
this._destroy(err$1 || null, function(err$2) {
if (!cb && err$2) {
if (!_this._writableState) pna$3.nextTick(emitErrorNT, _this, err$2);
else if (!_this._writableState.errorEmitted) {
_this._writableState.errorEmitted = true;
pna$3.nextTick(emitErrorNT, _this, err$2);
}
} else if (cb) cb(err$2);
});
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(self$1, err$1) {
self$1.emit("error", err$1);
}
module.exports = {
destroy,
undestroy
};
}) });
//#endregion
//#region node_modules/.pnpm/util-deprecate@1.0.2/node_modules/util-deprecate/node.js
var require_node = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/util-deprecate@1.0.2/node_modules/util-deprecate/node.js": ((exports, module) => {
/**
* For Node.js, simply re-export the core `util.deprecate` function.
*/
module.exports = __require("util").deprecate;
}) });
//#endregion
//#region node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/_stream_writable.js
var require__stream_writable = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/_stream_writable.js": ((exports, module) => {
var pna$2 = require_process_nextick_args();
module.exports = Writable$1;
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 : pna$2.nextTick;
var Duplex$3;
Writable$1.WritableState = WritableState;
var util$4 = Object.create(require_util());
util$4.inherits = require_inherits();
var internalUtil = { deprecate: require_node() };
var Stream$2 = require_stream();
var Buffer$3 = require_safe_buffer().Buffer;
var OurUint8Array$1 = (typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : typeof self !== "undefined" ? self : {}).Uint8Array || function() {};
function _uint8ArrayToBuffer$1(chunk) {
return Buffer$3.from(chunk);
}
function _isUint8Array$1(obj) {
return Buffer$3.isBuffer(obj) || obj instanceof OurUint8Array$1;
}
var destroyImpl$1 = require_destroy();
util$4.inherits(Writable$1, Stream$2);
function nop() {}
function WritableState(options, stream) {
Duplex$3 = Duplex$3 || require__stream_duplex();
options = options || {};
var isDuplex = stream instanceof Duplex$3;
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;
this.decodeStrings = !(options.decodeStrings === false);
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(stream, 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$1 = [];
while (current) {
out$1.push(current);
current = current.next;
}
return out$1;
};
(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$1, Symbol.hasInstance, { value: function(object) {
if (realHasInstance.call(this, object)) return true;
if (this !== Writable$1) return false;
return object && object._writableState instanceof WritableState;
} });
} else realHasInstance = function(object) {
return object instanceof this;
};
function Writable$1(options) {
Duplex$3 = Duplex$3 || require__stream_duplex();
if (!realHasInstance.call(Writable$1, this) && !(this instanceof Duplex$3)) return new Writable$1(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$2.call(this);
}
Writable$1.prototype.pipe = function() {
this.emit("error", /* @__PURE__ */ new Error("Cannot pipe, not readable"));
};
function writeAfterEnd(stream, cb) {
var er = /* @__PURE__ */ new Error("write after end");
stream.emit("error", er);
pna$2.nextTick(cb, er);
}
function validChunk(stream, state, chunk, cb) {
var valid = true;
var er = false;
if (chunk === null) er = /* @__PURE__ */ new TypeError("May not write null values to stream");
else if (typeof chunk !== "string" && chunk !== void 0 && !state.objectMode) er = /* @__PURE__ */ new TypeError("Invalid non-string/buffer chunk");
if (er) {
stream.emit("error", er);
pna$2.nextTick(cb, er);
valid = false;
}
return valid;
}
Writable$1.prototype.write = function(chunk, encoding, cb) {
var state = this._writableState;
var ret = false;
var isBuf = !state.objectMode && _isUint8Array$1(chunk);
if (isBuf && !Buffer$3.isBuffer(chunk)) chunk = _uint8ArrayToBuffer$1(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$1.prototype.cork = function() {
var state = this._writableState;
state.corked++;
};
Writable$1.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$1.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 = Buffer$3.from(chunk, encoding);
return chunk;
}
Object.defineProperty(Writable$1.prototype, "writableHighWaterMark", {
enumerable: false,
get: function() {
return this._writableState.highWaterMark;
}
});
function writeOrBuffer(stream, 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(stream, state, false, len, chunk, encoding, cb);
return ret;
}
function doWrite(stream, state, writev, len, chunk, encoding, cb) {
state.writelen = len;
state.writecb = cb;
state.writing = true;
state.sync = true;
if (writev) stream._writev(chunk, state.onwrite);
else stream._write(chunk, encoding, state.onwrite);
state.sync = false;
}
function onwriteError(stream, state, sync, er, cb) {
--state.pendingcb;
if (sync) {
pna$2.nextTick(cb, er);
pna$2.nextTick(finishMaybe, stream, state);
stream._writableState.errorEmitted = true;
stream.emit("error", er);
} else {
cb(er);
stream._writableState.errorEmitted = true;
stream.emit("error", er);
finishMaybe(stream, state);
}
}
function onwriteStateUpdate(state) {
state.writing = false;
state.writecb = null;
state.length -= state.writelen;
state.writelen = 0;
}
function onwrite(stream, er) {
var state = stream._writableState;
var sync = state.sync;
var cb = state.writecb;
onwriteStateUpdate(state);
if (er) onwriteError(stream, state, sync, er, cb);
else {
var finished = needFinish(state);
if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) clearBuffer(stream, state);
if (sync) asyncWrite(afterWrite, stream, state, finished, cb);
else afterWrite(stream, state, finished, cb);
}
}
function afterWrite(stream, state, finished, cb) {
if (!finished) onwriteDrain(stream, state);
state.pendingcb--;
cb();
finishMaybe(stream, state);
}
function onwriteDrain(stream, state) {
if (state.length === 0 && state.needDrain) {
state.needDrain = false;
stream.emit("drain");
}
}
function clearBuffer(stream, state) {
state.bufferProcessing = true;
var entry = state.bufferedRequest;
if (stream._writev && entry && entry.next) {
var l = state.bufferedRequestCount;
var buffer$2 = new Array(l);
var holder = state.corkedRequestsFree;
holder.entry = entry;
var count = 0;
var allBuffers = true;
while (entry) {
buffer$2[count] = entry;
if (!entry.isBuf) allBuffers = false;
entry = entry.next;
count += 1;
}
buffer$2.allBuffers = allBuffers;
doWrite(stream, state, true, state.length, buffer$2, "", 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;
doWrite(stream, state, false, state.objectMode ? 1 : chunk.length, 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$1.prototype._write = function(chunk, encoding, cb) {
cb(/* @__PURE__ */ new Error("_write() is not implemented"));
};
Writable$1.prototype._writev = null;
Writable$1.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(stream, state) {
stream._final(function(err$1) {
state.pendingcb--;
if (err$1) stream.emit("error", err$1);
state.prefinished = true;
stream.emit("prefinish");
finishMaybe(stream, state);
});
}
function prefinish$1(stream, state) {
if (!state.prefinished && !state.finalCalled) if (typeof stream._final === "function") {
state.pendingcb++;
state.finalCalled = true;
pna$2.nextTick(callFinal, stream, state);
} else {
state.prefinished = true;
stream.emit("prefinish");
}
}
function finishMaybe(stream, state) {
var need = needFinish(state);
if (need) {
prefinish$1(stream, state);
if (state.pendingcb === 0) {
state.finished = true;
stream.emit("finish");
}
}
return need;
}
function endWritable(stream, state, cb) {
state.ending = true;
finishMaybe(stream, state);
if (cb) if (state.finished) pna$2.nextTick(cb);
else stream.once("finish", cb);
state.ended = true;
stream.writable = false;
}
function onCorkedFinish(corkReq, state, err$1) {
var entry = corkReq.entry;
corkReq.entry = null;
while (entry) {
var cb = entry.callback;
state.pendingcb--;
cb(err$1);
entry = entry.next;
}
state.corkedRequestsFree.next = corkReq;
}
Object.defineProperty(Writable$1.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$1.prototype.destroy = destroyImpl$1.destroy;
Writable$1.prototype._undestroy = destroyImpl$1.undestroy;
Writable$1.prototype._destroy = function(err$1, cb) {
this.end();
cb(err$1);
};
}) });
//#endregion
//#region node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/_stream_duplex.js
var require__stream_duplex = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/_stream_duplex.js": ((exports, module) => {
var pna$1 = require_process_nextick_args();
var objectKeys = Object.keys || function(obj) {
var keys$1 = [];
for (var key in obj) keys$1.push(key);
return keys$1;
};
module.exports = Duplex$2;
var util$3 = Object.create(require_util());
util$3.inherits = require_inherits();
var Readable$2 = require__stream_readable();
var Writable = require__stream_writable();
util$3.inherits(Duplex$2, Readable$2);
var keys = objectKeys(Writable.prototype);
for (var v = 0; v < keys.length; v++) {
var method = keys[v];
if (!Duplex$2.prototype[method]) Duplex$2.prototype[method] = Writable.prototype[method];
}
function Duplex$2(options) {
if (!(this instanceof Duplex$2)) return new Duplex$2(options);
Readable$2.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$2.prototype, "writableHighWaterMark", {
enumerable: false,
get: function() {
return this._writableState.highWaterMark;
}
});
function onend() {
if (this.allowHalfOpen || this._writableState.ended) return;
pna$1.nextTick(onEndNT, this);
}
function onEndNT(self$1) {
self$1.end();
}
Object.defineProperty(Duplex$2.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$2.prototype._destroy = function(err$1, cb) {
this.push(null);
this.end();
pna$1.nextTick(cb, err$1);
};
}) });
//#endregion
//#region node_modules/.pnpm/string_decoder@1.1.1/node_modules/string_decoder/lib/string_decoder.js
var require_string_decoder = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/string_decoder@1.1.1/node_modules/string_decoder/lib/string_decoder.js": ((exports) => {
var Buffer$2 = require_safe_buffer().Buffer;
var isEncoding = Buffer$2.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" && (Buffer$2.isEncoding === isEncoding || !isEncoding(enc))) throw new Error("Unknown encoding: " + enc);
return nenc || enc;
}
exports.StringDecoder = StringDecoder$1;
function StringDecoder$1(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 = Buffer$2.allocUnsafe(nb);
}
StringDecoder$1.prototype.write = function(buf) {
if (buf.length === 0) return "";
var r;
var i$2;
if (this.lastNeed) {
r = this.fillLast(buf);
if (r === void 0) return "";
i$2 = this.lastNeed;
this.lastNeed = 0;
} else i$2 = 0;
if (i$2 < buf.length) return r ? r + this.text(buf, i$2) : this.text(buf, i$2);
return r || "";
};
StringDecoder$1.prototype.end = utf8End;
StringDecoder$1.prototype.text = utf8Text;
StringDecoder$1.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(self$1, buf, i$2) {
var j = buf.length - 1;
if (j < i$2) return 0;
var nb = utf8CheckByte(buf[j]);
if (nb >= 0) {
if (nb > 0) self$1.lastNeed = nb - 1;
return nb;
}
if (--j < i$2 || nb === -2) return 0;
nb = utf8CheckByte(buf[j]);
if (nb >= 0) {
if (nb > 0) self$1.lastNeed = nb - 2;
return nb;
}
if (--j < i$2 || nb === -2) return 0;
nb = utf8CheckByte(buf[j]);
if (nb >= 0) {
if (nb > 0) if (nb === 2) nb = 0;
else self$1.lastNeed = nb - 3;
return nb;
}
return 0;
}
function utf8CheckExtraBytes(self$1, buf, p) {
if ((buf[0] & 192) !== 128) {
self$1.lastNeed = 0;
return "�";
}
if (self$1.lastNeed > 1 && buf.length > 1) {
if ((buf[1] & 192) !== 128) {
self$1.lastNeed = 1;
return "�";
}
if (self$1.lastNeed > 2 && buf.length > 2) {
if ((buf[2] & 192) !== 128) {
self$1.lastNeed = 2;
return "�";
}
}
}
}
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$2) {
var total = utf8CheckIncomplete(this, buf, i$2);
if (!this.lastNeed) return buf.toString("utf8", i$2);
this.lastTotal = total;
var end = buf.length - (total - this.lastNeed);
buf.copy(this.lastChar, 0, end);
return buf.toString("utf8", i$2, end);
}
function utf8End(buf) {
var r = buf && buf.length ? this.write(buf) : "";
if (this.lastNeed) return r + "�";
return r;
}
function utf16Text(buf, i$2) {
if ((buf.length - i$2) % 2 === 0) {
var r = buf.toString("utf16le", i$2);
if (r) {
var c$1 = r.charCodeAt(r.length - 1);
if (c$1 >= 55296 && c$1 <= 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$2, 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$2) {
var n = (buf.length - i$2) % 3;
if (n === 0) return buf.toString("base64", i$2);
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$2, 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) : "";
}
}) });
//#endregion
//#region node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/_stream_readable.js
var require__stream_readable = /* @__PURE__ */ __commonJS({ "node_modules/.pnpm/readable-stream@2.3.8/node_modules/readable-stream/lib/_stream_readable.js": ((exports, module) => {
var pna = require_process_nextick_args();
module.exports = Readable$1;
var isArray = require_isarray();
var Duplex$1;
Readable$1.ReadableState = ReadableState;
__require("events").EventEmitter;
var EElistenerCount = function(emitter, type) {
return emitter.listeners(type).length;
};
var Stream$1 = require_stream();
var Buffer$1 = require_safe_buffer().Buffer;
var OurUint8Array = (typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : typeof self !== "undefined" ? self : {}).Uint8Array || function() {};
function _uint8ArrayToBuffer(chunk) {
return Buffer$1.from(chunk);
}
function _isUint8Array(obj) {
return Buffer$1.isBuffer(obj) || obj instanceof OurUint8Array;
}
var util$2 = Object.create(require_util());
util$2.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$2.inherits(Readable$1, Stream$1);
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 (isArray(emitter._events[event])) emitter._events[event].unshift(fn);
else emitter._events[event] = [fn, emitter._events[event]];
}
function ReadableState(options, stream) {
Duplex$1 = Duplex$1 || require__stream_duplex();
options = options || {};
var isDuplex = stream instanceof Duplex$1;
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$1(options) {
Duplex$1 = Duplex$1 || require__stream_duplex();
if (!(this instanceof Readable$1)) return new Readable$1(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$1.call(this);
}
Object.defineProperty(Readable$1.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$1.prototype.destroy = destroyImpl.destroy;
Readable$1.prototype._undestroy = destroyImpl.undestroy;
Readable$1.prototype._destroy = function(err$1, cb) {
this.push(null);
cb(err$1);
};
Readable$1.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 = Buffer$1.from(chunk, encoding);
encoding = "";
}
skipChunkCheck = true;
}
} else skipChunkCheck = true;
return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
};
Readable$1.prototype.unshift = function(chunk) {
return readableAddChunk(this, chunk, null, true, false);
};
function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
var state = stream._readableState;
if (chunk === null) {
state.reading = false;
onEofChunk(stream, state);
} else {
var er;
if (!skipChunkCheck) er = chunkInvalid(state, chunk);
if (er) stream.emit("error", er);
else if (state.objectMode || chunk && chunk.length > 0) {
if (typeof chunk !== "string" && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer$1.prototype) chunk = _uint8ArrayToBuffer(chunk);
if (addToFront) if (state.endEmitted) stream.emit("error", /* @__PURE__ */ new Error("stream.unshift() after end event"));
else addChunk(stream, state, chunk, true);
else if (state.ended) stream.emit("error", /* @__PURE__ */ 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(stream, state, chunk, false);
else maybeReadMore(stream, state);
} else addChunk(stream, state, chunk, false);
}
} else if (!addToFront) state.reading = false;
}
return needMoreData(state);
}
function addChunk(stream, state, chunk, addToFront) {
if (state.flowing && state.length === 0 && !state.sync) {
stream.emit("data", chunk);
stream.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(stream);
}
maybeReadMore(stream, state);
}
function chunkInvalid(state, chunk) {
var er;
if (!_isUint8Array(chunk) && typeof chunk !== "string" && chunk !== void 0 && !state.objectMode) er = /* @__PURE__ */ 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$1.prototype.isPaused = function() {
return this._readableState.flowing === false;
};
Readable$1.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$1.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(stream, 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(stream);
}
function emitReadable(stream) {
var state = stream._readableState;
state.needReadable = false;
if (!state.emittedReadable) {
debug("emitReadable", state.flowing);
state.emittedReadable = true;
if (state.sync) pna.nextTick(emitReadable_, stream);
else emitReadable_(stream);
}
}
function emitReadable_(stream) {
debug("emit readable");
stream.emit("readable");
flow(stream);
}
function maybeReadMore(stream, state) {
if (!state.readingMore) {
state.readingMore = true;
pna.nextTick(maybeReadMore_, stream, state);
}
}
function maybeReadMore_(stream, state) {
var len = state.length;
while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) {
debug("maybeReadMore read 0");
stream.read(0);
if (len === state.length) break;
else len = state.length;
}
state.readingMore = false;
}
Readable$1.prototype._read = function(n) {
this.emit("error", /* @__PURE__ */ new Error("_read() is not implemented"));
};
Readable$1.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 endFn = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr ? onend$1 : unpipe;
if (state.endEmitted) pna.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$1() {
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$1);
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;
if (false === dest.write(chunk) && !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$1.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$2 = 0; i$2 < len; i$2++) dests[i$2].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$1.prototype.on = function(ev, fn) {
var res = Stream$1.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) pna.nextTick(nReadingNextTick, this);
else if (state.length) emitReadable(this);
}
}
return res;
};
Readable$1.prototype.addListener = Readable$1.prototype.on;
function nReadingNextTick(self$1) {
debug("readable nexttick read 0");
self$1.read(0);
}
Readable$1.prototype.resume = function() {
var state = this._readableState;
if (!state.flowing) {
debug("resume");
state.flowing = true;
resume(this, state);
}
return this;
};
function resume(stream, state) {
if (!state.resumeScheduled) {
state.resumeScheduled = true;
pna.nextTick(resume_, stream, state);
}
}
function resume_(stream, state) {
if (!state.reading) {
debug("resume read 0");
stream.read(0);
}
state.resumeScheduled = false;
state.awaitDrain = 0;
stream.emit("resume");
flow(stream);
if (state.flowing && !state.reading) stream.read(0);
}
Readable$1.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(stream) {
var state = stream._readableState;
debug("flow", state.flowing);
while (state.flowing && stream.read() !== null);
}
Readable$1.prototype.wrap = function(stream) {
var _this = this;
var state = this._readableState;
var paused = false;
stream.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);
});
stream.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;
if (!_this.push(chunk)) {
paused = true;
stream.pause();
}
});
for (var i$2 in stream) if (this[i$2] === void 0 && typeof stream[i$2] === "function") this[i$2] = function(method$1) {
return function() {
return stream[method$1].apply(stream, arguments);
};
}(i$2);
for (var n = 0; n < kProxyEvents.length; n++) stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n]));
this._read = function(n$1) {
debug("wrapped _read", n$1);
if (paused) {
paused = false;
stream.resume();
}
};
return this;
};
Object.defineProperty(Readable$1.prototype, "readableHighWaterMark", {
enumerable: false,
get: function() {
return this._readableState.highWaterMark;
}
});
Readable$1._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 = 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$1;
if (p.next) list.head = p.next;
else list.head = list.tail = null;
} else {
list.head = p;
p.data = str.slice(nb);
}
break;
}
++c$1;
}
list.length -= c$1;
return ret;
}
function copyFromBuffer(n, list) {
var ret = Buffer$1.allocUnsafe(n);
var p = list.head;
var c$1 = 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$1;
if (p.next) list.head = p.next;
else list.head = list.tail = null;
} else {
list.head = p;
p.data = buf.slice(nb);
}
break;
}
++c$1;
}
list.length -= c$1;
return ret;
}
function endReadable(stream) {
var state = stream._readableState;
if (state.length > 0) throw new Error("\"endReadable()\" called on non-empty stream");
if (!state.endEmitted) {
state.ended = true;
pna.nextTick(endReadableNT, state, stream);
}
}
function endReadableNT(state, stream) {
if (!state.endEmitted && state.length === 0) {
state.endEmitted = true;
stream.readable = false;
stream.emit("end");
}
}
function indexOf(xs, x) {
for (var i$2 = 0, l = xs.le