7943 lines
279 KiB
JavaScript
7943 lines
279 KiB
JavaScript
var __bare_os_bundle_exports__ = (() => {
|
|
var __create = Object.create;
|
|
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __getProtoOf = Object.getPrototypeOf;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
}) : x)(function(x) {
|
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
});
|
|
var __commonJS = (cb, mod) => function __require2() {
|
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
};
|
|
var __export = (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
};
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
// file that has been converted to a CommonJS file using a Babel-
|
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
mod
|
|
));
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
|
|
// ../../node_modules/bare-events/lib/errors.js
|
|
var require_errors = __commonJS({
|
|
"../../node_modules/bare-events/lib/errors.js"(exports, module) {
|
|
module.exports = class EventEmitterError extends Error {
|
|
constructor(msg, code, fn = EventEmitterError, opts) {
|
|
super(`${code}: ${msg}`, opts);
|
|
this.code = code;
|
|
if (Error.captureStackTrace) {
|
|
Error.captureStackTrace(this, fn);
|
|
}
|
|
}
|
|
get name() {
|
|
return "EventEmitterError";
|
|
}
|
|
static OPERATION_ABORTED(cause, msg = "Operation aborted") {
|
|
return new EventEmitterError(msg, "OPERATION_ABORTED", EventEmitterError.OPERATION_ABORTED, {
|
|
cause
|
|
});
|
|
}
|
|
static UNHANDLED_ERROR(cause, msg = "Unhandled error") {
|
|
return new EventEmitterError(msg, "UNHANDLED_ERROR", EventEmitterError.UNHANDLED_ERROR, {
|
|
cause
|
|
});
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-events/index.js
|
|
var require_bare_events = __commonJS({
|
|
"../../node_modules/bare-events/index.js"(exports, module) {
|
|
var errors = require_errors();
|
|
var EventListener = class {
|
|
constructor() {
|
|
this.list = [];
|
|
this.count = 0;
|
|
}
|
|
append(ctx, name, fn, once) {
|
|
this.count++;
|
|
ctx.emit("newListener", name, fn);
|
|
this.list.push([fn, once]);
|
|
}
|
|
prepend(ctx, name, fn, once) {
|
|
this.count++;
|
|
ctx.emit("newListener", name, fn);
|
|
this.list.unshift([fn, once]);
|
|
}
|
|
remove(ctx, name, fn) {
|
|
for (let i = 0, n = this.list.length; i < n; i++) {
|
|
const l = this.list[i];
|
|
if (l[0] === fn) {
|
|
this.list.splice(i, 1);
|
|
if (this.count === 1) delete ctx._events[name];
|
|
ctx.emit("removeListener", name, fn);
|
|
this.count--;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
removeAll(ctx, name) {
|
|
const list = [...this.list];
|
|
this.list = [];
|
|
if (this.count === list.length) delete ctx._events[name];
|
|
for (let i = list.length - 1; i >= 0; i--) {
|
|
ctx.emit("removeListener", name, list[i][0]);
|
|
}
|
|
this.count -= list.length;
|
|
}
|
|
emit(ctx, name, ...args) {
|
|
const list = [...this.list];
|
|
for (let i = 0, n = list.length; i < n; i++) {
|
|
const l = list[i];
|
|
if (l[1] === true) this.remove(ctx, name, l[0]);
|
|
Reflect.apply(l[0], ctx, args);
|
|
}
|
|
return list.length > 0;
|
|
}
|
|
};
|
|
function appendListener(ctx, name, fn, once) {
|
|
if (ctx._events === void 0) ctx._events = /* @__PURE__ */ Object.create(null);
|
|
const e = ctx._events[name] || (ctx._events[name] = new EventListener());
|
|
e.append(ctx, name, fn, once);
|
|
return ctx;
|
|
}
|
|
function prependListener(ctx, name, fn, once) {
|
|
if (ctx._events === void 0) ctx._events = /* @__PURE__ */ Object.create(null);
|
|
const e = ctx._events[name] || (ctx._events[name] = new EventListener());
|
|
e.prepend(ctx, name, fn, once);
|
|
return ctx;
|
|
}
|
|
function removeListener(ctx, name, fn) {
|
|
if (ctx._events === void 0) return ctx;
|
|
const e = ctx._events[name];
|
|
if (e !== void 0) e.remove(ctx, name, fn);
|
|
return ctx;
|
|
}
|
|
function throwUnhandledError(...args) {
|
|
let err;
|
|
if (args.length > 0) err = args[0];
|
|
if (err instanceof Error === false) err = errors.UNHANDLED_ERROR(err);
|
|
if (Error.captureStackTrace) {
|
|
Error.captureStackTrace(err, exports.prototype.emit);
|
|
}
|
|
queueMicrotask(() => {
|
|
throw err;
|
|
});
|
|
}
|
|
module.exports = exports = class EventEmitter {
|
|
constructor() {
|
|
this._events = /* @__PURE__ */ Object.create(null);
|
|
}
|
|
addListener(name, fn) {
|
|
return appendListener(this, name, fn, false);
|
|
}
|
|
addOnceListener(name, fn) {
|
|
return appendListener(this, name, fn, true);
|
|
}
|
|
prependListener(name, fn) {
|
|
return prependListener(this, name, fn, false);
|
|
}
|
|
prependOnceListener(name, fn) {
|
|
return prependListener(this, name, fn, true);
|
|
}
|
|
removeListener(name, fn) {
|
|
return removeListener(this, name, fn);
|
|
}
|
|
on(name, fn) {
|
|
return appendListener(this, name, fn, false);
|
|
}
|
|
once(name, fn) {
|
|
return appendListener(this, name, fn, true);
|
|
}
|
|
off(name, fn) {
|
|
return removeListener(this, name, fn);
|
|
}
|
|
emit(name, ...args) {
|
|
if (name === "error" && this._events !== void 0 && this._events.error === void 0) {
|
|
throwUnhandledError(...args);
|
|
}
|
|
if (this._events === void 0) return false;
|
|
const e = this._events[name];
|
|
return e === void 0 ? false : e.emit(this, name, ...args);
|
|
}
|
|
listeners(name) {
|
|
if (this._events === void 0) return [];
|
|
const e = this._events[name];
|
|
return e === void 0 ? [] : [...e.list];
|
|
}
|
|
listenerCount(name) {
|
|
if (this._events === void 0) return 0;
|
|
const e = this._events[name];
|
|
return e === void 0 ? 0 : e.list.length;
|
|
}
|
|
getMaxListeners() {
|
|
return EventEmitter.defaultMaxListeners;
|
|
}
|
|
setMaxListeners(n) {
|
|
}
|
|
removeAllListeners(name) {
|
|
if (arguments.length === 0) {
|
|
for (const key of Reflect.ownKeys(this._events)) {
|
|
if (key === "removeListener") continue;
|
|
this.removeAllListeners(key);
|
|
}
|
|
this.removeAllListeners("removeListener");
|
|
} else {
|
|
const e = this._events[name];
|
|
if (e !== void 0) e.removeAll(this, name);
|
|
}
|
|
return this;
|
|
}
|
|
};
|
|
exports.EventEmitter = exports;
|
|
exports.errors = errors;
|
|
exports.defaultMaxListeners = 10;
|
|
exports.on = function on(emitter, name, opts = {}) {
|
|
const { signal } = opts;
|
|
if (signal && signal.aborted) {
|
|
throw errors.OPERATION_ABORTED(signal.reason);
|
|
}
|
|
let error = null;
|
|
let done = false;
|
|
const events = [];
|
|
const promises = [];
|
|
if (name !== "error") emitter.on("error", onerror);
|
|
if (signal) signal.addEventListener("abort", onabort);
|
|
emitter.on(name, onevent);
|
|
return {
|
|
next() {
|
|
if (events.length) {
|
|
return Promise.resolve({ value: events.shift(), done: false });
|
|
}
|
|
if (error) {
|
|
const err = error;
|
|
error = null;
|
|
return Promise.reject(err);
|
|
}
|
|
if (done) return onclose();
|
|
return new Promise((resolve, reject) => promises.push({ resolve, reject }));
|
|
},
|
|
return() {
|
|
return onclose();
|
|
},
|
|
throw(err) {
|
|
return onerror(err);
|
|
},
|
|
[Symbol.asyncIterator]() {
|
|
return this;
|
|
}
|
|
};
|
|
function onevent(...args) {
|
|
if (promises.length) {
|
|
promises.shift().resolve({ value: args, done: false });
|
|
} else {
|
|
events.push(args);
|
|
}
|
|
}
|
|
function onerror(err) {
|
|
emitter.off(name, onevent).off("error", onerror);
|
|
if (promises.length) {
|
|
promises.shift().reject(err);
|
|
} else {
|
|
error = err;
|
|
}
|
|
return Promise.resolve({ done: true });
|
|
}
|
|
function onabort() {
|
|
signal.removeEventListener("abort", onabort);
|
|
onerror(errors.OPERATION_ABORTED(signal.reason));
|
|
}
|
|
function onclose() {
|
|
emitter.off(name, onevent);
|
|
if (name !== "error") emitter.off("error", onerror);
|
|
if (signal) signal.removeEventListener("abort", onabort);
|
|
done = true;
|
|
if (promises.length) promises.shift().resolve({ done: true });
|
|
return Promise.resolve({ done: true });
|
|
}
|
|
};
|
|
exports.once = function once(emitter, name, opts = {}) {
|
|
const { signal } = opts;
|
|
if (signal && signal.aborted) {
|
|
return Promise.reject(errors.OPERATION_ABORTED(signal.reason));
|
|
}
|
|
return new Promise((resolve, reject) => {
|
|
if (name !== "error") emitter.on("error", onerror);
|
|
if (signal) signal.addEventListener("abort", onabort);
|
|
emitter.once(name, onevent);
|
|
function onevent(...args) {
|
|
if (name !== "error") emitter.off("error", onerror);
|
|
if (signal) signal.removeEventListener("abort", onabort);
|
|
resolve(args);
|
|
}
|
|
function onerror(err) {
|
|
emitter.off(name, onevent);
|
|
if (name !== "error") emitter.off("error", onerror);
|
|
reject(err);
|
|
}
|
|
function onabort() {
|
|
signal.removeEventListener("abort", onabort);
|
|
onerror(errors.OPERATION_ABORTED(signal.reason));
|
|
}
|
|
});
|
|
};
|
|
exports.forward = function forward(from, to, names, opts = {}) {
|
|
if (typeof names === "string") names = [names];
|
|
const { emit = to.emit.bind(to) } = opts;
|
|
const listeners = names.map(
|
|
(name) => function onevent(...args) {
|
|
emit(name, ...args);
|
|
}
|
|
);
|
|
to.on("newListener", (name) => {
|
|
const i = names.indexOf(name);
|
|
if (i !== -1 && to.listenerCount(name) === 0) {
|
|
from.on(name, listeners[i]);
|
|
}
|
|
}).on("removeListener", (name) => {
|
|
const i = names.indexOf(name);
|
|
if (i !== -1 && to.listenerCount(name) === 0) {
|
|
from.off(name, listeners[i]);
|
|
}
|
|
});
|
|
};
|
|
exports.listenerCount = function listenerCount(emitter, name) {
|
|
return emitter.listenerCount(name);
|
|
};
|
|
exports.getMaxListeners = function getMaxListeners(emitter) {
|
|
if (typeof emitter.getMaxListeners === "function") {
|
|
return emitter.getMaxListeners();
|
|
}
|
|
return exports.defaultMaxListeners;
|
|
};
|
|
exports.setMaxListeners = function setMaxListeners(n, ...emitters) {
|
|
if (emitters.length === 0) exports.defaultMaxListeners = n;
|
|
else {
|
|
for (const emitter of emitters) {
|
|
if (typeof emitter.setMaxListeners === "function") {
|
|
emitter.setMaxListeners(n);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../bare-os-openssh/vendor/bare-node-shims/bare-node-events/index.js
|
|
var require_bare_node_events = __commonJS({
|
|
"../bare-os-openssh/vendor/bare-node-shims/bare-node-events/index.js"(exports, module) {
|
|
module.exports = require_bare_events();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/events-universal/default.js
|
|
var require_default = __commonJS({
|
|
"../../node_modules/events-universal/default.js"(exports, module) {
|
|
module.exports = require_bare_node_events();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/fast-fifo/fixed-size.js
|
|
var require_fixed_size = __commonJS({
|
|
"../../node_modules/fast-fifo/fixed-size.js"(exports, module) {
|
|
module.exports = class FixedFIFO {
|
|
constructor(hwm) {
|
|
if (!(hwm > 0) || (hwm - 1 & hwm) !== 0) throw new Error("Max size for a FixedFIFO should be a power of two");
|
|
this.buffer = new Array(hwm);
|
|
this.mask = hwm - 1;
|
|
this.top = 0;
|
|
this.btm = 0;
|
|
this.next = null;
|
|
}
|
|
clear() {
|
|
this.top = this.btm = 0;
|
|
this.next = null;
|
|
this.buffer.fill(void 0);
|
|
}
|
|
push(data) {
|
|
if (this.buffer[this.top] !== void 0) return false;
|
|
this.buffer[this.top] = data;
|
|
this.top = this.top + 1 & this.mask;
|
|
return true;
|
|
}
|
|
shift() {
|
|
const last = this.buffer[this.btm];
|
|
if (last === void 0) return void 0;
|
|
this.buffer[this.btm] = void 0;
|
|
this.btm = this.btm + 1 & this.mask;
|
|
return last;
|
|
}
|
|
peek() {
|
|
return this.buffer[this.btm];
|
|
}
|
|
isEmpty() {
|
|
return this.buffer[this.btm] === void 0;
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/fast-fifo/index.js
|
|
var require_fast_fifo = __commonJS({
|
|
"../../node_modules/fast-fifo/index.js"(exports, module) {
|
|
var FixedFIFO = require_fixed_size();
|
|
module.exports = class FastFIFO {
|
|
constructor(hwm) {
|
|
this.hwm = hwm || 16;
|
|
this.head = new FixedFIFO(this.hwm);
|
|
this.tail = this.head;
|
|
this.length = 0;
|
|
}
|
|
clear() {
|
|
this.head = this.tail;
|
|
this.head.clear();
|
|
this.length = 0;
|
|
}
|
|
push(val) {
|
|
this.length++;
|
|
if (!this.head.push(val)) {
|
|
const prev = this.head;
|
|
this.head = prev.next = new FixedFIFO(2 * this.head.buffer.length);
|
|
this.head.push(val);
|
|
}
|
|
}
|
|
shift() {
|
|
if (this.length !== 0) this.length--;
|
|
const val = this.tail.shift();
|
|
if (val === void 0 && this.tail.next) {
|
|
const next = this.tail.next;
|
|
this.tail.next = null;
|
|
this.tail = next;
|
|
return this.tail.shift();
|
|
}
|
|
return val;
|
|
}
|
|
peek() {
|
|
const val = this.tail.peek();
|
|
if (val === void 0 && this.tail.next) return this.tail.next.peek();
|
|
return val;
|
|
}
|
|
isEmpty() {
|
|
return this.length === 0;
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/b4a/index.js
|
|
var require_b4a = __commonJS({
|
|
"../../node_modules/b4a/index.js"(exports, module) {
|
|
function isBuffer(value) {
|
|
return Buffer.isBuffer(value) || value instanceof Uint8Array;
|
|
}
|
|
function isEncoding(encoding) {
|
|
return Buffer.isEncoding(encoding);
|
|
}
|
|
function alloc(size, fill2, encoding) {
|
|
return Buffer.alloc(size, fill2, encoding);
|
|
}
|
|
function allocUnsafe(size) {
|
|
return Buffer.allocUnsafe(size);
|
|
}
|
|
function allocUnsafeSlow(size) {
|
|
return Buffer.allocUnsafeSlow(size);
|
|
}
|
|
function byteLength(string, encoding) {
|
|
return Buffer.byteLength(string, encoding);
|
|
}
|
|
function compare(a, b) {
|
|
return Buffer.compare(a, b);
|
|
}
|
|
function concat(buffers, totalLength) {
|
|
return Buffer.concat(buffers, totalLength);
|
|
}
|
|
function copy(source, target, targetStart, start, end) {
|
|
return toBuffer(source).copy(target, targetStart, start, end);
|
|
}
|
|
function equals(a, b) {
|
|
return toBuffer(a).equals(b);
|
|
}
|
|
function fill(buffer, value, offset, end, encoding) {
|
|
return toBuffer(buffer).fill(value, offset, end, encoding);
|
|
}
|
|
function from(value, encodingOrOffset, length) {
|
|
return Buffer.from(value, encodingOrOffset, length);
|
|
}
|
|
function includes(buffer, value, byteOffset, encoding) {
|
|
return toBuffer(buffer).includes(value, byteOffset, encoding);
|
|
}
|
|
function indexOf(buffer, value, byfeOffset, encoding) {
|
|
return toBuffer(buffer).indexOf(value, byfeOffset, encoding);
|
|
}
|
|
function lastIndexOf(buffer, value, byteOffset, encoding) {
|
|
return toBuffer(buffer).lastIndexOf(value, byteOffset, encoding);
|
|
}
|
|
function swap16(buffer) {
|
|
return toBuffer(buffer).swap16();
|
|
}
|
|
function swap32(buffer) {
|
|
return toBuffer(buffer).swap32();
|
|
}
|
|
function swap64(buffer) {
|
|
return toBuffer(buffer).swap64();
|
|
}
|
|
function toBuffer(buffer) {
|
|
if (Buffer.isBuffer(buffer)) return buffer;
|
|
return Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
}
|
|
function toString(buffer, encoding, start, end) {
|
|
return toBuffer(buffer).toString(encoding, start, end);
|
|
}
|
|
function write(buffer, string, offset, length, encoding) {
|
|
return toBuffer(buffer).write(string, offset, length, encoding);
|
|
}
|
|
function readDoubleBE(buffer, offset) {
|
|
return toBuffer(buffer).readDoubleBE(offset);
|
|
}
|
|
function readDoubleLE(buffer, offset) {
|
|
return toBuffer(buffer).readDoubleLE(offset);
|
|
}
|
|
function readFloatBE(buffer, offset) {
|
|
return toBuffer(buffer).readFloatBE(offset);
|
|
}
|
|
function readFloatLE(buffer, offset) {
|
|
return toBuffer(buffer).readFloatLE(offset);
|
|
}
|
|
function readInt32BE(buffer, offset) {
|
|
return toBuffer(buffer).readInt32BE(offset);
|
|
}
|
|
function readInt32LE(buffer, offset) {
|
|
return toBuffer(buffer).readInt32LE(offset);
|
|
}
|
|
function readUInt32BE(buffer, offset) {
|
|
return toBuffer(buffer).readUInt32BE(offset);
|
|
}
|
|
function readUInt32LE(buffer, offset) {
|
|
return toBuffer(buffer).readUInt32LE(offset);
|
|
}
|
|
function writeDoubleBE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeDoubleBE(value, offset);
|
|
}
|
|
function writeDoubleLE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeDoubleLE(value, offset);
|
|
}
|
|
function writeFloatBE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeFloatBE(value, offset);
|
|
}
|
|
function writeFloatLE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeFloatLE(value, offset);
|
|
}
|
|
function writeInt32BE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeInt32BE(value, offset);
|
|
}
|
|
function writeInt32LE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeInt32LE(value, offset);
|
|
}
|
|
function writeUInt32BE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeUInt32BE(value, offset);
|
|
}
|
|
function writeUInt32LE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeUInt32LE(value, offset);
|
|
}
|
|
module.exports = {
|
|
isBuffer,
|
|
isEncoding,
|
|
alloc,
|
|
allocUnsafe,
|
|
allocUnsafeSlow,
|
|
byteLength,
|
|
compare,
|
|
concat,
|
|
copy,
|
|
equals,
|
|
fill,
|
|
from,
|
|
includes,
|
|
indexOf,
|
|
lastIndexOf,
|
|
swap16,
|
|
swap32,
|
|
swap64,
|
|
toBuffer,
|
|
toString,
|
|
write,
|
|
readDoubleBE,
|
|
readDoubleLE,
|
|
readFloatBE,
|
|
readFloatLE,
|
|
readInt32BE,
|
|
readInt32LE,
|
|
readUInt32BE,
|
|
readUInt32LE,
|
|
writeDoubleBE,
|
|
writeDoubleLE,
|
|
writeFloatBE,
|
|
writeFloatLE,
|
|
writeInt32BE,
|
|
writeInt32LE,
|
|
writeUInt32BE,
|
|
writeUInt32LE
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/text-decoder/lib/pass-through-decoder.js
|
|
var require_pass_through_decoder = __commonJS({
|
|
"../../node_modules/text-decoder/lib/pass-through-decoder.js"(exports, module) {
|
|
var b4a = require_b4a();
|
|
module.exports = class PassThroughDecoder {
|
|
constructor(encoding) {
|
|
this.encoding = encoding;
|
|
}
|
|
get remaining() {
|
|
return 0;
|
|
}
|
|
decode(data) {
|
|
return b4a.toString(data, this.encoding);
|
|
}
|
|
flush() {
|
|
return "";
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/text-decoder/lib/utf8-decoder.js
|
|
var require_utf8_decoder = __commonJS({
|
|
"../../node_modules/text-decoder/lib/utf8-decoder.js"(exports, module) {
|
|
var b4a = require_b4a();
|
|
module.exports = class UTF8Decoder {
|
|
constructor() {
|
|
this._reset();
|
|
}
|
|
get remaining() {
|
|
return this.bytesSeen;
|
|
}
|
|
decode(data) {
|
|
if (data.byteLength === 0) return "";
|
|
if (this.bytesNeeded === 0 && trailingIncomplete(data, 0) === 0) {
|
|
this.bytesSeen = trailingBytesSeen(data);
|
|
return b4a.toString(data, "utf8");
|
|
}
|
|
let result = "";
|
|
let start = 0;
|
|
if (this.bytesNeeded > 0) {
|
|
while (start < data.byteLength) {
|
|
const byte = data[start];
|
|
if (byte < this.lowerBoundary || byte > this.upperBoundary) {
|
|
result += "\uFFFD";
|
|
this._reset();
|
|
break;
|
|
}
|
|
this.lowerBoundary = 128;
|
|
this.upperBoundary = 191;
|
|
this.codePoint = this.codePoint << 6 | byte & 63;
|
|
this.bytesSeen++;
|
|
start++;
|
|
if (this.bytesSeen === this.bytesNeeded) {
|
|
result += String.fromCodePoint(this.codePoint);
|
|
this._reset();
|
|
break;
|
|
}
|
|
}
|
|
if (this.bytesNeeded > 0) return result;
|
|
}
|
|
const trailing = trailingIncomplete(data, start);
|
|
const end = data.byteLength - trailing;
|
|
if (end > start) result += b4a.toString(data, "utf8", start, end);
|
|
for (let i = end; i < data.byteLength; i++) {
|
|
const byte = data[i];
|
|
if (this.bytesNeeded === 0) {
|
|
if (byte <= 127) {
|
|
this.bytesSeen = 0;
|
|
result += String.fromCharCode(byte);
|
|
} else if (byte >= 194 && byte <= 223) {
|
|
this.bytesNeeded = 2;
|
|
this.bytesSeen = 1;
|
|
this.codePoint = byte & 31;
|
|
} else if (byte >= 224 && byte <= 239) {
|
|
if (byte === 224) this.lowerBoundary = 160;
|
|
else if (byte === 237) this.upperBoundary = 159;
|
|
this.bytesNeeded = 3;
|
|
this.bytesSeen = 1;
|
|
this.codePoint = byte & 15;
|
|
} else if (byte >= 240 && byte <= 244) {
|
|
if (byte === 240) this.lowerBoundary = 144;
|
|
else if (byte === 244) this.upperBoundary = 143;
|
|
this.bytesNeeded = 4;
|
|
this.bytesSeen = 1;
|
|
this.codePoint = byte & 7;
|
|
} else {
|
|
this.bytesSeen = 1;
|
|
result += "\uFFFD";
|
|
}
|
|
continue;
|
|
}
|
|
if (byte < this.lowerBoundary || byte > this.upperBoundary) {
|
|
result += "\uFFFD";
|
|
i--;
|
|
this._reset();
|
|
continue;
|
|
}
|
|
this.lowerBoundary = 128;
|
|
this.upperBoundary = 191;
|
|
this.codePoint = this.codePoint << 6 | byte & 63;
|
|
this.bytesSeen++;
|
|
if (this.bytesSeen === this.bytesNeeded) {
|
|
result += String.fromCodePoint(this.codePoint);
|
|
this._reset();
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
flush() {
|
|
const result = this.bytesNeeded > 0 ? "\uFFFD" : "";
|
|
this._reset();
|
|
return result;
|
|
}
|
|
_reset() {
|
|
this.codePoint = 0;
|
|
this.bytesNeeded = 0;
|
|
this.bytesSeen = 0;
|
|
this.lowerBoundary = 128;
|
|
this.upperBoundary = 191;
|
|
}
|
|
};
|
|
function trailingIncomplete(data, start) {
|
|
const len = data.byteLength;
|
|
if (len <= start) return 0;
|
|
const limit = Math.max(start, len - 4);
|
|
let i = len - 1;
|
|
while (i > limit && (data[i] & 192) === 128) i--;
|
|
if (i < start) return 0;
|
|
const byte = data[i];
|
|
let needed;
|
|
if (byte <= 127) return 0;
|
|
if (byte >= 194 && byte <= 223) needed = 2;
|
|
else if (byte >= 224 && byte <= 239) needed = 3;
|
|
else if (byte >= 240 && byte <= 244) needed = 4;
|
|
else return 0;
|
|
const available = len - i;
|
|
return available < needed ? available : 0;
|
|
}
|
|
function trailingBytesSeen(data) {
|
|
const len = data.byteLength;
|
|
if (len === 0) return 0;
|
|
const last = data[len - 1];
|
|
if (last <= 127) return 0;
|
|
if ((last & 192) !== 128) return 1;
|
|
const limit = Math.max(0, len - 4);
|
|
let i = len - 2;
|
|
while (i >= limit && (data[i] & 192) === 128) i--;
|
|
if (i < 0) return 1;
|
|
const first = data[i];
|
|
let needed;
|
|
if (first >= 194 && first <= 223) needed = 2;
|
|
else if (first >= 224 && first <= 239) needed = 3;
|
|
else if (first >= 240 && first <= 244) needed = 4;
|
|
else return 1;
|
|
if (len - i !== needed) return 1;
|
|
if (needed >= 3) {
|
|
const second = data[i + 1];
|
|
if (first === 224 && second < 160) return 1;
|
|
if (first === 237 && second > 159) return 1;
|
|
if (first === 240 && second < 144) return 1;
|
|
if (first === 244 && second > 143) return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/text-decoder/index.js
|
|
var require_text_decoder = __commonJS({
|
|
"../../node_modules/text-decoder/index.js"(exports, module) {
|
|
var PassThroughDecoder = require_pass_through_decoder();
|
|
var UTF8Decoder = require_utf8_decoder();
|
|
module.exports = class TextDecoder {
|
|
constructor(encoding = "utf8") {
|
|
this.encoding = normalizeEncoding(encoding);
|
|
switch (this.encoding) {
|
|
case "utf8":
|
|
this.decoder = new UTF8Decoder();
|
|
break;
|
|
case "utf16le":
|
|
case "base64":
|
|
throw new Error("Unsupported encoding: " + this.encoding);
|
|
default:
|
|
this.decoder = new PassThroughDecoder(this.encoding);
|
|
}
|
|
}
|
|
get remaining() {
|
|
return this.decoder.remaining;
|
|
}
|
|
push(data) {
|
|
if (typeof data === "string") return data;
|
|
return this.decoder.decode(data);
|
|
}
|
|
// For Node.js compatibility
|
|
write(data) {
|
|
return this.push(data);
|
|
}
|
|
end(data) {
|
|
let result = "";
|
|
if (data) result = this.push(data);
|
|
result += this.decoder.flush();
|
|
return result;
|
|
}
|
|
};
|
|
function normalizeEncoding(encoding) {
|
|
encoding = encoding.toLowerCase();
|
|
switch (encoding) {
|
|
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 encoding;
|
|
default:
|
|
throw new Error("Unknown encoding: " + encoding);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/streamx/index.js
|
|
var require_streamx = __commonJS({
|
|
"../../node_modules/streamx/index.js"(exports, module) {
|
|
var { EventEmitter } = require_default();
|
|
var STREAM_DESTROYED = new Error("Stream was destroyed");
|
|
var PREMATURE_CLOSE = new Error("Premature close");
|
|
var FIFO = require_fast_fifo();
|
|
var TextDecoder = require_text_decoder();
|
|
var qmt = typeof queueMicrotask === "undefined" ? (fn) => global.process.nextTick(fn) : queueMicrotask;
|
|
var MAX = (1 << 29) - 1;
|
|
var OPENING = 1;
|
|
var PREDESTROYING = 2;
|
|
var DESTROYING = 4;
|
|
var DESTROYED = 8;
|
|
var NOT_OPENING = MAX ^ OPENING;
|
|
var NOT_PREDESTROYING = MAX ^ PREDESTROYING;
|
|
var READ_ACTIVE = 1 << 4;
|
|
var READ_UPDATING = 2 << 4;
|
|
var READ_PRIMARY = 4 << 4;
|
|
var READ_QUEUED = 8 << 4;
|
|
var READ_RESUMED = 16 << 4;
|
|
var READ_PIPE_DRAINED = 32 << 4;
|
|
var READ_ENDING = 64 << 4;
|
|
var READ_EMIT_DATA = 128 << 4;
|
|
var READ_EMIT_READABLE = 256 << 4;
|
|
var READ_EMITTED_READABLE = 512 << 4;
|
|
var READ_DONE = 1024 << 4;
|
|
var READ_NEXT_TICK = 2048 << 4;
|
|
var READ_NEEDS_PUSH = 4096 << 4;
|
|
var READ_READ_AHEAD = 8192 << 4;
|
|
var READ_FLOWING = READ_RESUMED | READ_PIPE_DRAINED;
|
|
var READ_ACTIVE_AND_NEEDS_PUSH = READ_ACTIVE | READ_NEEDS_PUSH;
|
|
var READ_PRIMARY_AND_ACTIVE = READ_PRIMARY | READ_ACTIVE;
|
|
var READ_EMIT_READABLE_AND_QUEUED = READ_EMIT_READABLE | READ_QUEUED;
|
|
var READ_RESUMED_READ_AHEAD = READ_RESUMED | READ_READ_AHEAD;
|
|
var READ_NOT_ACTIVE = MAX ^ READ_ACTIVE;
|
|
var READ_NON_PRIMARY = MAX ^ READ_PRIMARY;
|
|
var READ_NON_PRIMARY_AND_PUSHED = MAX ^ (READ_PRIMARY | READ_NEEDS_PUSH);
|
|
var READ_PUSHED = MAX ^ READ_NEEDS_PUSH;
|
|
var READ_PAUSED = MAX ^ READ_RESUMED;
|
|
var READ_NOT_QUEUED = MAX ^ (READ_QUEUED | READ_EMITTED_READABLE);
|
|
var READ_NOT_ENDING = MAX ^ READ_ENDING;
|
|
var READ_PIPE_NOT_DRAINED = MAX ^ READ_FLOWING;
|
|
var READ_NOT_NEXT_TICK = MAX ^ READ_NEXT_TICK;
|
|
var READ_NOT_UPDATING = MAX ^ READ_UPDATING;
|
|
var READ_NO_READ_AHEAD = MAX ^ READ_READ_AHEAD;
|
|
var READ_PAUSED_NO_READ_AHEAD = MAX ^ READ_RESUMED_READ_AHEAD;
|
|
var WRITE_ACTIVE = 1 << 18;
|
|
var WRITE_UPDATING = 2 << 18;
|
|
var WRITE_PRIMARY = 4 << 18;
|
|
var WRITE_QUEUED = 8 << 18;
|
|
var WRITE_UNDRAINED = 16 << 18;
|
|
var WRITE_DONE = 32 << 18;
|
|
var WRITE_EMIT_DRAIN = 64 << 18;
|
|
var WRITE_NEXT_TICK = 128 << 18;
|
|
var WRITE_WRITING = 256 << 18;
|
|
var WRITE_FINISHING = 512 << 18;
|
|
var WRITE_CORKED = 1024 << 18;
|
|
var WRITE_NOT_ACTIVE = MAX ^ (WRITE_ACTIVE | WRITE_WRITING);
|
|
var WRITE_NON_PRIMARY = MAX ^ WRITE_PRIMARY;
|
|
var WRITE_NOT_FINISHING = MAX ^ (WRITE_ACTIVE | WRITE_FINISHING);
|
|
var WRITE_DRAINED = MAX ^ WRITE_UNDRAINED;
|
|
var WRITE_NOT_QUEUED = MAX ^ WRITE_QUEUED;
|
|
var WRITE_NOT_NEXT_TICK = MAX ^ WRITE_NEXT_TICK;
|
|
var WRITE_NOT_UPDATING = MAX ^ WRITE_UPDATING;
|
|
var WRITE_NOT_CORKED = MAX ^ WRITE_CORKED;
|
|
var ACTIVE = READ_ACTIVE | WRITE_ACTIVE;
|
|
var NOT_ACTIVE = MAX ^ ACTIVE;
|
|
var DONE = READ_DONE | WRITE_DONE;
|
|
var DESTROY_STATUS = DESTROYING | DESTROYED | PREDESTROYING;
|
|
var OPEN_STATUS = DESTROY_STATUS | OPENING;
|
|
var AUTO_DESTROY = DESTROY_STATUS | DONE;
|
|
var NON_PRIMARY = WRITE_NON_PRIMARY & READ_NON_PRIMARY;
|
|
var ACTIVE_OR_TICKING = WRITE_NEXT_TICK | READ_NEXT_TICK;
|
|
var TICKING = ACTIVE_OR_TICKING & NOT_ACTIVE;
|
|
var IS_OPENING = OPEN_STATUS | TICKING;
|
|
var READ_PRIMARY_STATUS = OPEN_STATUS | READ_ENDING | READ_DONE;
|
|
var READ_STATUS = OPEN_STATUS | READ_DONE | READ_QUEUED;
|
|
var READ_ENDING_STATUS = OPEN_STATUS | READ_ENDING | READ_QUEUED;
|
|
var READ_READABLE_STATUS = OPEN_STATUS | READ_EMIT_READABLE | READ_QUEUED | READ_EMITTED_READABLE;
|
|
var SHOULD_NOT_READ = OPEN_STATUS | READ_ACTIVE | READ_ENDING | READ_DONE | READ_NEEDS_PUSH | READ_READ_AHEAD;
|
|
var READ_BACKPRESSURE_STATUS = DESTROY_STATUS | READ_ENDING | READ_DONE;
|
|
var READ_UPDATE_SYNC_STATUS = READ_UPDATING | OPEN_STATUS | READ_NEXT_TICK | READ_PRIMARY;
|
|
var READ_NEXT_TICK_OR_OPENING = READ_NEXT_TICK | OPENING;
|
|
var WRITE_PRIMARY_STATUS = OPEN_STATUS | WRITE_FINISHING | WRITE_DONE;
|
|
var WRITE_QUEUED_AND_UNDRAINED = WRITE_QUEUED | WRITE_UNDRAINED;
|
|
var WRITE_QUEUED_AND_ACTIVE = WRITE_QUEUED | WRITE_ACTIVE;
|
|
var WRITE_DRAIN_STATUS = WRITE_QUEUED | WRITE_UNDRAINED | OPEN_STATUS | WRITE_ACTIVE;
|
|
var WRITE_STATUS = OPEN_STATUS | WRITE_ACTIVE | WRITE_QUEUED | WRITE_CORKED;
|
|
var WRITE_PRIMARY_AND_ACTIVE = WRITE_PRIMARY | WRITE_ACTIVE;
|
|
var WRITE_ACTIVE_AND_WRITING = WRITE_ACTIVE | WRITE_WRITING;
|
|
var WRITE_FINISHING_STATUS = OPEN_STATUS | WRITE_FINISHING | WRITE_QUEUED_AND_ACTIVE | WRITE_DONE;
|
|
var WRITE_BACKPRESSURE_STATUS = WRITE_UNDRAINED | DESTROY_STATUS | WRITE_FINISHING | WRITE_DONE;
|
|
var WRITE_UPDATE_SYNC_STATUS = WRITE_UPDATING | OPEN_STATUS | WRITE_NEXT_TICK | WRITE_PRIMARY;
|
|
var WRITE_DROP_DATA = WRITE_FINISHING | WRITE_DONE | DESTROY_STATUS;
|
|
var asyncIterator = Symbol.asyncIterator || Symbol("asyncIterator");
|
|
var WritableState = class {
|
|
constructor(stream, { highWaterMark = 16384, map = null, mapWritable, byteLength, byteLengthWritable } = {}) {
|
|
this.stream = stream;
|
|
this.queue = new FIFO();
|
|
this.highWaterMark = highWaterMark;
|
|
this.buffered = 0;
|
|
this.error = null;
|
|
this.pipeline = null;
|
|
this.drains = null;
|
|
this.byteLength = byteLengthWritable || byteLength || defaultByteLength;
|
|
this.map = mapWritable || map;
|
|
this.afterWrite = afterWrite.bind(this);
|
|
this.afterUpdateNextTick = updateWriteNT.bind(this);
|
|
}
|
|
get ending() {
|
|
return (this.stream._duplexState & WRITE_FINISHING) !== 0;
|
|
}
|
|
get ended() {
|
|
return (this.stream._duplexState & WRITE_DONE) !== 0;
|
|
}
|
|
push(data) {
|
|
if ((this.stream._duplexState & WRITE_DROP_DATA) !== 0) return false;
|
|
if (this.map !== null) data = this.map(data);
|
|
this.buffered += this.byteLength(data);
|
|
this.queue.push(data);
|
|
if (this.buffered < this.highWaterMark) {
|
|
this.stream._duplexState |= WRITE_QUEUED;
|
|
return true;
|
|
}
|
|
this.stream._duplexState |= WRITE_QUEUED_AND_UNDRAINED;
|
|
return false;
|
|
}
|
|
shift() {
|
|
const data = this.queue.shift();
|
|
this.buffered -= this.byteLength(data);
|
|
if (this.buffered === 0) this.stream._duplexState &= WRITE_NOT_QUEUED;
|
|
return data;
|
|
}
|
|
end(data) {
|
|
if (typeof data === "function") this.stream.once("finish", data);
|
|
else if (data !== void 0 && data !== null) this.push(data);
|
|
this.stream._duplexState = (this.stream._duplexState | WRITE_FINISHING) & WRITE_NON_PRIMARY;
|
|
}
|
|
autoBatch(data, cb) {
|
|
const buffer = [];
|
|
const stream = this.stream;
|
|
buffer.push(data);
|
|
while ((stream._duplexState & WRITE_STATUS) === WRITE_QUEUED_AND_ACTIVE) {
|
|
buffer.push(stream._writableState.shift());
|
|
}
|
|
if ((stream._duplexState & OPEN_STATUS) !== 0) return cb(null);
|
|
stream._writev(buffer, cb);
|
|
}
|
|
update() {
|
|
const stream = this.stream;
|
|
stream._duplexState |= WRITE_UPDATING;
|
|
do {
|
|
while ((stream._duplexState & WRITE_STATUS) === WRITE_QUEUED) {
|
|
const data = this.shift();
|
|
stream._duplexState |= WRITE_ACTIVE_AND_WRITING;
|
|
stream._write(data, this.afterWrite);
|
|
}
|
|
if ((stream._duplexState & WRITE_PRIMARY_AND_ACTIVE) === 0) this.updateNonPrimary();
|
|
} while (this.continueUpdate() === true);
|
|
stream._duplexState &= WRITE_NOT_UPDATING;
|
|
}
|
|
updateNonPrimary() {
|
|
const stream = this.stream;
|
|
if ((stream._duplexState & WRITE_FINISHING_STATUS) === WRITE_FINISHING) {
|
|
stream._duplexState = stream._duplexState | WRITE_ACTIVE;
|
|
stream._final(afterFinal.bind(this));
|
|
return;
|
|
}
|
|
if ((stream._duplexState & DESTROY_STATUS) === DESTROYING) {
|
|
if ((stream._duplexState & ACTIVE_OR_TICKING) === 0) {
|
|
stream._duplexState |= ACTIVE;
|
|
stream._destroy(afterDestroy.bind(this));
|
|
}
|
|
return;
|
|
}
|
|
if ((stream._duplexState & IS_OPENING) === OPENING) {
|
|
stream._duplexState = (stream._duplexState | ACTIVE) & NOT_OPENING;
|
|
stream._open(afterOpen.bind(this));
|
|
}
|
|
}
|
|
continueUpdate() {
|
|
if ((this.stream._duplexState & WRITE_NEXT_TICK) === 0) return false;
|
|
this.stream._duplexState &= WRITE_NOT_NEXT_TICK;
|
|
return true;
|
|
}
|
|
updateCallback() {
|
|
if ((this.stream._duplexState & WRITE_UPDATE_SYNC_STATUS) === WRITE_PRIMARY) this.update();
|
|
else this.updateNextTick();
|
|
}
|
|
updateNextTick() {
|
|
if ((this.stream._duplexState & WRITE_NEXT_TICK) !== 0) return;
|
|
this.stream._duplexState |= WRITE_NEXT_TICK;
|
|
if ((this.stream._duplexState & WRITE_UPDATING) === 0) qmt(this.afterUpdateNextTick);
|
|
}
|
|
};
|
|
var ReadableState = class {
|
|
constructor(stream, { highWaterMark = 16384, map = null, mapReadable, byteLength, byteLengthReadable } = {}) {
|
|
this.stream = stream;
|
|
this.queue = new FIFO();
|
|
this.highWaterMark = highWaterMark === 0 ? 1 : highWaterMark;
|
|
this.buffered = 0;
|
|
this.readAhead = highWaterMark > 0;
|
|
this.error = null;
|
|
this.pipeline = null;
|
|
this.byteLength = byteLengthReadable || byteLength || defaultByteLength;
|
|
this.map = mapReadable || map;
|
|
this.pipeTo = null;
|
|
this.afterRead = afterRead.bind(this);
|
|
this.afterUpdateNextTick = updateReadNT.bind(this);
|
|
}
|
|
get ending() {
|
|
return (this.stream._duplexState & READ_ENDING) !== 0;
|
|
}
|
|
get ended() {
|
|
return (this.stream._duplexState & READ_DONE) !== 0;
|
|
}
|
|
pipe(pipeTo, cb) {
|
|
if (this.pipeTo !== null) throw new Error("Can only pipe to one destination");
|
|
if (typeof cb !== "function") cb = null;
|
|
this.stream._duplexState |= READ_PIPE_DRAINED;
|
|
this.pipeTo = pipeTo;
|
|
this.pipeline = new Pipeline(this.stream, pipeTo, cb);
|
|
if (cb) this.stream.on("error", noop);
|
|
if (isStreamx(pipeTo)) {
|
|
pipeTo._writableState.pipeline = this.pipeline;
|
|
if (cb) pipeTo.on("error", noop);
|
|
pipeTo.on("finish", this.pipeline.finished.bind(this.pipeline));
|
|
} else {
|
|
const onerror = this.pipeline.done.bind(this.pipeline, pipeTo);
|
|
const onclose = this.pipeline.done.bind(this.pipeline, pipeTo, null);
|
|
pipeTo.on("error", onerror);
|
|
pipeTo.on("close", onclose);
|
|
pipeTo.on("finish", this.pipeline.finished.bind(this.pipeline));
|
|
}
|
|
pipeTo.on("drain", afterDrain.bind(this));
|
|
this.stream.emit("piping", pipeTo);
|
|
pipeTo.emit("pipe", this.stream);
|
|
}
|
|
push(data) {
|
|
const stream = this.stream;
|
|
if (data === null) {
|
|
this.highWaterMark = 0;
|
|
stream._duplexState = (stream._duplexState | READ_ENDING) & READ_NON_PRIMARY_AND_PUSHED;
|
|
return false;
|
|
}
|
|
if (this.map !== null) {
|
|
data = this.map(data);
|
|
if (data === null) {
|
|
stream._duplexState &= READ_PUSHED;
|
|
return this.buffered < this.highWaterMark;
|
|
}
|
|
}
|
|
this.buffered += this.byteLength(data);
|
|
this.queue.push(data);
|
|
stream._duplexState = (stream._duplexState | READ_QUEUED) & READ_PUSHED;
|
|
return this.buffered < this.highWaterMark;
|
|
}
|
|
shift() {
|
|
const data = this.queue.shift();
|
|
this.buffered -= this.byteLength(data);
|
|
if (this.buffered === 0) this.stream._duplexState &= READ_NOT_QUEUED;
|
|
return data;
|
|
}
|
|
unshift(data) {
|
|
const pending = [this.map !== null ? this.map(data) : data];
|
|
while (this.buffered > 0) pending.push(this.shift());
|
|
for (let i = 0; i < pending.length - 1; i++) {
|
|
const data2 = pending[i];
|
|
this.buffered += this.byteLength(data2);
|
|
this.queue.push(data2);
|
|
}
|
|
this.push(pending[pending.length - 1]);
|
|
}
|
|
read() {
|
|
const stream = this.stream;
|
|
if ((stream._duplexState & READ_STATUS) === READ_QUEUED) {
|
|
const data = this.shift();
|
|
if (this.pipeTo !== null && this.pipeTo.write(data) === false)
|
|
stream._duplexState &= READ_PIPE_NOT_DRAINED;
|
|
if ((stream._duplexState & READ_EMIT_DATA) !== 0) stream.emit("data", data);
|
|
return data;
|
|
}
|
|
if (this.readAhead === false) {
|
|
stream._duplexState |= READ_READ_AHEAD;
|
|
this.updateNextTick();
|
|
}
|
|
return null;
|
|
}
|
|
drain() {
|
|
const stream = this.stream;
|
|
while ((stream._duplexState & READ_STATUS) === READ_QUEUED && (stream._duplexState & READ_FLOWING) !== 0) {
|
|
const data = this.shift();
|
|
if (this.pipeTo !== null && this.pipeTo.write(data) === false)
|
|
stream._duplexState &= READ_PIPE_NOT_DRAINED;
|
|
if ((stream._duplexState & READ_EMIT_DATA) !== 0) stream.emit("data", data);
|
|
}
|
|
}
|
|
update() {
|
|
const stream = this.stream;
|
|
stream._duplexState |= READ_UPDATING;
|
|
do {
|
|
this.drain();
|
|
while (this.buffered < this.highWaterMark && (stream._duplexState & SHOULD_NOT_READ) === READ_READ_AHEAD) {
|
|
stream._duplexState |= READ_ACTIVE_AND_NEEDS_PUSH;
|
|
stream._read(this.afterRead);
|
|
this.drain();
|
|
}
|
|
if ((stream._duplexState & READ_READABLE_STATUS) === READ_EMIT_READABLE_AND_QUEUED) {
|
|
stream._duplexState |= READ_EMITTED_READABLE;
|
|
stream.emit("readable");
|
|
}
|
|
if ((stream._duplexState & READ_PRIMARY_AND_ACTIVE) === 0) this.updateNonPrimary();
|
|
} while (this.continueUpdate() === true);
|
|
stream._duplexState &= READ_NOT_UPDATING;
|
|
}
|
|
updateNonPrimary() {
|
|
const stream = this.stream;
|
|
if ((stream._duplexState & READ_ENDING_STATUS) === READ_ENDING) {
|
|
stream._duplexState = (stream._duplexState | READ_DONE) & READ_NOT_ENDING;
|
|
stream.emit("end");
|
|
if ((stream._duplexState & AUTO_DESTROY) === DONE) stream._duplexState |= DESTROYING;
|
|
if (this.pipeTo !== null) this.pipeTo.end();
|
|
}
|
|
if ((stream._duplexState & DESTROY_STATUS) === DESTROYING) {
|
|
if ((stream._duplexState & ACTIVE_OR_TICKING) === 0) {
|
|
stream._duplexState |= ACTIVE;
|
|
stream._destroy(afterDestroy.bind(this));
|
|
}
|
|
return;
|
|
}
|
|
if ((stream._duplexState & IS_OPENING) === OPENING) {
|
|
stream._duplexState = (stream._duplexState | ACTIVE) & NOT_OPENING;
|
|
stream._open(afterOpen.bind(this));
|
|
}
|
|
}
|
|
continueUpdate() {
|
|
if ((this.stream._duplexState & READ_NEXT_TICK) === 0) return false;
|
|
this.stream._duplexState &= READ_NOT_NEXT_TICK;
|
|
return true;
|
|
}
|
|
updateCallback() {
|
|
if ((this.stream._duplexState & READ_UPDATE_SYNC_STATUS) === READ_PRIMARY) this.update();
|
|
else this.updateNextTick();
|
|
}
|
|
updateNextTickIfOpen() {
|
|
if ((this.stream._duplexState & READ_NEXT_TICK_OR_OPENING) !== 0) return;
|
|
this.stream._duplexState |= READ_NEXT_TICK;
|
|
if ((this.stream._duplexState & READ_UPDATING) === 0) qmt(this.afterUpdateNextTick);
|
|
}
|
|
updateNextTick() {
|
|
if ((this.stream._duplexState & READ_NEXT_TICK) !== 0) return;
|
|
this.stream._duplexState |= READ_NEXT_TICK;
|
|
if ((this.stream._duplexState & READ_UPDATING) === 0) qmt(this.afterUpdateNextTick);
|
|
}
|
|
};
|
|
var TransformState = class {
|
|
constructor(stream) {
|
|
this.data = null;
|
|
this.afterTransform = afterTransform.bind(stream);
|
|
this.afterFinal = null;
|
|
}
|
|
};
|
|
var Pipeline = class {
|
|
constructor(src, dst, cb) {
|
|
this.from = src;
|
|
this.to = dst;
|
|
this.afterPipe = cb;
|
|
this.error = null;
|
|
this.pipeToFinished = false;
|
|
}
|
|
finished() {
|
|
this.pipeToFinished = true;
|
|
}
|
|
done(stream, err) {
|
|
if (err) this.error = err;
|
|
if (stream === this.to) {
|
|
this.to = null;
|
|
if (this.from !== null) {
|
|
if ((this.from._duplexState & READ_DONE) === 0 || !this.pipeToFinished) {
|
|
this.from.destroy(this.error || new Error("Writable stream closed prematurely"));
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
if (stream === this.from) {
|
|
this.from = null;
|
|
if (this.to !== null) {
|
|
if ((stream._duplexState & READ_DONE) === 0) {
|
|
this.to.destroy(this.error || new Error("Readable stream closed before ending"));
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
if (this.afterPipe !== null) this.afterPipe(this.error);
|
|
this.to = this.from = this.afterPipe = null;
|
|
}
|
|
};
|
|
function afterDrain() {
|
|
this.stream._duplexState |= READ_PIPE_DRAINED;
|
|
this.updateCallback();
|
|
}
|
|
function afterFinal(err) {
|
|
const stream = this.stream;
|
|
if (err) stream.destroy(err);
|
|
if ((stream._duplexState & DESTROY_STATUS) === 0) {
|
|
stream._duplexState |= WRITE_DONE;
|
|
stream.emit("finish");
|
|
}
|
|
if ((stream._duplexState & AUTO_DESTROY) === DONE) {
|
|
stream._duplexState |= DESTROYING;
|
|
}
|
|
stream._duplexState &= WRITE_NOT_FINISHING;
|
|
if ((stream._duplexState & WRITE_UPDATING) === 0) this.update();
|
|
else this.updateNextTick();
|
|
}
|
|
function afterDestroy(err) {
|
|
const stream = this.stream;
|
|
if (!err && this.error !== STREAM_DESTROYED) err = this.error;
|
|
if (err) stream.emit("error", err);
|
|
stream._duplexState |= DESTROYED;
|
|
stream.emit("close");
|
|
const rs = stream._readableState;
|
|
const ws = stream._writableState;
|
|
if (rs !== null && rs.pipeline !== null) rs.pipeline.done(stream, err);
|
|
if (ws !== null) {
|
|
while (ws.drains !== null && ws.drains.length > 0) ws.drains.shift().resolve(false);
|
|
if (ws.pipeline !== null) ws.pipeline.done(stream, err);
|
|
}
|
|
}
|
|
function afterWrite(err) {
|
|
const stream = this.stream;
|
|
if (err) stream.destroy(err);
|
|
stream._duplexState &= WRITE_NOT_ACTIVE;
|
|
if (this.drains !== null) tickDrains(this.drains);
|
|
if ((stream._duplexState & WRITE_DRAIN_STATUS) === WRITE_UNDRAINED) {
|
|
stream._duplexState &= WRITE_DRAINED;
|
|
if ((stream._duplexState & WRITE_EMIT_DRAIN) === WRITE_EMIT_DRAIN) {
|
|
stream.emit("drain");
|
|
}
|
|
}
|
|
this.updateCallback();
|
|
}
|
|
function afterRead(err) {
|
|
if (err) this.stream.destroy(err);
|
|
this.stream._duplexState &= READ_NOT_ACTIVE;
|
|
if (this.readAhead === false && (this.stream._duplexState & READ_RESUMED) === 0)
|
|
this.stream._duplexState &= READ_NO_READ_AHEAD;
|
|
this.updateCallback();
|
|
}
|
|
function updateReadNT() {
|
|
if ((this.stream._duplexState & READ_UPDATING) === 0) {
|
|
this.stream._duplexState &= READ_NOT_NEXT_TICK;
|
|
this.update();
|
|
}
|
|
}
|
|
function updateWriteNT() {
|
|
if ((this.stream._duplexState & WRITE_UPDATING) === 0) {
|
|
this.stream._duplexState &= WRITE_NOT_NEXT_TICK;
|
|
this.update();
|
|
}
|
|
}
|
|
function tickDrains(drains) {
|
|
for (let i = 0; i < drains.length; i++) {
|
|
if (--drains[i].writes === 0) {
|
|
drains.shift().resolve(true);
|
|
i--;
|
|
}
|
|
}
|
|
}
|
|
function afterOpen(err) {
|
|
const stream = this.stream;
|
|
if (err) stream.destroy(err);
|
|
if ((stream._duplexState & DESTROYING) === 0) {
|
|
if ((stream._duplexState & READ_PRIMARY_STATUS) === 0) stream._duplexState |= READ_PRIMARY;
|
|
if ((stream._duplexState & WRITE_PRIMARY_STATUS) === 0) stream._duplexState |= WRITE_PRIMARY;
|
|
stream.emit("open");
|
|
}
|
|
stream._duplexState &= NOT_ACTIVE;
|
|
if (stream._writableState !== null) {
|
|
stream._writableState.updateCallback();
|
|
}
|
|
if (stream._readableState !== null) {
|
|
stream._readableState.updateCallback();
|
|
}
|
|
}
|
|
function afterTransform(err, data) {
|
|
if (data !== void 0 && data !== null) this.push(data);
|
|
this._writableState.afterWrite(err);
|
|
}
|
|
function newListener(name) {
|
|
if (this._readableState !== null) {
|
|
if (name === "data") {
|
|
this._duplexState |= READ_EMIT_DATA | READ_RESUMED_READ_AHEAD;
|
|
this._readableState.updateNextTick();
|
|
}
|
|
if (name === "readable") {
|
|
this._duplexState |= READ_EMIT_READABLE;
|
|
this._readableState.updateNextTick();
|
|
}
|
|
}
|
|
if (this._writableState !== null) {
|
|
if (name === "drain") {
|
|
this._duplexState |= WRITE_EMIT_DRAIN;
|
|
this._writableState.updateNextTick();
|
|
}
|
|
}
|
|
}
|
|
var Stream = class extends EventEmitter {
|
|
constructor(opts) {
|
|
super();
|
|
this._duplexState = 0;
|
|
this._readableState = null;
|
|
this._writableState = null;
|
|
if (opts) {
|
|
if (opts.open) this._open = opts.open;
|
|
if (opts.destroy) this._destroy = opts.destroy;
|
|
if (opts.predestroy) this._predestroy = opts.predestroy;
|
|
if (opts.signal) {
|
|
opts.signal.addEventListener("abort", abort.bind(this));
|
|
}
|
|
}
|
|
this.on("newListener", newListener);
|
|
}
|
|
_open(cb) {
|
|
cb(null);
|
|
}
|
|
_destroy(cb) {
|
|
cb(null);
|
|
}
|
|
_predestroy() {
|
|
}
|
|
get readable() {
|
|
return this._readableState !== null ? true : void 0;
|
|
}
|
|
get writable() {
|
|
return this._writableState !== null ? true : void 0;
|
|
}
|
|
get destroyed() {
|
|
return (this._duplexState & DESTROYED) !== 0;
|
|
}
|
|
get destroying() {
|
|
return (this._duplexState & DESTROY_STATUS) !== 0;
|
|
}
|
|
destroy(err) {
|
|
if ((this._duplexState & DESTROY_STATUS) === 0) {
|
|
if (!err) err = STREAM_DESTROYED;
|
|
this._duplexState = (this._duplexState | DESTROYING) & NON_PRIMARY;
|
|
if (this._readableState !== null) {
|
|
this._readableState.highWaterMark = 0;
|
|
this._readableState.error = err;
|
|
}
|
|
if (this._writableState !== null) {
|
|
this._writableState.highWaterMark = 0;
|
|
this._writableState.error = err;
|
|
}
|
|
this._duplexState |= PREDESTROYING;
|
|
this._predestroy();
|
|
this._duplexState &= NOT_PREDESTROYING;
|
|
if (this._readableState !== null) this._readableState.updateNextTick();
|
|
if (this._writableState !== null) this._writableState.updateNextTick();
|
|
}
|
|
}
|
|
};
|
|
var Readable = class _Readable extends Stream {
|
|
constructor(opts) {
|
|
super(opts);
|
|
this._duplexState |= OPENING | WRITE_DONE | READ_READ_AHEAD;
|
|
this._readableState = new ReadableState(this, opts);
|
|
if (opts) {
|
|
if (this._readableState.readAhead === false) this._duplexState &= READ_NO_READ_AHEAD;
|
|
if (opts.read) this._read = opts.read;
|
|
if (opts.eagerOpen) this._readableState.updateNextTick();
|
|
if (opts.encoding) this.setEncoding(opts.encoding);
|
|
}
|
|
}
|
|
setEncoding(encoding) {
|
|
const dec = new TextDecoder(encoding);
|
|
const map = this._readableState.map || echo;
|
|
this._readableState.map = mapOrSkip;
|
|
return this;
|
|
function mapOrSkip(data) {
|
|
const next = dec.push(data);
|
|
return next === "" && (data.byteLength !== 0 || dec.remaining > 0) ? null : map(next);
|
|
}
|
|
}
|
|
_read(cb) {
|
|
cb(null);
|
|
}
|
|
pipe(dest, cb) {
|
|
this._readableState.updateNextTick();
|
|
this._readableState.pipe(dest, cb);
|
|
return dest;
|
|
}
|
|
read() {
|
|
this._readableState.updateNextTick();
|
|
return this._readableState.read();
|
|
}
|
|
push(data) {
|
|
this._readableState.updateNextTickIfOpen();
|
|
return this._readableState.push(data);
|
|
}
|
|
unshift(data) {
|
|
this._readableState.updateNextTickIfOpen();
|
|
return this._readableState.unshift(data);
|
|
}
|
|
resume() {
|
|
this._duplexState |= READ_RESUMED_READ_AHEAD;
|
|
this._readableState.updateNextTick();
|
|
return this;
|
|
}
|
|
pause() {
|
|
this._duplexState &= this._readableState.readAhead === false ? READ_PAUSED_NO_READ_AHEAD : READ_PAUSED;
|
|
return this;
|
|
}
|
|
static _fromAsyncIterator(ite, opts) {
|
|
let destroy;
|
|
const rs = new _Readable({
|
|
...opts,
|
|
read(cb) {
|
|
ite.next().then(push).then(cb.bind(null, null)).catch(cb);
|
|
},
|
|
predestroy() {
|
|
destroy = ite.return();
|
|
},
|
|
destroy(cb) {
|
|
if (!destroy) return cb(null);
|
|
destroy.then(cb.bind(null, null)).catch(cb);
|
|
}
|
|
});
|
|
return rs;
|
|
function push(data) {
|
|
if (data.done) rs.push(null);
|
|
else rs.push(data.value);
|
|
}
|
|
}
|
|
static from(data, opts) {
|
|
if (isReadStreamx(data)) return data;
|
|
if (data[asyncIterator]) return this._fromAsyncIterator(data[asyncIterator](), opts);
|
|
if (!Array.isArray(data)) data = data === void 0 ? [] : [data];
|
|
let i = 0;
|
|
return new _Readable({
|
|
...opts,
|
|
read(cb) {
|
|
this.push(i === data.length ? null : data[i++]);
|
|
cb(null);
|
|
}
|
|
});
|
|
}
|
|
static isBackpressured(rs) {
|
|
return (rs._duplexState & READ_BACKPRESSURE_STATUS) !== 0 || rs._readableState.buffered >= rs._readableState.highWaterMark;
|
|
}
|
|
static isPaused(rs) {
|
|
return (rs._duplexState & READ_RESUMED) === 0;
|
|
}
|
|
[asyncIterator]() {
|
|
const stream = this;
|
|
let error = null;
|
|
let promiseResolve = null;
|
|
let promiseReject = null;
|
|
this.on("error", (err) => {
|
|
error = err;
|
|
});
|
|
this.on("readable", onreadable);
|
|
this.on("close", onclose);
|
|
return {
|
|
[asyncIterator]() {
|
|
return this;
|
|
},
|
|
next() {
|
|
return new Promise(function(resolve, reject) {
|
|
promiseResolve = resolve;
|
|
promiseReject = reject;
|
|
const data = stream.read();
|
|
if (data !== null) ondata(data);
|
|
else if ((stream._duplexState & DESTROYED) !== 0) ondata(null);
|
|
});
|
|
},
|
|
return() {
|
|
return destroy(null);
|
|
},
|
|
throw(err) {
|
|
return destroy(err);
|
|
}
|
|
};
|
|
function onreadable() {
|
|
if (promiseResolve !== null) ondata(stream.read());
|
|
}
|
|
function onclose() {
|
|
if (promiseResolve !== null) ondata(null);
|
|
}
|
|
function ondata(data) {
|
|
if (promiseReject === null) return;
|
|
if (error) promiseReject(error);
|
|
else if (data === null && (stream._duplexState & READ_DONE) === 0)
|
|
promiseReject(STREAM_DESTROYED);
|
|
else promiseResolve({ value: data, done: data === null });
|
|
promiseReject = promiseResolve = null;
|
|
}
|
|
function destroy(err) {
|
|
stream.destroy(err);
|
|
return new Promise((resolve, reject) => {
|
|
if (stream._duplexState & DESTROYED) return resolve({ value: void 0, done: true });
|
|
stream.once("close", function() {
|
|
if (err) reject(err);
|
|
else resolve({ value: void 0, done: true });
|
|
});
|
|
});
|
|
}
|
|
}
|
|
};
|
|
var Writable = class extends Stream {
|
|
constructor(opts) {
|
|
super(opts);
|
|
this._duplexState |= OPENING | READ_DONE;
|
|
this._writableState = new WritableState(this, opts);
|
|
if (opts) {
|
|
if (opts.writev) this._writev = opts.writev;
|
|
if (opts.write) this._write = opts.write;
|
|
if (opts.final) this._final = opts.final;
|
|
if (opts.eagerOpen) this._writableState.updateNextTick();
|
|
}
|
|
}
|
|
cork() {
|
|
this._duplexState |= WRITE_CORKED;
|
|
}
|
|
uncork() {
|
|
this._duplexState &= WRITE_NOT_CORKED;
|
|
this._writableState.updateNextTick();
|
|
}
|
|
_writev(batch, cb) {
|
|
cb(null);
|
|
}
|
|
_write(data, cb) {
|
|
this._writableState.autoBatch(data, cb);
|
|
}
|
|
_final(cb) {
|
|
cb(null);
|
|
}
|
|
static isBackpressured(ws) {
|
|
return (ws._duplexState & WRITE_BACKPRESSURE_STATUS) !== 0;
|
|
}
|
|
static drained(ws) {
|
|
if (ws.destroyed) return Promise.resolve(false);
|
|
const state = ws._writableState;
|
|
const pending = isWritev(ws) ? Math.min(1, state.queue.length) : state.queue.length;
|
|
const writes = pending + (ws._duplexState & WRITE_WRITING ? 1 : 0);
|
|
if (writes === 0) return Promise.resolve(true);
|
|
if (state.drains === null) state.drains = [];
|
|
return new Promise((resolve) => {
|
|
state.drains.push({ writes, resolve });
|
|
});
|
|
}
|
|
write(data) {
|
|
this._writableState.updateNextTick();
|
|
return this._writableState.push(data);
|
|
}
|
|
end(data) {
|
|
this._writableState.updateNextTick();
|
|
this._writableState.end(data);
|
|
return this;
|
|
}
|
|
};
|
|
var Duplex = class extends Readable {
|
|
// and Writable
|
|
constructor(opts) {
|
|
super(opts);
|
|
this._duplexState = OPENING | this._duplexState & READ_READ_AHEAD;
|
|
this._writableState = new WritableState(this, opts);
|
|
if (opts) {
|
|
if (opts.writev) this._writev = opts.writev;
|
|
if (opts.write) this._write = opts.write;
|
|
if (opts.final) this._final = opts.final;
|
|
}
|
|
}
|
|
cork() {
|
|
this._duplexState |= WRITE_CORKED;
|
|
}
|
|
uncork() {
|
|
this._duplexState &= WRITE_NOT_CORKED;
|
|
this._writableState.updateNextTick();
|
|
}
|
|
_writev(batch, cb) {
|
|
cb(null);
|
|
}
|
|
_write(data, cb) {
|
|
this._writableState.autoBatch(data, cb);
|
|
}
|
|
_final(cb) {
|
|
cb(null);
|
|
}
|
|
write(data) {
|
|
this._writableState.updateNextTick();
|
|
return this._writableState.push(data);
|
|
}
|
|
end(data) {
|
|
this._writableState.updateNextTick();
|
|
this._writableState.end(data);
|
|
return this;
|
|
}
|
|
};
|
|
var Transform = class extends Duplex {
|
|
constructor(opts) {
|
|
super(opts);
|
|
this._transformState = new TransformState(this);
|
|
if (opts) {
|
|
if (opts.transform) this._transform = opts.transform;
|
|
if (opts.flush) this._flush = opts.flush;
|
|
}
|
|
}
|
|
_write(data, cb) {
|
|
if (this._readableState.buffered >= this._readableState.highWaterMark) {
|
|
this._transformState.data = data;
|
|
} else {
|
|
this._transform(data, this._transformState.afterTransform);
|
|
}
|
|
}
|
|
_read(cb) {
|
|
if (this._transformState.data !== null) {
|
|
const data = this._transformState.data;
|
|
this._transformState.data = null;
|
|
cb(null);
|
|
this._transform(data, this._transformState.afterTransform);
|
|
} else {
|
|
cb(null);
|
|
}
|
|
}
|
|
destroy(err) {
|
|
super.destroy(err);
|
|
if (this._transformState.data !== null) {
|
|
this._transformState.data = null;
|
|
this._transformState.afterTransform();
|
|
}
|
|
}
|
|
_transform(data, cb) {
|
|
cb(null, data);
|
|
}
|
|
_flush(cb) {
|
|
cb(null);
|
|
}
|
|
_final(cb) {
|
|
this._transformState.afterFinal = cb;
|
|
this._flush(transformAfterFlush.bind(this));
|
|
}
|
|
};
|
|
var PassThrough = class extends Transform {
|
|
};
|
|
function transformAfterFlush(err, data) {
|
|
const cb = this._transformState.afterFinal;
|
|
if (err) return cb(err);
|
|
if (data !== null && data !== void 0) this.push(data);
|
|
this.push(null);
|
|
cb(null);
|
|
}
|
|
function pipelinePromise(...streams) {
|
|
return new Promise((resolve, reject) => {
|
|
return pipeline(...streams, (err) => {
|
|
if (err) return reject(err);
|
|
resolve();
|
|
});
|
|
});
|
|
}
|
|
function pipeline(stream, ...streams) {
|
|
const all = Array.isArray(stream) ? [...stream, ...streams] : [stream, ...streams];
|
|
const done = all.length && typeof all[all.length - 1] === "function" ? all.pop() : null;
|
|
if (all.length < 2) throw new Error("Pipeline requires at least 2 streams");
|
|
let src = all[0];
|
|
let dest = null;
|
|
let error = null;
|
|
for (let i = 1; i < all.length; i++) {
|
|
dest = all[i];
|
|
if (isStreamx(src)) {
|
|
src.pipe(dest, onerror);
|
|
} else {
|
|
errorHandle(src, true, i > 1, onerror);
|
|
src.pipe(dest);
|
|
}
|
|
src = dest;
|
|
}
|
|
if (done) {
|
|
let fin = false;
|
|
const autoDestroy = isStreamx(dest) || !!(dest._writableState && dest._writableState.autoDestroy);
|
|
dest.on("error", (err) => {
|
|
if (error === null) error = err;
|
|
});
|
|
dest.on("finish", () => {
|
|
fin = true;
|
|
if (!autoDestroy) done(error);
|
|
});
|
|
if (autoDestroy) {
|
|
dest.on("close", () => done(error || (fin ? null : PREMATURE_CLOSE)));
|
|
}
|
|
}
|
|
return dest;
|
|
function errorHandle(s, rd, wr, onerror2) {
|
|
s.on("error", onerror2);
|
|
s.on("close", onclose);
|
|
function onclose() {
|
|
if (rd && s._readableState && !s._readableState.ended) return onerror2(PREMATURE_CLOSE);
|
|
if (wr && s._writableState && !s._writableState.ended) return onerror2(PREMATURE_CLOSE);
|
|
}
|
|
}
|
|
function onerror(err) {
|
|
if (!err || error) return;
|
|
error = err;
|
|
for (const s of all) {
|
|
s.destroy(err);
|
|
}
|
|
}
|
|
}
|
|
function echo(s) {
|
|
return s;
|
|
}
|
|
function isStream(stream) {
|
|
return !!stream._readableState || !!stream._writableState;
|
|
}
|
|
function isStreamx(stream) {
|
|
return typeof stream._duplexState === "number" && isStream(stream);
|
|
}
|
|
function isEnding(stream) {
|
|
return !!stream._readableState && stream._readableState.ending;
|
|
}
|
|
function isEnded(stream) {
|
|
return !!stream._readableState && stream._readableState.ended;
|
|
}
|
|
function isFinishing(stream) {
|
|
return !!stream._writableState && stream._writableState.ending;
|
|
}
|
|
function isFinished(stream) {
|
|
return !!stream._writableState && stream._writableState.ended;
|
|
}
|
|
function getStreamError(stream, opts = {}) {
|
|
const err = stream._readableState && stream._readableState.error || stream._writableState && stream._writableState.error;
|
|
return !opts.all && err === STREAM_DESTROYED ? null : err;
|
|
}
|
|
function isReadStreamx(stream) {
|
|
return isStreamx(stream) && stream.readable;
|
|
}
|
|
function isDisturbed(stream) {
|
|
return (stream._duplexState & OPENING) !== OPENING || (stream._duplexState & DESTROYING) === DESTROYING || (stream._duplexState & ACTIVE_OR_TICKING) !== 0;
|
|
}
|
|
function isTypedArray(data) {
|
|
return typeof data === "object" && data !== null && typeof data.byteLength === "number";
|
|
}
|
|
function defaultByteLength(data) {
|
|
return isTypedArray(data) ? data.byteLength : 1024;
|
|
}
|
|
function noop() {
|
|
}
|
|
function abort() {
|
|
this.destroy(new Error("Stream aborted."));
|
|
}
|
|
function isWritev(s) {
|
|
return s._writev !== Writable.prototype._writev && s._writev !== Duplex.prototype._writev;
|
|
}
|
|
module.exports = {
|
|
pipeline,
|
|
pipelinePromise,
|
|
isStream,
|
|
isStreamx,
|
|
isEnding,
|
|
isEnded,
|
|
isFinishing,
|
|
isFinished,
|
|
isDisturbed,
|
|
getStreamError,
|
|
Stream,
|
|
Writable,
|
|
Readable,
|
|
Duplex,
|
|
Transform,
|
|
// Export PassThrough for compatibility with Node.js core's stream module
|
|
PassThrough
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/teex/index.js
|
|
var require_teex = __commonJS({
|
|
"../../node_modules/teex/index.js"(exports, module) {
|
|
var { Readable } = require_streamx();
|
|
module.exports = function(s, forks = 2) {
|
|
const streams = new Array(forks);
|
|
const status = new Array(forks).fill(true);
|
|
let ended = false;
|
|
for (let i = 0; i < forks; i++) {
|
|
streams[i] = new Readable({
|
|
read(cb) {
|
|
const check = !status[i];
|
|
status[i] = true;
|
|
if (check && allReadable()) s.resume();
|
|
cb(null);
|
|
}
|
|
});
|
|
}
|
|
s.on("end", function() {
|
|
ended = true;
|
|
for (const stream of streams) stream.push(null);
|
|
});
|
|
s.on("error", function(err) {
|
|
for (const stream of streams) stream.destroy(err);
|
|
});
|
|
s.on("close", function() {
|
|
if (ended) return;
|
|
for (const stream of streams) stream.destroy();
|
|
});
|
|
s.on("data", function(data) {
|
|
let needsPause = false;
|
|
for (let i = 0; i < streams.length; i++) {
|
|
if (!(status[i] = streams[i].push(data))) {
|
|
needsPause = true;
|
|
}
|
|
}
|
|
if (needsPause) s.pause();
|
|
});
|
|
return streams;
|
|
function allReadable() {
|
|
for (let j = 0; j < status.length; j++) {
|
|
if (!status[j]) return false;
|
|
}
|
|
return true;
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-stream/web.js
|
|
var require_web = __commonJS({
|
|
"../../node_modules/bare-stream/web.js"(exports) {
|
|
var { Readable, Writable, Transform, getStreamError, isStreamx, isDisturbed } = require_streamx();
|
|
var tee = require_teex();
|
|
var readableKind = Symbol.for("bare.stream.readable.kind");
|
|
var writableKind = Symbol.for("bare.stream.writable.kind");
|
|
var transformKind = Symbol.for("bare.stream.transform.kind");
|
|
exports.ReadableStreamDefaultReader = class ReadableStreamDefaultReader {
|
|
constructor(stream) {
|
|
this._stream = stream;
|
|
this._stream._stream.once("close", onclose).once("error", onerror);
|
|
const closed = Promise.withResolvers();
|
|
closed.promise.catch(noop);
|
|
this._closed = closed;
|
|
function onclose() {
|
|
closed.resolve();
|
|
}
|
|
function onerror(err) {
|
|
closed.reject(err);
|
|
}
|
|
}
|
|
get closed() {
|
|
return this._closed.promise;
|
|
}
|
|
read() {
|
|
const stream = this._stream._stream;
|
|
return new Promise((resolve, reject) => {
|
|
const err = getStreamError(stream);
|
|
if (err) return reject(err);
|
|
if (stream.destroyed) {
|
|
return resolve({ value: void 0, done: true });
|
|
}
|
|
const value = stream.read();
|
|
if (value !== null) {
|
|
return resolve({ value, done: false });
|
|
}
|
|
stream.once("readable", onreadable).once("close", onclose).once("error", onerror);
|
|
function onreadable() {
|
|
const value2 = stream.read();
|
|
ondone(null, value2 === null ? { value: void 0, done: true } : { value: value2, done: false });
|
|
}
|
|
function onclose() {
|
|
ondone(null, { value: void 0, done: true });
|
|
}
|
|
function onerror(err2) {
|
|
ondone(err2, null);
|
|
}
|
|
function ondone(err2, value2) {
|
|
stream.off("readable", onreadable).off("close", onclose).off("error", onerror);
|
|
if (err2) reject(err2);
|
|
else resolve(value2);
|
|
}
|
|
});
|
|
}
|
|
releaseLock() {
|
|
this._closed.reject(new TypeError("Reader was released"));
|
|
this._stream._releaseLock();
|
|
this._stream = null;
|
|
}
|
|
cancel(reason = new TypeError("Stream was cancelled")) {
|
|
const stream = this._stream._stream;
|
|
if (stream.destroyed) return Promise.resolve();
|
|
return new Promise(
|
|
(resolve) => stream.once("close", resolve).once("error", noop).destroy(reason)
|
|
);
|
|
}
|
|
};
|
|
exports.ReadableStreamDefaultController = class ReadableStreamDefaultController {
|
|
constructor(stream) {
|
|
this._stream = stream;
|
|
}
|
|
get desiredSize() {
|
|
const stream = this._stream._stream;
|
|
return stream._readableState.highWaterMark - stream._readableState.buffered;
|
|
}
|
|
enqueue(data) {
|
|
this._stream._stream.push(data);
|
|
}
|
|
close() {
|
|
this._stream._stream.push(null);
|
|
}
|
|
error(err) {
|
|
this._stream._stream.destroy(err);
|
|
}
|
|
};
|
|
var ReadableStream = class _ReadableStream {
|
|
static get [readableKind]() {
|
|
return 0;
|
|
}
|
|
static from(iterable) {
|
|
return new _ReadableStream(Readable.from(iterable));
|
|
}
|
|
constructor(underlyingSource = {}, queuingStrategy) {
|
|
if (isStreamx(underlyingSource)) {
|
|
this._stream = underlyingSource;
|
|
} else {
|
|
if (queuingStrategy === void 0) {
|
|
queuingStrategy = new exports.CountQueuingStrategy();
|
|
}
|
|
const { start, pull, cancel } = underlyingSource;
|
|
const { highWaterMark = 1, size = defaultSize } = queuingStrategy;
|
|
this._stream = new Readable({ highWaterMark, byteLength: size });
|
|
const controller = new exports.ReadableStreamDefaultController(this);
|
|
if (start) {
|
|
this._stream._open = this._open.bind(this, start.call(this, controller));
|
|
}
|
|
if (pull) {
|
|
this._stream._read = this._read.bind(this, pull.bind(this, controller));
|
|
}
|
|
if (cancel) {
|
|
this._stream.once("error", cancel);
|
|
}
|
|
}
|
|
this._reader = null;
|
|
}
|
|
get [readableKind]() {
|
|
return _ReadableStream[readableKind];
|
|
}
|
|
get locked() {
|
|
return this._reader !== null;
|
|
}
|
|
getReader() {
|
|
if (this.locked) throw new TypeError("Stream is locked");
|
|
this._reader = new exports.ReadableStreamDefaultReader(this);
|
|
return this._reader;
|
|
}
|
|
cancel(reason = new TypeError("Stream was cancelled")) {
|
|
const stream = this._stream;
|
|
if (stream.destroyed) return Promise.resolve();
|
|
if (this.locked) return Promise.reject(new TypeError("Stream is locked"));
|
|
return new Promise(
|
|
(resolve) => stream.once("close", resolve).once("error", noop).destroy(reason)
|
|
);
|
|
}
|
|
tee() {
|
|
const [a, b] = tee(this._stream);
|
|
return [new _ReadableStream(a), new _ReadableStream(b)];
|
|
}
|
|
pipeTo(destination) {
|
|
return new Promise(
|
|
(resolve, reject) => this._stream.pipe(destination._stream, (err) => {
|
|
err ? reject(err) : resolve();
|
|
})
|
|
);
|
|
}
|
|
[Symbol.asyncIterator]() {
|
|
return this._stream[Symbol.asyncIterator]();
|
|
}
|
|
_releaseLock() {
|
|
this._reader = null;
|
|
}
|
|
async _open(starting, cb) {
|
|
let err = null;
|
|
try {
|
|
await starting;
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
cb(err);
|
|
}
|
|
async _read(pull, cb) {
|
|
let err = null;
|
|
try {
|
|
await pull();
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
cb(err);
|
|
}
|
|
};
|
|
function defaultSize() {
|
|
return 1;
|
|
}
|
|
exports.ReadableStream = ReadableStream;
|
|
exports.CountQueuingStrategy = class CountQueuingStrategy {
|
|
constructor(opts = {}) {
|
|
const { highWaterMark = 1 } = opts;
|
|
this.highWaterMark = highWaterMark;
|
|
}
|
|
size(chunk) {
|
|
return 1;
|
|
}
|
|
};
|
|
exports.ByteLengthQueuingStrategy = class ByteLengthQueuingStrategy {
|
|
constructor(opts = {}) {
|
|
const { highWaterMark = 16384 } = opts;
|
|
this.highWaterMark = highWaterMark;
|
|
}
|
|
size(chunk) {
|
|
return chunk.byteLength;
|
|
}
|
|
};
|
|
exports.isReadableStream = function isReadableStream(value) {
|
|
if (value instanceof ReadableStream) return true;
|
|
return typeof value === "object" && value !== null && value[readableKind] === ReadableStream[readableKind];
|
|
};
|
|
exports.isReadableStreamErrored = function isReadableStreamErrored(stream) {
|
|
return getStreamError(stream._stream) !== null;
|
|
};
|
|
exports.isReadableStreamDisturbed = function isReadableStreamDisturbed(stream) {
|
|
return isDisturbed(stream._stream);
|
|
};
|
|
exports.WritableStreamDefaultWriter = class WritableStreamDefaultWriter {
|
|
constructor(stream) {
|
|
this._stream = stream;
|
|
this._stream._stream.once("close", onclose).once("error", onerror);
|
|
const closed = Promise.withResolvers();
|
|
closed.promise.catch(noop);
|
|
this._closed = closed;
|
|
function onclose() {
|
|
closed.resolve();
|
|
}
|
|
function onerror(err) {
|
|
closed.reject(err);
|
|
}
|
|
}
|
|
get desiredSize() {
|
|
const stream = this._stream._stream;
|
|
return stream._writableState.highWaterMark - stream._writableState.buffered;
|
|
}
|
|
get closed() {
|
|
return this._closed.promise;
|
|
}
|
|
get ready() {
|
|
const stream = this._stream._stream;
|
|
if (getStreamError(stream)) return Promise.reject();
|
|
return Writable.drained(stream).then();
|
|
}
|
|
async write(chunk) {
|
|
const stream = this._stream._stream;
|
|
let err = getStreamError(stream);
|
|
if (err) return Promise.reject(err);
|
|
stream.write(chunk);
|
|
await Writable.drained(stream);
|
|
err = getStreamError(stream);
|
|
if (err) return Promise.reject(err);
|
|
}
|
|
releaseLock() {
|
|
this._closed.reject(new TypeError("Writer was released"));
|
|
this._stream._releaseLock();
|
|
this._stream = null;
|
|
}
|
|
close() {
|
|
const stream = this._stream._stream;
|
|
if (stream.destroyed) return Promise.resolve();
|
|
return new Promise((resolve) => stream.once("close", resolve).end());
|
|
}
|
|
abort(reason = new TypeError("Stream was aborted")) {
|
|
const stream = this._stream._stream;
|
|
if (stream.destroyed) return Promise.resolve();
|
|
return new Promise((resolve) => stream.once("close", resolve).destroy(reason));
|
|
}
|
|
};
|
|
exports.WritableStreamDefaultController = class WritableStreamDefaultController {
|
|
constructor(stream) {
|
|
this._stream = stream;
|
|
}
|
|
error(err) {
|
|
this._stream._stream.destroy(err);
|
|
}
|
|
};
|
|
var WritableStream = class _WritableStream {
|
|
static get [writableKind]() {
|
|
return 0;
|
|
}
|
|
constructor(underlyingSink = {}, queuingStrategy = {}) {
|
|
if (isStreamx(underlyingSink)) {
|
|
this._stream = underlyingSink;
|
|
} else {
|
|
if (queuingStrategy === void 0) {
|
|
queuingStrategy = new exports.CountQueuingStrategy();
|
|
}
|
|
const { start, write, close, abort } = underlyingSink;
|
|
const { highWaterMark = 1, size = defaultSize } = queuingStrategy;
|
|
this._stream = new Writable({ highWaterMark, byteLength: size });
|
|
this._controller = new exports.WritableStreamDefaultController(this);
|
|
if (start) {
|
|
this._stream._open = this._open.bind(this, start.call(this, this._controller));
|
|
}
|
|
if (write) {
|
|
this._stream._write = this._write.bind(this, write);
|
|
}
|
|
if (close) {
|
|
this._stream._destroy = this._destroy.bind(this, close.call(this));
|
|
}
|
|
if (abort) {
|
|
this._stream.once("error", abort);
|
|
}
|
|
}
|
|
this._writer = null;
|
|
}
|
|
get [writableKind]() {
|
|
return _WritableStream[writableKind];
|
|
}
|
|
get locked() {
|
|
return this._writer !== null;
|
|
}
|
|
getWriter() {
|
|
if (this.locked) throw new TypeError("Stream is locked");
|
|
this._writer = new exports.WritableStreamDefaultWriter(this);
|
|
return this._writer;
|
|
}
|
|
abort(reason = new TypeError("Stream was aborted")) {
|
|
if (this._stream.destroyed) return Promise.resolve();
|
|
if (this.locked) return Promise.reject(new TypeError("Stream is locked"));
|
|
return new Promise((resolve) => this._stream.once("close", resolve).destroy(reason));
|
|
}
|
|
close() {
|
|
if (this._stream.destroyed) return Promise.resolve();
|
|
if (this.locked) return Promise.reject(new TypeError("Stream is locked"));
|
|
return new Promise((resolve) => this._stream.once("close", resolve).end());
|
|
}
|
|
_releaseLock() {
|
|
this._writer = null;
|
|
}
|
|
async _open(starting, cb) {
|
|
let err = null;
|
|
try {
|
|
await starting;
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
cb(err);
|
|
}
|
|
async _write(write, data, cb) {
|
|
let err = null;
|
|
try {
|
|
await write(data, this._controller);
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
cb(err);
|
|
}
|
|
async _destroy(closing, cb) {
|
|
let err = null;
|
|
try {
|
|
await closing;
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
cb(err);
|
|
}
|
|
};
|
|
exports.WritableStream = WritableStream;
|
|
exports.isWritableStream = function isWritableStream(value) {
|
|
if (value instanceof WritableStream) return true;
|
|
return typeof value === "object" && value !== null && value[writableKind] === WritableStream[writableKind];
|
|
};
|
|
exports.TransformStreamDefaultController = class TransformStreamDefaultController {
|
|
constructor(stream) {
|
|
this._stream = stream;
|
|
}
|
|
get desiredSize() {
|
|
const stream = this._stream._stream;
|
|
return stream._readableState.highWaterMark - stream._readableState.buffered;
|
|
}
|
|
enqueue(data) {
|
|
this._stream._stream.push(data);
|
|
}
|
|
error(err) {
|
|
this._stream._stream.destroy(err);
|
|
}
|
|
terminate() {
|
|
const stream = this._stream._stream;
|
|
stream.push(null);
|
|
stream.destroy(new TypeError("Stream has been terminated"));
|
|
}
|
|
};
|
|
var TransformStream = class _TransformStream {
|
|
static get [transformKind]() {
|
|
return 0;
|
|
}
|
|
constructor(transformer = {}, writableStrategy = {}, readableStrategy = {}) {
|
|
const { start, transform, flush } = transformer;
|
|
this._stream = new Transform({ ...writableStrategy, ...readableStrategy });
|
|
this._writable = new WritableStream(this._stream);
|
|
this._readable = new ReadableStream(this._stream);
|
|
this._controller = new exports.TransformStreamDefaultController(this);
|
|
if (start) {
|
|
this._stream._open = this._open.bind(this, start.call(this, this._controller));
|
|
}
|
|
if (transform) {
|
|
this._stream._write = this._transform.bind(this, transform);
|
|
}
|
|
if (flush) {
|
|
this._stream._flush = this._flush.bind(this, flush.call(this, this._controller));
|
|
}
|
|
}
|
|
get [transformKind]() {
|
|
return _TransformStream[transformKind];
|
|
}
|
|
get writable() {
|
|
return this._writable;
|
|
}
|
|
get readable() {
|
|
return this._readable;
|
|
}
|
|
async _open(starting, cb) {
|
|
let err = null;
|
|
try {
|
|
await starting;
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
cb(err);
|
|
}
|
|
async _transform(transform, data, cb) {
|
|
let err = null;
|
|
try {
|
|
await transform(data, this._controller);
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
cb(err);
|
|
}
|
|
async _flush(flush, cb) {
|
|
let err = null;
|
|
try {
|
|
await flush;
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
cb(err);
|
|
}
|
|
};
|
|
exports.TransformStream = TransformStream;
|
|
exports.isTransformStream = function isTransformStream(value) {
|
|
if (value instanceof TransformStream) return true;
|
|
return typeof value === "object" && value !== null && value[transformKind] === TransformStream[transformKind];
|
|
};
|
|
function noop() {
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-stream/index.js
|
|
var require_bare_stream = __commonJS({
|
|
"../../node_modules/bare-stream/index.js"(exports, module) {
|
|
var stream = require_streamx();
|
|
var { ReadableStream, WritableStream } = require_web();
|
|
var defaultEncoding = "utf8";
|
|
module.exports = exports = stream.Stream;
|
|
exports.pipeline = stream.pipeline;
|
|
exports.isStream = stream.isStream;
|
|
exports.isEnding = stream.isEnding;
|
|
exports.isEnded = stream.isEnded;
|
|
exports.isFinishing = stream.isFinishing;
|
|
exports.isFinished = stream.isFinished;
|
|
exports.isDisturbed = stream.isDisturbed;
|
|
exports.isErrored = function isErrored(stream2) {
|
|
return exports.getStreamError(stream2) !== null;
|
|
};
|
|
exports.isReadable = function isReadable(stream2) {
|
|
return stream2.readable && !stream2.destroying && !exports.isEnded(stream2);
|
|
};
|
|
exports.isWritable = function isWritable(stream2) {
|
|
return stream2.writable && !stream2.destroying && !exports.isFinishing(stream2);
|
|
};
|
|
exports.getStreamError = stream.getStreamError;
|
|
exports.addAbortSignal = function addAbortSignal(signal, stream2) {
|
|
function onAbort() {
|
|
stream2.destroy(signal.reason);
|
|
}
|
|
if (signal.aborted) onAbort();
|
|
else signal.addEventListener("abort", onAbort);
|
|
return stream2;
|
|
};
|
|
exports.Stream = exports;
|
|
exports.Readable = class Readable extends stream.Readable {
|
|
constructor(opts = {}) {
|
|
super({
|
|
...opts,
|
|
byteLength: null,
|
|
byteLengthReadable: null,
|
|
map: null,
|
|
mapReadable: null
|
|
});
|
|
if (this._construct) this._open = this._construct;
|
|
if (this._read !== stream.Readable.prototype._read) {
|
|
this._read = read.bind(this, this._read);
|
|
}
|
|
if (this._destroy !== stream.Stream.prototype._destroy) {
|
|
this._destroy = destroy.bind(this, this._destroy);
|
|
}
|
|
}
|
|
get closed() {
|
|
return !exports.isReadable(this);
|
|
}
|
|
get errored() {
|
|
return stream.getStreamError(this);
|
|
}
|
|
push(chunk, encoding) {
|
|
if (typeof chunk === "string") {
|
|
chunk = Buffer.from(chunk, encoding || defaultEncoding);
|
|
}
|
|
return super.push(chunk);
|
|
}
|
|
unshift(chunk, encoding) {
|
|
if (typeof chunk === "string") {
|
|
chunk = Buffer.from(chunk, encoding || defaultEncoding);
|
|
}
|
|
super.unshift(chunk);
|
|
}
|
|
static fromWeb(readableStream, opts = {}) {
|
|
const stream2 = readableStream._stream;
|
|
if (opts.encoding) stream2.setEncoding(opts.encoding);
|
|
if (opts.signal) exports.addAbortSignal(opts.signal, stream2);
|
|
return stream2;
|
|
}
|
|
static toWeb(readable, opts = {}) {
|
|
return new ReadableStream(readable, opts.strategy);
|
|
}
|
|
async [Symbol.asyncDispose]() {
|
|
if (!this.destroyed) this.destroy();
|
|
await new Promise((resolve) => exports.finished(this, resolve));
|
|
}
|
|
};
|
|
exports.Writable = class Writable extends stream.Writable {
|
|
constructor(opts = {}) {
|
|
super({
|
|
...opts,
|
|
byteLength: null,
|
|
byteLengthWritable,
|
|
map: null,
|
|
mapWritable: null
|
|
});
|
|
if (this._construct) this._open = this._construct;
|
|
if (this._write !== stream.Writable.prototype._write) {
|
|
this._write = write.bind(this, this._write);
|
|
}
|
|
if (this._destroy !== stream.Stream.prototype._destroy) {
|
|
this._destroy = destroy.bind(this, this._destroy);
|
|
}
|
|
}
|
|
get closed() {
|
|
return !exports.isWritable(this);
|
|
}
|
|
get errored() {
|
|
return stream.getStreamError(this);
|
|
}
|
|
write(chunk, encoding, cb) {
|
|
if (typeof encoding === "function") {
|
|
cb = encoding;
|
|
encoding = null;
|
|
}
|
|
if (typeof chunk === "string") {
|
|
encoding = encoding || defaultEncoding;
|
|
chunk = Buffer.from(chunk, encoding);
|
|
} else {
|
|
encoding = "buffer";
|
|
}
|
|
const result = super.write({ chunk, encoding });
|
|
if (cb) stream.Writable.drained(this).then(() => cb(null), cb);
|
|
return result;
|
|
}
|
|
end(chunk, encoding, cb) {
|
|
if (typeof chunk === "function") {
|
|
cb = chunk;
|
|
chunk = null;
|
|
} else if (typeof encoding === "function") {
|
|
cb = encoding;
|
|
encoding = null;
|
|
}
|
|
if (typeof chunk === "string") {
|
|
encoding = encoding || defaultEncoding;
|
|
chunk = Buffer.from(chunk, encoding || defaultEncoding);
|
|
} else {
|
|
encoding = "buffer";
|
|
}
|
|
const result = chunk !== void 0 && chunk !== null ? super.end({ chunk, encoding }) : super.end();
|
|
if (cb) this.once("finish", () => cb(null));
|
|
return result;
|
|
}
|
|
static fromWeb(writableStream, opts = {}) {
|
|
const stream2 = writableStream._stream;
|
|
if (opts.signal) exports.addAbortSignal(opts.signal, stream2);
|
|
return stream2;
|
|
}
|
|
static toWeb(writable) {
|
|
return new WritableStream(writable);
|
|
}
|
|
async [Symbol.asyncDispose]() {
|
|
if (!this.destroyed) this.destroy();
|
|
await new Promise((resolve) => exports.finished(this, resolve));
|
|
}
|
|
};
|
|
exports.Duplex = class Duplex extends stream.Duplex {
|
|
constructor(opts = {}) {
|
|
super({
|
|
...opts,
|
|
byteLength: null,
|
|
byteLengthReadable: null,
|
|
byteLengthWritable,
|
|
map: null,
|
|
mapReadable: null,
|
|
mapWritable: null
|
|
});
|
|
if (this._construct) this._open = this._construct;
|
|
if (this._read !== stream.Readable.prototype._read) {
|
|
this._read = read.bind(this, this._read);
|
|
}
|
|
if (this._write !== stream.Duplex.prototype._write) {
|
|
this._write = write.bind(this, this._write);
|
|
}
|
|
if (this._destroy !== stream.Stream.prototype._destroy) {
|
|
this._destroy = destroy.bind(this, this._destroy);
|
|
}
|
|
}
|
|
push(chunk, encoding) {
|
|
if (typeof chunk === "string") {
|
|
chunk = Buffer.from(chunk, encoding || defaultEncoding);
|
|
}
|
|
return super.push(chunk);
|
|
}
|
|
unshift(chunk, encoding) {
|
|
if (typeof chunk === "string") {
|
|
chunk = Buffer.from(chunk, encoding || defaultEncoding);
|
|
}
|
|
super.unshift(chunk);
|
|
}
|
|
write(chunk, encoding, cb) {
|
|
if (typeof encoding === "function") {
|
|
cb = encoding;
|
|
encoding = null;
|
|
}
|
|
if (typeof chunk === "string") {
|
|
encoding = encoding || defaultEncoding;
|
|
chunk = Buffer.from(chunk, encoding);
|
|
} else {
|
|
encoding = "buffer";
|
|
}
|
|
const result = super.write({ chunk, encoding });
|
|
if (cb) stream.Writable.drained(this).then(() => cb(null), cb);
|
|
return result;
|
|
}
|
|
end(chunk, encoding, cb) {
|
|
if (typeof chunk === "function") {
|
|
cb = chunk;
|
|
chunk = null;
|
|
} else if (typeof encoding === "function") {
|
|
cb = encoding;
|
|
encoding = null;
|
|
}
|
|
if (typeof chunk === "string") {
|
|
encoding = encoding || defaultEncoding;
|
|
chunk = Buffer.from(chunk, encoding);
|
|
} else {
|
|
encoding = "buffer";
|
|
}
|
|
const result = chunk !== void 0 && chunk !== null ? super.end({ chunk, encoding }) : super.end();
|
|
if (cb) this.once("finish", () => cb(null));
|
|
return result;
|
|
}
|
|
static fromWeb({ readable: readableStream, writable: writableStream }, opts) {
|
|
const readable = exports.Readable.fromWeb(readableStream, opts);
|
|
const writable = exports.Readable.fromWeb(writableStream, opts);
|
|
const duplex = new exports.Duplex({
|
|
write(data, encoding, cb) {
|
|
writable.write(data, encoding, cb);
|
|
}
|
|
});
|
|
readable.on("data", (data) => duplex.push(data)).on("end", () => duplex.push(null)).on("error", (err) => duplex.destroy(err));
|
|
writable.on("finish", () => duplex.end()).on("error", (err) => duplex.destroy(err));
|
|
return duplex;
|
|
}
|
|
static toWeb(duplex) {
|
|
const readableStream = exports.Readable.toWeb(duplex);
|
|
const writableStream = exports.Writable.toWeb(duplex);
|
|
return { readable: readableStream, writable: writableStream };
|
|
}
|
|
};
|
|
var DuplexSide = class extends exports.Duplex {
|
|
constructor(opts) {
|
|
super(opts);
|
|
this._otherSide = null;
|
|
this._cb = null;
|
|
}
|
|
_read() {
|
|
const cb = this._cb;
|
|
if (!cb) return;
|
|
this._cb = null;
|
|
cb();
|
|
}
|
|
_write(chunk, encoding, cb) {
|
|
this._otherSide.push(chunk, encoding);
|
|
this._otherSide._cb = cb;
|
|
}
|
|
_final(cb) {
|
|
this._otherSide.on("end", cb);
|
|
this._otherSide.push(null);
|
|
}
|
|
};
|
|
exports.duplexPair = function duplexPair(opts) {
|
|
const sideA = new DuplexSide(opts);
|
|
const sideB = new DuplexSide(opts);
|
|
sideA._otherSide = sideB;
|
|
sideB._otherSide = sideA;
|
|
return [sideA, sideB];
|
|
};
|
|
exports.Transform = class Transform extends stream.Transform {
|
|
constructor(opts = {}) {
|
|
super({
|
|
...opts,
|
|
byteLength: null,
|
|
byteLengthReadable: null,
|
|
byteLengthWritable,
|
|
map: null,
|
|
mapReadable: null,
|
|
mapWritable: null
|
|
});
|
|
if (this._transform !== stream.Transform.prototype._transform) {
|
|
this._transform = transform.bind(this, this._transform);
|
|
} else {
|
|
this._transform = passthrough;
|
|
}
|
|
}
|
|
push(chunk, encoding) {
|
|
if (typeof chunk === "string") {
|
|
chunk = Buffer.from(chunk, encoding || defaultEncoding);
|
|
}
|
|
return super.push(chunk);
|
|
}
|
|
unshift(chunk, encoding) {
|
|
if (typeof chunk === "string") {
|
|
chunk = Buffer.from(chunk, encoding || defaultEncoding);
|
|
}
|
|
super.unshift(chunk);
|
|
}
|
|
write(chunk, encoding, cb) {
|
|
if (typeof encoding === "function") {
|
|
cb = encoding;
|
|
encoding = null;
|
|
}
|
|
if (typeof chunk === "string") {
|
|
encoding = encoding || defaultEncoding;
|
|
chunk = Buffer.from(chunk, encoding);
|
|
} else {
|
|
encoding = "buffer";
|
|
}
|
|
const result = super.write({ chunk, encoding });
|
|
if (cb) stream.Writable.drained(this).then(() => cb(null), cb);
|
|
return result;
|
|
}
|
|
end(chunk, encoding, cb) {
|
|
if (typeof chunk === "function") {
|
|
cb = chunk;
|
|
chunk = null;
|
|
} else if (typeof encoding === "function") {
|
|
cb = encoding;
|
|
encoding = null;
|
|
}
|
|
if (typeof chunk === "string") {
|
|
encoding = encoding || defaultEncoding;
|
|
chunk = Buffer.from(chunk, encoding);
|
|
} else {
|
|
encoding = "buffer";
|
|
}
|
|
const result = chunk !== void 0 && chunk !== null ? super.end({ chunk, encoding }) : super.end();
|
|
if (cb) this.once("finish", () => cb(null));
|
|
return result;
|
|
}
|
|
};
|
|
exports.PassThrough = class PassThrough extends exports.Transform {
|
|
};
|
|
exports.finished = function finished(stream2, opts, cb) {
|
|
if (typeof opts === "function") {
|
|
cb = opts;
|
|
opts = {};
|
|
}
|
|
if (!opts) opts = {};
|
|
const { cleanup = false } = opts;
|
|
const done = () => {
|
|
cb(exports.getStreamError(stream2, { all: true }));
|
|
if (cleanup) detach();
|
|
};
|
|
const detach = () => {
|
|
stream2.off("close", done);
|
|
stream2.off("error", noop);
|
|
};
|
|
if (stream2.destroyed) {
|
|
done();
|
|
} else {
|
|
stream2.on("close", done);
|
|
stream2.on("error", noop);
|
|
}
|
|
return detach;
|
|
};
|
|
function read(read2, cb) {
|
|
read2.call(this, 65536);
|
|
cb(null);
|
|
}
|
|
function write(write2, data, cb) {
|
|
write2.call(this, data.chunk, data.encoding, cb);
|
|
}
|
|
function transform(transform2, data, cb) {
|
|
transform2.call(this, data.chunk, data.encoding, cb);
|
|
}
|
|
function destroy(destroy2, cb) {
|
|
destroy2.call(this, exports.getStreamError(this), cb);
|
|
}
|
|
function passthrough(data, cb) {
|
|
cb(null, data.chunk);
|
|
}
|
|
function byteLengthWritable(data) {
|
|
return data.chunk.byteLength;
|
|
}
|
|
function noop() {
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-type/binding.js
|
|
var require_binding = __commonJS({
|
|
"../../node_modules/bare-type/binding.js"(exports, module) {
|
|
module.exports = __require.addon();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-type/index.js
|
|
var require_bare_type = __commonJS({
|
|
"../../node_modules/bare-type/index.js"(exports, module) {
|
|
var binding = require_binding();
|
|
var t = binding.constants;
|
|
var Type = class {
|
|
constructor(type) {
|
|
this._type = type;
|
|
}
|
|
isUndefined() {
|
|
return this._type === t.UNDEFINED;
|
|
}
|
|
isNull() {
|
|
return this._type === t.NULL;
|
|
}
|
|
isBoolean() {
|
|
return this._type === t.BOOLEAN;
|
|
}
|
|
isNumber() {
|
|
return (this._type & 255) === t.NUMBER;
|
|
}
|
|
isInt32() {
|
|
return (this._type & (255 | t.INT32)) === (t.NUMBER | t.INT32);
|
|
}
|
|
isUint32() {
|
|
return (this._type & (255 | t.UINT32)) === (t.NUMBER | t.UINT32);
|
|
}
|
|
isString() {
|
|
return this._type === t.STRING;
|
|
}
|
|
isSymbol() {
|
|
return this._type === t.SYMBOL;
|
|
}
|
|
isObject() {
|
|
return (this._type & 255) === t.OBJECT;
|
|
}
|
|
isArray() {
|
|
return this._type === (t.OBJECT | t.ARRAY);
|
|
}
|
|
isArguments() {
|
|
return this._type === (t.OBJECT | t.ARGUMENTS);
|
|
}
|
|
isDate() {
|
|
return this._type === (t.OBJECT | t.DATE);
|
|
}
|
|
isRegExp() {
|
|
return this._type === (t.OBJECT | t.REGEXP);
|
|
}
|
|
isError() {
|
|
return this._type === (t.OBJECT | t.ERROR);
|
|
}
|
|
isPromise() {
|
|
return this._type === (t.OBJECT | t.PROMISE);
|
|
}
|
|
isProxy() {
|
|
return this._type === (t.OBJECT | t.PROXY);
|
|
}
|
|
isGenerator() {
|
|
return this._type === (t.OBJECT | t.GENERATOR);
|
|
}
|
|
isMap() {
|
|
return this._type === (t.OBJECT | t.MAP);
|
|
}
|
|
isSet() {
|
|
return this._type === (t.OBJECT | t.SET);
|
|
}
|
|
isWeakMap() {
|
|
return this._type === (t.OBJECT | t.WEAK_MAP);
|
|
}
|
|
isWeakSet() {
|
|
return this._type === (t.OBJECT | t.WEAK_SET);
|
|
}
|
|
isWeakRef() {
|
|
return this._type === (t.OBJECT | t.WEAK_REF);
|
|
}
|
|
isArrayBuffer() {
|
|
return this._type === (t.OBJECT | t.ARRAYBUFFER);
|
|
}
|
|
isSharedArrayBuffer() {
|
|
return this._type === (t.OBJECT | t.SHAREDARRAYBUFFER);
|
|
}
|
|
isTypedArray() {
|
|
return (this._type & 65535) === (t.OBJECT | t.TYPEDARRAY);
|
|
}
|
|
isInt8Array() {
|
|
return this._type === (t.OBJECT | t.TYPEDARRAY | t.INT8ARRAY);
|
|
}
|
|
isUint8Array() {
|
|
return this._type === (t.OBJECT | t.TYPEDARRAY | t.UINT8ARRAY);
|
|
}
|
|
isUint8ClampedArray() {
|
|
return this._type === (t.OBJECT | t.TYPEDARRAY | t.UINT8CLAMPEDARRAY);
|
|
}
|
|
isInt16Array() {
|
|
return this._type === (t.OBJECT | t.TYPEDARRAY | t.INT16ARRAY);
|
|
}
|
|
isUint16Array() {
|
|
return this._type === (t.OBJECT | t.TYPEDARRAY | t.UINT16ARRAY);
|
|
}
|
|
isInt32Array() {
|
|
return this._type === (t.OBJECT | t.TYPEDARRAY | t.INT32ARRAY);
|
|
}
|
|
isUint32Array() {
|
|
return this._type === (t.OBJECT | t.TYPEDARRAY | t.UINT32ARRAY);
|
|
}
|
|
isFloat16Array() {
|
|
return this._type === (t.OBJECT | t.TYPEDARRAY | t.FLOAT16ARRAY);
|
|
}
|
|
isFloat32Array() {
|
|
return this._type === (t.OBJECT | t.TYPEDARRAY | t.FLOAT32ARRAY);
|
|
}
|
|
isFloat64Array() {
|
|
return this._type === (t.OBJECT | t.TYPEDARRAY | t.FLOAT64ARRAY);
|
|
}
|
|
isBigInt64Array() {
|
|
return this._type === (t.OBJECT | t.TYPEDARRAY | t.BIGINT64ARRAY);
|
|
}
|
|
isBigUint64Array() {
|
|
return this._type === (t.OBJECT | t.TYPEDARRAY | t.BIGUINT64ARRAY);
|
|
}
|
|
isDataView() {
|
|
return this._type === (t.OBJECT | t.DATAVIEW);
|
|
}
|
|
isModuleNamespace() {
|
|
return this._type === (t.OBJECT | t.MODULE_NAMESPACE);
|
|
}
|
|
isFunction() {
|
|
return (this._type & 255) === t.FUNCTION;
|
|
}
|
|
isAsyncFunction() {
|
|
return (this._type & (255 | t.ASYNC_FUNCTION)) === (t.FUNCTION | t.ASYNC_FUNCTION);
|
|
}
|
|
isGeneratorFunction() {
|
|
return (this._type & (255 | t.GENERATOR_FUNCTION)) === (t.FUNCTION | t.GENERATOR_FUNCTION);
|
|
}
|
|
isExternal() {
|
|
return this._type === t.EXTERNAL;
|
|
}
|
|
isBigInt() {
|
|
return this._type === t.BIGINT;
|
|
}
|
|
};
|
|
module.exports = exports = function type(value) {
|
|
switch (typeof value) {
|
|
case "undefined":
|
|
return new Type(t.UNDEFINED);
|
|
case "boolean":
|
|
return new Type(t.BOOLEAN);
|
|
case "number":
|
|
return new Type(
|
|
Number.isSafeInteger(value) ? binding.type(value) : t.NUMBER
|
|
);
|
|
case "string":
|
|
return new Type(t.STRING);
|
|
case "symbol":
|
|
return new Type(t.SYMBOL);
|
|
case "object":
|
|
return new Type(value === null ? t.NULL : binding.type(value));
|
|
case "function":
|
|
return new Type(binding.type(value));
|
|
case "bigint":
|
|
return new Type(t.BIGINT);
|
|
}
|
|
};
|
|
exports.createTag = function createTag(...components) {
|
|
const tag = new Uint32Array(4);
|
|
for (let i = 0; i < 4; i++) tag[i] = components[i] || 0;
|
|
return tag;
|
|
};
|
|
exports.addTag = function addTag(object, tag) {
|
|
binding.addTag(object, tag);
|
|
};
|
|
exports.checkTag = function checkTag(object, tag) {
|
|
return binding.checkTag(object, tag);
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-os/binding.js
|
|
var require_binding2 = __commonJS({
|
|
"../../node_modules/bare-os/binding.js"(exports, module) {
|
|
module.exports = __require.addon();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-os/lib/errors.js
|
|
var require_errors2 = __commonJS({
|
|
"../../node_modules/bare-os/lib/errors.js"(exports, module) {
|
|
module.exports = class OSError extends Error {
|
|
constructor(msg, code, fn = OSError) {
|
|
super(`${code}: ${msg}`);
|
|
this.code = code;
|
|
if (Error.captureStackTrace) {
|
|
Error.captureStackTrace(this, fn);
|
|
}
|
|
}
|
|
get name() {
|
|
return "OSError";
|
|
}
|
|
static UNKNOWN_SIGNAL(msg) {
|
|
return new OSError(msg, "UNKNOWN_SIGNAL", OSError.UNKNOWN_SIGNAL);
|
|
}
|
|
static TITLE_OVERFLOW(msg) {
|
|
return new OSError(msg, "TITLE_OVERFLOW", OSError.TITLE_OVERFLOW);
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-os/lib/constants.js
|
|
var require_constants = __commonJS({
|
|
"../../node_modules/bare-os/lib/constants.js"(exports, module) {
|
|
var binding = require_binding2();
|
|
module.exports = {
|
|
signals: binding.signals,
|
|
errnos: binding.errnos,
|
|
priority: binding.priority
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-os/index.js
|
|
var require_bare_os = __commonJS({
|
|
"../../node_modules/bare-os/index.js"(exports) {
|
|
var binding = require_binding2();
|
|
var errors = require_errors2();
|
|
var constants = require_constants();
|
|
exports.constants = constants;
|
|
exports.EOL = binding.platform === "win32" ? "\r\n" : "\n";
|
|
exports.devNull = binding.platform === "win32" ? "\\\\.\\nul" : "/dev/null";
|
|
exports.platform = function platform() {
|
|
return binding.platform;
|
|
};
|
|
exports.arch = function arch() {
|
|
return binding.arch;
|
|
};
|
|
exports.type = binding.type;
|
|
exports.version = binding.version;
|
|
exports.release = binding.release;
|
|
exports.machine = binding.machine;
|
|
exports.execPath = binding.execPath;
|
|
exports.pid = binding.pid;
|
|
exports.ppid = binding.ppid;
|
|
exports.cwd = binding.cwd;
|
|
exports.chdir = binding.chdir;
|
|
exports.tmpdir = binding.tmpdir;
|
|
exports.homedir = binding.homedir;
|
|
exports.hostname = binding.hostname;
|
|
exports.userInfo = binding.userInfo;
|
|
exports.networkInterfaces = function networkInterfaces() {
|
|
const result = {};
|
|
for (const entry of binding.networkInterfaces()) {
|
|
const { name, ...properties } = entry;
|
|
if (result[name]) result[name].push(properties);
|
|
else result[name] = [properties];
|
|
}
|
|
return result;
|
|
};
|
|
exports.kill = function kill(pid, signal = constants.signals.SIGTERM) {
|
|
if (typeof signal === "string") {
|
|
if (signal in constants.signals === false) {
|
|
throw errors.UNKNOWN_SIGNAL("Unknown signal: " + signal);
|
|
}
|
|
signal = constants.signals[signal];
|
|
}
|
|
binding.kill(pid, signal);
|
|
};
|
|
exports.endianness = function endianness() {
|
|
return binding.isLittleEndian ? "LE" : "BE";
|
|
};
|
|
exports.availableParallelism = binding.availableParallelism;
|
|
exports.cpuUsage = function cpuUsage(previous) {
|
|
const current = binding.cpuUsage();
|
|
if (previous) {
|
|
return {
|
|
user: current.user - previous.user,
|
|
system: current.system - previous.system
|
|
};
|
|
}
|
|
return current;
|
|
};
|
|
exports.threadCpuUsage = function threadCpuUsage(previous) {
|
|
const current = binding.threadCpuUsage();
|
|
if (previous) {
|
|
return {
|
|
user: current.user - previous.user,
|
|
system: current.system - previous.system
|
|
};
|
|
}
|
|
return current;
|
|
};
|
|
exports.resourceUsage = binding.resourceUsage;
|
|
exports.memoryUsage = binding.memoryUsage;
|
|
exports.freemem = binding.freemem;
|
|
exports.totalmem = binding.totalmem;
|
|
exports.availableMemory = binding.availableMemory;
|
|
exports.constrainedMemory = binding.constrainedMemory;
|
|
exports.uptime = binding.uptime;
|
|
exports.loadavg = binding.loadavg;
|
|
exports.cpus = binding.cpus;
|
|
exports.getProcessTitle = binding.getProcessTitle;
|
|
exports.setProcessTitle = function setProcessTitle(title) {
|
|
if (typeof title !== "string") title = title.toString();
|
|
if (title.length >= 256) {
|
|
throw errors.TITLE_OVERFLOW("Process title is too long");
|
|
}
|
|
binding.setProcessTitle(title);
|
|
};
|
|
exports.getPriority = function getPriority(pid = 0) {
|
|
return binding.getPriority(pid);
|
|
};
|
|
exports.setPriority = function setPriority(pid, priority) {
|
|
if (priority === void 0) {
|
|
priority = pid;
|
|
pid = 0;
|
|
}
|
|
binding.setPriority(pid, priority);
|
|
};
|
|
exports.getEnvKeys = binding.getEnvKeys;
|
|
exports.getEnv = binding.getEnv;
|
|
exports.hasEnv = binding.hasEnv;
|
|
exports.setEnv = binding.setEnv;
|
|
exports.unsetEnv = binding.unsetEnv;
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-path/lib/constants.js
|
|
var require_constants2 = __commonJS({
|
|
"../../node_modules/bare-path/lib/constants.js"(exports, module) {
|
|
module.exports = {
|
|
CHAR_UPPERCASE_A: 65,
|
|
CHAR_LOWERCASE_A: 97,
|
|
CHAR_UPPERCASE_Z: 90,
|
|
CHAR_LOWERCASE_Z: 122,
|
|
CHAR_DOT: 46,
|
|
CHAR_FORWARD_SLASH: 47,
|
|
CHAR_BACKWARD_SLASH: 92,
|
|
CHAR_COLON: 58,
|
|
CHAR_QUESTION_MARK: 63
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-path/lib/shared.js
|
|
var require_shared = __commonJS({
|
|
"../../node_modules/bare-path/lib/shared.js"(exports) {
|
|
var {
|
|
CHAR_DOT,
|
|
CHAR_FORWARD_SLASH
|
|
} = require_constants2();
|
|
exports.normalizeString = function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
|
|
let res = "";
|
|
let lastSegmentLength = 0;
|
|
let lastSlash = -1;
|
|
let dots = 0;
|
|
let code = 0;
|
|
for (let i = 0; i <= path.length; ++i) {
|
|
if (i < path.length) {
|
|
code = path.charCodeAt(i);
|
|
} else if (isPathSeparator(code)) {
|
|
break;
|
|
} else {
|
|
code = CHAR_FORWARD_SLASH;
|
|
}
|
|
if (isPathSeparator(code)) {
|
|
if (lastSlash === i - 1 || dots === 1) ;
|
|
else if (dots === 2) {
|
|
if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== CHAR_DOT || res.charCodeAt(res.length - 2) !== CHAR_DOT) {
|
|
if (res.length > 2) {
|
|
const lastSlashIndex = res.lastIndexOf(separator);
|
|
if (lastSlashIndex === -1) {
|
|
res = "";
|
|
lastSegmentLength = 0;
|
|
} else {
|
|
res = res.substring(0, lastSlashIndex);
|
|
lastSegmentLength = res.length - 1 - res.lastIndexOf(separator);
|
|
}
|
|
lastSlash = i;
|
|
dots = 0;
|
|
continue;
|
|
} else if (res.length !== 0) {
|
|
res = "";
|
|
lastSegmentLength = 0;
|
|
lastSlash = i;
|
|
dots = 0;
|
|
continue;
|
|
}
|
|
}
|
|
if (allowAboveRoot) {
|
|
res += res.length > 0 ? `${separator}..` : "..";
|
|
lastSegmentLength = 2;
|
|
}
|
|
} else {
|
|
if (res.length > 0) {
|
|
res += `${separator}${path.substring(lastSlash + 1, i)}`;
|
|
} else {
|
|
res = path.substring(lastSlash + 1, i);
|
|
}
|
|
lastSegmentLength = i - lastSlash - 1;
|
|
}
|
|
lastSlash = i;
|
|
dots = 0;
|
|
} else if (code === CHAR_DOT && dots !== -1) {
|
|
++dots;
|
|
} else {
|
|
dots = -1;
|
|
}
|
|
}
|
|
return res;
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-path/lib/posix.js
|
|
var require_posix = __commonJS({
|
|
"../../node_modules/bare-path/lib/posix.js"(exports) {
|
|
var os = require_bare_os();
|
|
var { normalizeString } = require_shared();
|
|
var {
|
|
CHAR_DOT,
|
|
CHAR_FORWARD_SLASH
|
|
} = require_constants2();
|
|
function isPosixPathSeparator(code) {
|
|
return code === CHAR_FORWARD_SLASH;
|
|
}
|
|
exports.win32 = require_win32();
|
|
exports.posix = exports;
|
|
exports.sep = "/";
|
|
exports.delimiter = ":";
|
|
exports.resolve = function resolve(...args) {
|
|
let resolvedPath = "";
|
|
let resolvedAbsolute = false;
|
|
for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
|
const path = i >= 0 ? args[i] : os.cwd();
|
|
if (path.length === 0) {
|
|
continue;
|
|
}
|
|
resolvedPath = `${path}/${resolvedPath}`;
|
|
resolvedAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
|
|
}
|
|
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute, "/", isPosixPathSeparator);
|
|
if (resolvedAbsolute) {
|
|
return `/${resolvedPath}`;
|
|
}
|
|
return resolvedPath.length > 0 ? resolvedPath : ".";
|
|
};
|
|
exports.normalize = function normalize(path) {
|
|
if (path.length === 0) return ".";
|
|
const isAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
|
|
const trailingSeparator = path.charCodeAt(path.length - 1) === CHAR_FORWARD_SLASH;
|
|
path = normalizeString(path, !isAbsolute, "/", isPosixPathSeparator);
|
|
if (path.length === 0) {
|
|
if (isAbsolute) return "/";
|
|
return trailingSeparator ? "./" : ".";
|
|
}
|
|
if (trailingSeparator) path += "/";
|
|
return isAbsolute ? `/${path}` : path;
|
|
};
|
|
exports.isAbsolute = function isAbsolute(path) {
|
|
return path.length > 0 && path.charCodeAt(0) === CHAR_FORWARD_SLASH;
|
|
};
|
|
exports.join = function join(...args) {
|
|
if (args.length === 0) return ".";
|
|
let joined;
|
|
for (let i = 0; i < args.length; ++i) {
|
|
const arg = args[i];
|
|
if (arg.length > 0) {
|
|
if (joined === void 0) joined = arg;
|
|
else joined += `/${arg}`;
|
|
}
|
|
}
|
|
if (joined === void 0) return ".";
|
|
return exports.normalize(joined);
|
|
};
|
|
exports.relative = function relative(from, to) {
|
|
if (from === to) return "";
|
|
from = exports.resolve(from);
|
|
to = exports.resolve(to);
|
|
if (from === to) return "";
|
|
const fromStart = 1;
|
|
const fromEnd = from.length;
|
|
const fromLen = fromEnd - fromStart;
|
|
const toStart = 1;
|
|
const toLen = to.length - toStart;
|
|
const length = fromLen < toLen ? fromLen : toLen;
|
|
let lastCommonSep = -1;
|
|
let i = 0;
|
|
for (; i < length; i++) {
|
|
const fromCode = from.charCodeAt(fromStart + i);
|
|
if (fromCode !== to.charCodeAt(toStart + i)) {
|
|
break;
|
|
} else if (fromCode === CHAR_FORWARD_SLASH) {
|
|
lastCommonSep = i;
|
|
}
|
|
}
|
|
if (i === length) {
|
|
if (toLen > length) {
|
|
if (to.charCodeAt(toStart + i) === CHAR_FORWARD_SLASH) {
|
|
return to.substring(toStart + i + 1);
|
|
}
|
|
if (i === 0) {
|
|
return to.substring(toStart + i);
|
|
}
|
|
} else if (fromLen > length) {
|
|
if (from.charCodeAt(fromStart + i) === CHAR_FORWARD_SLASH) {
|
|
lastCommonSep = i;
|
|
} else if (i === 0) {
|
|
lastCommonSep = 0;
|
|
}
|
|
}
|
|
}
|
|
let out = "";
|
|
for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
|
|
if (i === fromEnd || from.charCodeAt(i) === CHAR_FORWARD_SLASH) {
|
|
out += out.length === 0 ? ".." : "/..";
|
|
}
|
|
}
|
|
return `${out}${to.substring(toStart + lastCommonSep)}`;
|
|
};
|
|
exports.toNamespacedPath = function toNamespacedPath(path) {
|
|
return path;
|
|
};
|
|
exports.dirname = function dirname(path) {
|
|
if (path.length === 0) return ".";
|
|
const hasRoot = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
|
|
let end = -1;
|
|
let matchedSlash = true;
|
|
for (let i = path.length - 1; i >= 1; --i) {
|
|
if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) {
|
|
if (!matchedSlash) {
|
|
end = i;
|
|
break;
|
|
}
|
|
} else {
|
|
matchedSlash = false;
|
|
}
|
|
}
|
|
if (end === -1) return hasRoot ? "/" : ".";
|
|
if (hasRoot && end === 1) return "//";
|
|
return path.substring(0, end);
|
|
};
|
|
exports.basename = function basename(path, suffix) {
|
|
let start = 0;
|
|
let end = -1;
|
|
let matchedSlash = true;
|
|
if (suffix !== void 0 && suffix.length > 0 && suffix.length <= path.length) {
|
|
if (suffix === path) {
|
|
return "";
|
|
}
|
|
let extIdx = suffix.length - 1;
|
|
let firstNonSlashEnd = -1;
|
|
for (let i = path.length - 1; i >= 0; --i) {
|
|
const code = path.charCodeAt(i);
|
|
if (code === CHAR_FORWARD_SLASH) {
|
|
if (!matchedSlash) {
|
|
start = i + 1;
|
|
break;
|
|
}
|
|
} else {
|
|
if (firstNonSlashEnd === -1) {
|
|
matchedSlash = false;
|
|
firstNonSlashEnd = i + 1;
|
|
}
|
|
if (extIdx >= 0) {
|
|
if (code === suffix.charCodeAt(extIdx)) {
|
|
if (--extIdx === -1) {
|
|
end = i;
|
|
}
|
|
} else {
|
|
extIdx = -1;
|
|
end = firstNonSlashEnd;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (start === end) end = firstNonSlashEnd;
|
|
else if (end === -1) end = path.length;
|
|
return path.substring(start, end);
|
|
}
|
|
for (let i = path.length - 1; i >= 0; --i) {
|
|
if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) {
|
|
if (!matchedSlash) {
|
|
start = i + 1;
|
|
break;
|
|
}
|
|
} else if (end === -1) {
|
|
matchedSlash = false;
|
|
end = i + 1;
|
|
}
|
|
}
|
|
if (end === -1) return "";
|
|
return path.substring(start, end);
|
|
};
|
|
exports.extname = function extname(path) {
|
|
let startDot = -1;
|
|
let startPart = 0;
|
|
let end = -1;
|
|
let matchedSlash = true;
|
|
let preDotState = 0;
|
|
for (let i = path.length - 1; i >= 0; --i) {
|
|
const code = path.charCodeAt(i);
|
|
if (code === CHAR_FORWARD_SLASH) {
|
|
if (!matchedSlash) {
|
|
startPart = i + 1;
|
|
break;
|
|
}
|
|
continue;
|
|
}
|
|
if (end === -1) {
|
|
matchedSlash = false;
|
|
end = i + 1;
|
|
}
|
|
if (code === CHAR_DOT) {
|
|
if (startDot === -1) startDot = i;
|
|
else if (preDotState !== 1) preDotState = 1;
|
|
} else if (startDot !== -1) {
|
|
preDotState = -1;
|
|
}
|
|
}
|
|
if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
|
|
return "";
|
|
}
|
|
return path.substring(startDot, end);
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-path/lib/win32.js
|
|
var require_win32 = __commonJS({
|
|
"../../node_modules/bare-path/lib/win32.js"(exports) {
|
|
var os = require_bare_os();
|
|
var { normalizeString } = require_shared();
|
|
var {
|
|
CHAR_UPPERCASE_A,
|
|
CHAR_LOWERCASE_A,
|
|
CHAR_UPPERCASE_Z,
|
|
CHAR_LOWERCASE_Z,
|
|
CHAR_DOT,
|
|
CHAR_FORWARD_SLASH,
|
|
CHAR_BACKWARD_SLASH,
|
|
CHAR_COLON,
|
|
CHAR_QUESTION_MARK
|
|
} = require_constants2();
|
|
function isWindowsPathSeparator(code) {
|
|
return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
|
|
}
|
|
function isWindowsDeviceRoot(code) {
|
|
return code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z || code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z;
|
|
}
|
|
exports.posix = require_posix();
|
|
exports.win32 = exports;
|
|
exports.sep = "\\";
|
|
exports.delimiter = ";";
|
|
exports.resolve = function resolve(...args) {
|
|
let resolvedDevice = "";
|
|
let resolvedTail = "";
|
|
let resolvedAbsolute = false;
|
|
for (let i = args.length - 1; i >= -1; i--) {
|
|
let path;
|
|
if (i >= 0) {
|
|
path = args[i];
|
|
if (path.length === 0) continue;
|
|
} else if (resolvedDevice.length === 0) {
|
|
path = os.cwd();
|
|
} else {
|
|
path = os.getEnv(`=${resolvedDevice}`) || os.cwd();
|
|
if (path === void 0 || path.substring(0, 2).toLowerCase() !== resolvedDevice.toLowerCase() && path.charCodeAt(2) === CHAR_BACKWARD_SLASH) {
|
|
path = `${resolvedDevice}\\`;
|
|
}
|
|
}
|
|
const len = path.length;
|
|
let rootEnd = 0;
|
|
let device = "";
|
|
let isAbsolute = false;
|
|
const code = path.charCodeAt(0);
|
|
if (len === 1) {
|
|
if (isWindowsPathSeparator(code)) {
|
|
rootEnd = 1;
|
|
isAbsolute = true;
|
|
}
|
|
} else if (isWindowsPathSeparator(code)) {
|
|
isAbsolute = true;
|
|
if (isWindowsPathSeparator(path.charCodeAt(1))) {
|
|
let j = 2;
|
|
let last = j;
|
|
while (j < len && !isWindowsPathSeparator(path.charCodeAt(j))) {
|
|
j++;
|
|
}
|
|
if (j < len && j !== last) {
|
|
const firstPart = path.substring(last, j);
|
|
last = j;
|
|
while (j < len && isWindowsPathSeparator(path.charCodeAt(j))) {
|
|
j++;
|
|
}
|
|
if (j < len && j !== last) {
|
|
last = j;
|
|
while (j < len && !isWindowsPathSeparator(path.charCodeAt(j))) {
|
|
j++;
|
|
}
|
|
if (j === len || j !== last) {
|
|
device = `\\\\${firstPart}\\${path.substring(last, j)}`;
|
|
rootEnd = j;
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
rootEnd = 1;
|
|
}
|
|
} else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) {
|
|
device = path.substring(0, 2);
|
|
rootEnd = 2;
|
|
if (len > 2 && isWindowsPathSeparator(path.charCodeAt(2))) {
|
|
isAbsolute = true;
|
|
rootEnd = 3;
|
|
}
|
|
}
|
|
if (device.length > 0) {
|
|
if (resolvedDevice.length > 0) {
|
|
if (device.toLowerCase() !== resolvedDevice.toLowerCase()) {
|
|
continue;
|
|
}
|
|
} else {
|
|
resolvedDevice = device;
|
|
}
|
|
}
|
|
if (resolvedAbsolute) {
|
|
if (resolvedDevice.length > 0) {
|
|
break;
|
|
}
|
|
} else {
|
|
resolvedTail = `${path.substring(rootEnd)}\\${resolvedTail}`;
|
|
resolvedAbsolute = isAbsolute;
|
|
if (isAbsolute && resolvedDevice.length > 0) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
resolvedTail = normalizeString(resolvedTail, !resolvedAbsolute, "\\", isWindowsPathSeparator);
|
|
return resolvedAbsolute ? `${resolvedDevice}\\${resolvedTail}` : `${resolvedDevice}${resolvedTail}` || ".";
|
|
};
|
|
exports.normalize = function normalize(path) {
|
|
const len = path.length;
|
|
if (len === 0) return ".";
|
|
let rootEnd = 0;
|
|
let device;
|
|
let isAbsolute = false;
|
|
const code = path.charCodeAt(0);
|
|
if (len === 1) {
|
|
return code === CHAR_FORWARD_SLASH ? "\\" : path;
|
|
}
|
|
if (isWindowsPathSeparator(code)) {
|
|
isAbsolute = true;
|
|
if (isWindowsPathSeparator(path.charCodeAt(1))) {
|
|
let j = 2;
|
|
let last = j;
|
|
while (j < len && !isWindowsPathSeparator(path.charCodeAt(j))) {
|
|
j++;
|
|
}
|
|
if (j < len && j !== last) {
|
|
const firstPart = path.substring(last, j);
|
|
last = j;
|
|
while (j < len && isWindowsPathSeparator(path.charCodeAt(j))) {
|
|
j++;
|
|
}
|
|
if (j < len && j !== last) {
|
|
last = j;
|
|
while (j < len && !isWindowsPathSeparator(path.charCodeAt(j))) {
|
|
j++;
|
|
}
|
|
if (j === len) {
|
|
return `\\\\${firstPart}\\${path.substring(last)}\\`;
|
|
}
|
|
if (j !== last) {
|
|
device = `\\\\${firstPart}\\${path.substring(last, j)}`;
|
|
rootEnd = j;
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
rootEnd = 1;
|
|
}
|
|
} else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) {
|
|
device = path.substring(0, 2);
|
|
rootEnd = 2;
|
|
if (len > 2 && isWindowsPathSeparator(path.charCodeAt(2))) {
|
|
isAbsolute = true;
|
|
rootEnd = 3;
|
|
}
|
|
}
|
|
let tail = rootEnd < len ? normalizeString(path.substring(rootEnd), !isAbsolute, "\\", isWindowsPathSeparator) : "";
|
|
if (tail.length === 0 && !isAbsolute) {
|
|
tail = ".";
|
|
}
|
|
if (tail.length > 0 && isWindowsPathSeparator(path.charCodeAt(len - 1))) {
|
|
tail += "\\";
|
|
}
|
|
if (device === void 0) {
|
|
return isAbsolute ? `\\${tail}` : tail;
|
|
}
|
|
return isAbsolute ? `${device}\\${tail}` : `${device}${tail}`;
|
|
};
|
|
exports.isAbsolute = function isAbsolute(path) {
|
|
const len = path.length;
|
|
if (len === 0) return false;
|
|
const code = path.charCodeAt(0);
|
|
return isWindowsPathSeparator(code) || len > 2 && isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON && isWindowsPathSeparator(path.charCodeAt(2));
|
|
};
|
|
exports.join = function join(...args) {
|
|
if (args.length === 0) return ".";
|
|
let joined;
|
|
let firstPart;
|
|
for (let i = 0; i < args.length; ++i) {
|
|
const arg = args[i];
|
|
if (arg.length > 0) {
|
|
if (joined === void 0) joined = firstPart = arg;
|
|
else joined += `\\${arg}`;
|
|
}
|
|
}
|
|
if (joined === void 0) return ".";
|
|
let needsReplace = true;
|
|
let slashCount = 0;
|
|
if (isWindowsPathSeparator(firstPart.charCodeAt(0))) {
|
|
++slashCount;
|
|
const firstLen = firstPart.length;
|
|
if (firstLen > 1 && isWindowsPathSeparator(firstPart.charCodeAt(1))) {
|
|
++slashCount;
|
|
if (firstLen > 2) {
|
|
if (isWindowsPathSeparator(firstPart.charCodeAt(2))) {
|
|
++slashCount;
|
|
} else {
|
|
needsReplace = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (needsReplace) {
|
|
while (slashCount < joined.length && isWindowsPathSeparator(joined.charCodeAt(slashCount))) {
|
|
slashCount++;
|
|
}
|
|
if (slashCount >= 2) {
|
|
joined = `\\${joined.substring(slashCount)}`;
|
|
}
|
|
}
|
|
return exports.normalize(joined);
|
|
};
|
|
exports.relative = function relative(from, to) {
|
|
if (from === to) return "";
|
|
const fromOrig = exports.resolve(from);
|
|
const toOrig = exports.resolve(to);
|
|
if (fromOrig === toOrig) return "";
|
|
from = fromOrig.toLowerCase();
|
|
to = toOrig.toLowerCase();
|
|
if (from === to) return "";
|
|
let fromStart = 0;
|
|
while (fromStart < from.length && from.charCodeAt(fromStart) === CHAR_BACKWARD_SLASH) {
|
|
fromStart++;
|
|
}
|
|
let fromEnd = from.length;
|
|
while (fromEnd - 1 > fromStart && from.charCodeAt(fromEnd - 1) === CHAR_BACKWARD_SLASH) {
|
|
fromEnd--;
|
|
}
|
|
const fromLen = fromEnd - fromStart;
|
|
let toStart = 0;
|
|
while (toStart < to.length && to.charCodeAt(toStart) === CHAR_BACKWARD_SLASH) {
|
|
toStart++;
|
|
}
|
|
let toEnd = to.length;
|
|
while (toEnd - 1 > toStart && to.charCodeAt(toEnd - 1) === CHAR_BACKWARD_SLASH) {
|
|
toEnd--;
|
|
}
|
|
const toLen = toEnd - toStart;
|
|
const length = fromLen < toLen ? fromLen : toLen;
|
|
let lastCommonSep = -1;
|
|
let i = 0;
|
|
for (; i < length; i++) {
|
|
const fromCode = from.charCodeAt(fromStart + i);
|
|
if (fromCode !== to.charCodeAt(toStart + i)) {
|
|
break;
|
|
} else if (fromCode === CHAR_BACKWARD_SLASH) {
|
|
lastCommonSep = i;
|
|
}
|
|
}
|
|
if (i !== length) {
|
|
if (lastCommonSep === -1) return toOrig;
|
|
} else {
|
|
if (toLen > length) {
|
|
if (to.charCodeAt(toStart + i) === CHAR_BACKWARD_SLASH) {
|
|
return toOrig.substring(toStart + i + 1);
|
|
}
|
|
if (i === 2) {
|
|
return toOrig.substring(toStart + i);
|
|
}
|
|
}
|
|
if (fromLen > length) {
|
|
if (from.charCodeAt(fromStart + i) === CHAR_BACKWARD_SLASH) {
|
|
lastCommonSep = i;
|
|
} else if (i === 2) {
|
|
lastCommonSep = 3;
|
|
}
|
|
}
|
|
if (lastCommonSep === -1) lastCommonSep = 0;
|
|
}
|
|
let out = "";
|
|
for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
|
|
if (i === fromEnd || from.charCodeAt(i) === CHAR_BACKWARD_SLASH) {
|
|
out += out.length === 0 ? ".." : "\\..";
|
|
}
|
|
}
|
|
toStart += lastCommonSep;
|
|
if (out.length > 0) {
|
|
return `${out}${toOrig.substring(toStart, toEnd)}`;
|
|
}
|
|
if (toOrig.charCodeAt(toStart) === CHAR_BACKWARD_SLASH) {
|
|
++toStart;
|
|
}
|
|
return toOrig.substring(toStart, toEnd);
|
|
};
|
|
exports.toNamespacedPath = function toNamespacedPath(path) {
|
|
if (path.length === 0) return path;
|
|
const resolvedPath = exports.resolve(path);
|
|
if (resolvedPath.length <= 2) return path;
|
|
if (resolvedPath.charCodeAt(0) === CHAR_BACKWARD_SLASH) {
|
|
if (resolvedPath.charCodeAt(1) === CHAR_BACKWARD_SLASH) {
|
|
const code = resolvedPath.charCodeAt(2);
|
|
if (code !== CHAR_QUESTION_MARK && code !== CHAR_DOT) {
|
|
return `\\\\?\\UNC\\${resolvedPath.substring(2)}`;
|
|
}
|
|
}
|
|
} else if (isWindowsDeviceRoot(resolvedPath.charCodeAt(0)) && resolvedPath.charCodeAt(1) === CHAR_COLON && resolvedPath.charCodeAt(2) === CHAR_BACKWARD_SLASH) {
|
|
return `\\\\?\\${resolvedPath}`;
|
|
}
|
|
return path;
|
|
};
|
|
exports.dirname = function dirname(path) {
|
|
const len = path.length;
|
|
if (len === 0) return ".";
|
|
let rootEnd = -1;
|
|
let offset = 0;
|
|
const code = path.charCodeAt(0);
|
|
if (len === 1) {
|
|
return isWindowsPathSeparator(code) ? path : ".";
|
|
}
|
|
if (isWindowsPathSeparator(code)) {
|
|
rootEnd = offset = 1;
|
|
if (isWindowsPathSeparator(path.charCodeAt(1))) {
|
|
let j = 2;
|
|
let last = j;
|
|
while (j < len && !isWindowsPathSeparator(path.charCodeAt(j))) {
|
|
j++;
|
|
}
|
|
if (j < len && j !== last) {
|
|
last = j;
|
|
while (j < len && isWindowsPathSeparator(path.charCodeAt(j))) {
|
|
j++;
|
|
}
|
|
if (j < len && j !== last) {
|
|
last = j;
|
|
while (j < len && !isWindowsPathSeparator(path.charCodeAt(j))) {
|
|
j++;
|
|
}
|
|
if (j === len) {
|
|
return path;
|
|
}
|
|
if (j !== last) {
|
|
rootEnd = offset = j + 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) {
|
|
rootEnd = len > 2 && isWindowsPathSeparator(path.charCodeAt(2)) ? 3 : 2;
|
|
offset = rootEnd;
|
|
}
|
|
let end = -1;
|
|
let matchedSlash = true;
|
|
for (let i = len - 1; i >= offset; --i) {
|
|
if (isWindowsPathSeparator(path.charCodeAt(i))) {
|
|
if (!matchedSlash) {
|
|
end = i;
|
|
break;
|
|
}
|
|
} else {
|
|
matchedSlash = false;
|
|
}
|
|
}
|
|
if (end === -1) {
|
|
if (rootEnd === -1) return ".";
|
|
end = rootEnd;
|
|
}
|
|
return path.substring(0, end);
|
|
};
|
|
exports.basename = function basename(path, suffix) {
|
|
let start = 0;
|
|
let end = -1;
|
|
let matchedSlash = true;
|
|
if (path.length >= 2 && isWindowsDeviceRoot(path.charCodeAt(0)) && path.charCodeAt(1) === CHAR_COLON) {
|
|
start = 2;
|
|
}
|
|
if (suffix !== void 0 && suffix.length > 0 && suffix.length <= path.length) {
|
|
if (suffix === path) return "";
|
|
let extIdx = suffix.length - 1;
|
|
let firstNonSlashEnd = -1;
|
|
for (let i = path.length - 1; i >= start; --i) {
|
|
const code = path.charCodeAt(i);
|
|
if (isWindowsPathSeparator(code)) {
|
|
if (!matchedSlash) {
|
|
start = i + 1;
|
|
break;
|
|
}
|
|
} else {
|
|
if (firstNonSlashEnd === -1) {
|
|
matchedSlash = false;
|
|
firstNonSlashEnd = i + 1;
|
|
}
|
|
if (extIdx >= 0) {
|
|
if (code === suffix.charCodeAt(extIdx)) {
|
|
if (--extIdx === -1) {
|
|
end = i;
|
|
}
|
|
} else {
|
|
extIdx = -1;
|
|
end = firstNonSlashEnd;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (start === end) end = firstNonSlashEnd;
|
|
else if (end === -1) end = path.length;
|
|
return path.substring(start, end);
|
|
}
|
|
for (let i = path.length - 1; i >= start; --i) {
|
|
if (isWindowsPathSeparator(path.charCodeAt(i))) {
|
|
if (!matchedSlash) {
|
|
start = i + 1;
|
|
break;
|
|
}
|
|
} else if (end === -1) {
|
|
matchedSlash = false;
|
|
end = i + 1;
|
|
}
|
|
}
|
|
if (end === -1) return "";
|
|
return path.substring(start, end);
|
|
};
|
|
exports.extname = function extname(path) {
|
|
let start = 0;
|
|
let startDot = -1;
|
|
let startPart = 0;
|
|
let end = -1;
|
|
let matchedSlash = true;
|
|
let preDotState = 0;
|
|
if (path.length >= 2 && path.charCodeAt(1) === CHAR_COLON && isWindowsDeviceRoot(path.charCodeAt(0))) {
|
|
start = startPart = 2;
|
|
}
|
|
for (let i = path.length - 1; i >= start; --i) {
|
|
const code = path.charCodeAt(i);
|
|
if (isWindowsPathSeparator(code)) {
|
|
if (!matchedSlash) {
|
|
startPart = i + 1;
|
|
break;
|
|
}
|
|
continue;
|
|
}
|
|
if (end === -1) {
|
|
matchedSlash = false;
|
|
end = i + 1;
|
|
}
|
|
if (code === CHAR_DOT) {
|
|
if (startDot === -1) startDot = i;
|
|
else if (preDotState !== 1) preDotState = 1;
|
|
} else if (startDot !== -1) {
|
|
preDotState = -1;
|
|
}
|
|
}
|
|
if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
|
|
return "";
|
|
}
|
|
return path.substring(startDot, end);
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-path/index.js
|
|
var require_bare_path = __commonJS({
|
|
"../../node_modules/bare-path/index.js"(exports, module) {
|
|
if (Bare.platform === "win32") {
|
|
module.exports = require_win32();
|
|
} else {
|
|
module.exports = require_posix();
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-url/binding.js
|
|
var require_binding3 = __commonJS({
|
|
"../../node_modules/bare-url/binding.js"(exports, module) {
|
|
module.exports = __require.addon();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-url/lib/errors.js
|
|
var require_errors3 = __commonJS({
|
|
"../../node_modules/bare-url/lib/errors.js"(exports, module) {
|
|
module.exports = class URLError extends Error {
|
|
constructor(msg, fn = URLError, code = fn.name) {
|
|
super(`${code}: ${msg}`);
|
|
this.code = code;
|
|
if (Error.captureStackTrace) Error.captureStackTrace(this, fn);
|
|
}
|
|
get name() {
|
|
return "URLError";
|
|
}
|
|
static INVALID_URL(msg, input) {
|
|
const err = new URLError(msg, URLError.INVALID_URL);
|
|
err.input = input;
|
|
return err;
|
|
}
|
|
static INVALID_URL_SCHEME(msg = "Invalid URL") {
|
|
return new URLError(msg, URLError.INVALID_URL_SCHEME);
|
|
}
|
|
static INVALID_FILE_URL_HOST(msg = "Invalid file: URL host") {
|
|
return new URLError(msg, URLError.INVALID_FILE_URL_HOST);
|
|
}
|
|
static INVALID_FILE_URL_PATH(msg = "Invalid file: URL path") {
|
|
return new URLError(msg, URLError.INVALID_FILE_URL_PATH);
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-url/lib/url-search-params.js
|
|
var require_url_search_params = __commonJS({
|
|
"../../node_modules/bare-url/lib/url-search-params.js"(exports, module) {
|
|
var kind = Symbol.for("bare.url.search-params.kind");
|
|
var URLSearchParams = class _URLSearchParams {
|
|
static _urls = /* @__PURE__ */ new WeakMap();
|
|
static get [kind]() {
|
|
return 0;
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-urlsearchparams-urlsearchparams
|
|
constructor(init, url = null) {
|
|
this._params = /* @__PURE__ */ new Map();
|
|
if (url) _URLSearchParams._urls.set(this, url);
|
|
if (typeof init === "string") {
|
|
this._parse(init);
|
|
} else if (init) {
|
|
for (const [name, value] of typeof init[Symbol.iterator] === "function" ? init : Object.entries(init)) {
|
|
this.append(name, value);
|
|
}
|
|
}
|
|
}
|
|
get [kind]() {
|
|
return _URLSearchParams[kind];
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-urlsearchparams-size
|
|
get size() {
|
|
return this._params.length;
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-urlsearchparams-append
|
|
append(name, value = null) {
|
|
if (value === null) return;
|
|
let list = this._params.get(name);
|
|
if (list === void 0) {
|
|
list = [];
|
|
this._params.set(name, list);
|
|
}
|
|
list.push(value);
|
|
this._update();
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-urlsearchparams-delete
|
|
delete(name, value = null) {
|
|
if (value === null) this._params.delete(name);
|
|
else {
|
|
let list = this._params.get(name);
|
|
if (list === void 0) return;
|
|
list = list.filter((found) => found !== value);
|
|
if (list.length === 0) this._params.delete(name);
|
|
else this._params.set(name, list);
|
|
}
|
|
this._update();
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-urlsearchparams-get
|
|
get(name) {
|
|
const list = this._params.get(name);
|
|
if (list === void 0) return null;
|
|
return list[0];
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-urlsearchparams-getall
|
|
getAll(name) {
|
|
const list = this._params.get(name);
|
|
if (list === void 0) return [];
|
|
return Array.from(list);
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-urlsearchparams-has
|
|
has(name, value = null) {
|
|
const list = this._params.get(name);
|
|
if (list === void 0) return false;
|
|
if (value === null) return true;
|
|
return list.includes(value);
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-urlsearchparams-set
|
|
set(name, value = null) {
|
|
if (value === null) this._params.delete(name);
|
|
else this._params.set(name, [value]);
|
|
this._update();
|
|
}
|
|
toString() {
|
|
return this._serialize();
|
|
}
|
|
toJSON() {
|
|
return [...this];
|
|
}
|
|
*[Symbol.iterator]() {
|
|
for (const [name, values] of this._params) {
|
|
for (const value of values) yield [name, value];
|
|
}
|
|
}
|
|
[Symbol.for("bare.inspect")]() {
|
|
const object = {
|
|
__proto__: { constructor: _URLSearchParams }
|
|
};
|
|
for (const [name, values] of this._params) {
|
|
if (values.length === 1) object[name] = values[0];
|
|
else object[name] = values;
|
|
}
|
|
return object;
|
|
}
|
|
// https://url.spec.whatwg.org/#concept-urlsearchparams-update
|
|
_update() {
|
|
const url = _URLSearchParams._urls.get(this);
|
|
if (url === void 0) return;
|
|
url.search = this._serialize();
|
|
}
|
|
// https://url.spec.whatwg.org/#concept-urlencoded-parser
|
|
_parse(input) {
|
|
if (input[0] === "?") input = input.substring(1);
|
|
this._params = /* @__PURE__ */ new Map();
|
|
for (const sequence of input.split("&")) {
|
|
if (sequence.length === 0) continue;
|
|
let i = sequence.indexOf("=");
|
|
if (i === -1) i = sequence.length;
|
|
const name = decodeURIComponent(sequence.substring(0, i));
|
|
const value = decodeURIComponent(sequence.substring(i + 1, sequence.length));
|
|
let list = this._params.get(name);
|
|
if (list === void 0) {
|
|
list = [];
|
|
this._params.set(name, list);
|
|
}
|
|
list.push(value);
|
|
}
|
|
}
|
|
// https://url.spec.whatwg.org/#concept-urlencoded-serializer
|
|
_serialize() {
|
|
let output = "";
|
|
for (let [name, values] of this._params) {
|
|
name = encodeURIComponent(name);
|
|
for (const value of values) {
|
|
if (output) output += "&";
|
|
output += name + "=" + encodeURIComponent(value);
|
|
}
|
|
}
|
|
return output;
|
|
}
|
|
};
|
|
module.exports = exports = URLSearchParams;
|
|
exports.isURLSearchParams = function isURLSearchParams(value) {
|
|
if (value instanceof URLSearchParams) return true;
|
|
return typeof value === "object" && value !== null && value[kind] === URLSearchParams[kind];
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-url/index.js
|
|
var require_bare_url = __commonJS({
|
|
"../../node_modules/bare-url/index.js"(exports, module) {
|
|
var path = require_bare_path();
|
|
var binding = require_binding3();
|
|
var errors = require_errors3();
|
|
var URLSearchParams = require_url_search_params();
|
|
var kind = Symbol.for("bare.url.kind");
|
|
var isWindows = Bare.platform === "win32";
|
|
var URL2 = class _URL {
|
|
static get [kind]() {
|
|
return 0;
|
|
}
|
|
constructor(input, base, opts = {}) {
|
|
if (arguments.length === 0) throw errors.INVALID_URL();
|
|
input = String(input);
|
|
if (base !== void 0) base = String(base);
|
|
this._components = new Uint32Array(8);
|
|
this._parse(input, base, opts.throw !== false);
|
|
if (this._href) this._params = new URLSearchParams(this.search, this);
|
|
}
|
|
get [kind]() {
|
|
return _URL[kind];
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-url-href
|
|
get href() {
|
|
return this._href;
|
|
}
|
|
set href(value) {
|
|
this._update(value);
|
|
this._params._parse(this.search);
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-url-protocol
|
|
get protocol() {
|
|
return this._slice(0, this._components[0]) + ":";
|
|
}
|
|
set protocol(value) {
|
|
this._update(this._replace(value.replace(/:+$/, ""), 0, this._components[0]));
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-url-username
|
|
get username() {
|
|
return this._slice(this._components[0] + 3, this._components[1]);
|
|
}
|
|
set username(value) {
|
|
if (cannotHaveCredentialsOrPort(this)) {
|
|
return;
|
|
}
|
|
if (this.username === "") value += "@";
|
|
this._update(this._replace(value, this._components[0] + 3, this._components[1]));
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-url-password
|
|
get password() {
|
|
return this._href.slice(
|
|
this._components[1] + 1,
|
|
this._components[2] - 1
|
|
/* @ */
|
|
);
|
|
}
|
|
set password(value) {
|
|
if (cannotHaveCredentialsOrPort(this)) {
|
|
return;
|
|
}
|
|
let start = this._components[1] + 1;
|
|
let end = this._components[2] - 1;
|
|
if (this.password === "") {
|
|
value = ":" + value;
|
|
start--;
|
|
}
|
|
if (this.username === "") {
|
|
value += "@";
|
|
end++;
|
|
}
|
|
this._update(this._replace(value, start, end));
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-url-host
|
|
get host() {
|
|
return this._slice(this._components[2], this._components[5]);
|
|
}
|
|
set host(value) {
|
|
if (hasOpaquePath(this)) {
|
|
return;
|
|
}
|
|
this._update(
|
|
this._replace(value, this._components[2], this._components[value.includes(":") ? 5 : 3])
|
|
);
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-url-hostname
|
|
get hostname() {
|
|
return this._slice(this._components[2], this._components[3]);
|
|
}
|
|
set hostname(value) {
|
|
if (hasOpaquePath(this)) {
|
|
return;
|
|
}
|
|
this._update(this._replace(value, this._components[2], this._components[3]));
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-url-port
|
|
get port() {
|
|
return this._slice(this._components[3] + 1, this._components[5]);
|
|
}
|
|
set port(value) {
|
|
if (cannotHaveCredentialsOrPort(this)) {
|
|
return;
|
|
}
|
|
let start = this._components[3] + 1;
|
|
if (this.port === "") {
|
|
value = ":" + value;
|
|
start--;
|
|
}
|
|
this._update(this._replace(value, start, this._components[5]));
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-url-pathname
|
|
get pathname() {
|
|
return this._slice(
|
|
this._components[5],
|
|
this._components[6] - 1
|
|
/* ? */
|
|
);
|
|
}
|
|
set pathname(value) {
|
|
if (hasOpaquePath(this)) {
|
|
return;
|
|
}
|
|
if (value[0] !== "/" && value[0] !== "\\") {
|
|
value = "/" + value;
|
|
}
|
|
this._update(this._replace(
|
|
value,
|
|
this._components[5],
|
|
this._components[6] - 1
|
|
/* ? */
|
|
));
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-url-search
|
|
get search() {
|
|
return this._slice(
|
|
this._components[6] - 1,
|
|
this._components[7] - 1
|
|
/* # */
|
|
);
|
|
}
|
|
set search(value) {
|
|
if (value && value[0] !== "?") value = "?" + value;
|
|
this._update(
|
|
this._replace(
|
|
value,
|
|
this._components[6] - 1,
|
|
this._components[7] - 1
|
|
/* # */
|
|
)
|
|
);
|
|
this._params._parse(this.search);
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-url-searchparams
|
|
get searchParams() {
|
|
return this._params;
|
|
}
|
|
// https://url.spec.whatwg.org/#dom-url-hash
|
|
get hash() {
|
|
return this._slice(
|
|
this._components[7] - 1
|
|
/* # */
|
|
);
|
|
}
|
|
set hash(value) {
|
|
if (value && value[0] !== "#") value = "#" + value;
|
|
this._update(this._replace(
|
|
value,
|
|
this._components[7] - 1
|
|
/* # */
|
|
));
|
|
}
|
|
toString() {
|
|
return this._href;
|
|
}
|
|
toJSON() {
|
|
return this._href;
|
|
}
|
|
[Symbol.for("bare.inspect")]() {
|
|
return {
|
|
__proto__: { constructor: _URL },
|
|
href: this.href,
|
|
protocol: this.protocol,
|
|
username: this.username,
|
|
password: this.password,
|
|
host: this.host,
|
|
hostname: this.hostname,
|
|
port: this.port,
|
|
pathname: this.pathname,
|
|
search: this.search,
|
|
searchParams: this.searchParams,
|
|
hash: this.hash
|
|
};
|
|
}
|
|
_slice(start, end = this._href.length) {
|
|
return this._href.slice(start, end);
|
|
}
|
|
_replace(replacement, start, end = this._href.length) {
|
|
return this._slice(0, start) + replacement + this._slice(end);
|
|
}
|
|
_parse(input, base, shouldThrow) {
|
|
try {
|
|
this._href = binding.parse(
|
|
String(input),
|
|
base ? String(base) : null,
|
|
this._components,
|
|
shouldThrow
|
|
);
|
|
} catch (err) {
|
|
if (err instanceof TypeError) throw err;
|
|
throw errors.INVALID_URL(`Invalid URL '${input}'`, input);
|
|
}
|
|
}
|
|
_update(input) {
|
|
try {
|
|
this._parse(input, null, true);
|
|
} catch (err) {
|
|
if (err instanceof TypeError) throw err;
|
|
}
|
|
}
|
|
};
|
|
module.exports = exports = URL2;
|
|
function hasOpaquePath(url) {
|
|
return url.pathname[0] !== "/";
|
|
}
|
|
function cannotHaveCredentialsOrPort(url) {
|
|
return url.hostname === "" || url.protocol === "file:";
|
|
}
|
|
exports.URL = URL2;
|
|
exports.URLSearchParams = URLSearchParams;
|
|
exports.errors = errors;
|
|
exports.isURL = function isURL(value) {
|
|
if (value instanceof URL2) return true;
|
|
return typeof value === "object" && value !== null && value[kind] === URL2[kind];
|
|
};
|
|
exports.isURLSearchParams = URLSearchParams.isURLSearchParams;
|
|
exports.parse = function parse(input, base) {
|
|
const url = new URL2(input, base, { throw: false });
|
|
return url._href ? url : null;
|
|
};
|
|
exports.canParse = function canParse(input, base) {
|
|
return binding.canParse(String(input), base ? String(base) : null);
|
|
};
|
|
exports.fileURLToPath = function fileURLToPath(url) {
|
|
if (typeof url === "string") {
|
|
url = new URL2(url);
|
|
}
|
|
if (url.protocol !== "file:") {
|
|
throw errors.INVALID_URL_SCHEME("The URL must use the file: protocol");
|
|
}
|
|
if (isWindows) {
|
|
if (/%2f|%5c/i.test(url.pathname)) {
|
|
throw errors.INVALID_FILE_URL_PATH(
|
|
"The file: URL path must not include encoded \\ or / characters"
|
|
);
|
|
}
|
|
} else {
|
|
if (url.hostname) {
|
|
throw errors.INVALID_FILE_URL_HOST("The file: URL host must be 'localhost' or empty");
|
|
}
|
|
if (/%2f/i.test(url.pathname)) {
|
|
throw errors.INVALID_FILE_URL_PATH("The file: URL path must not include encoded / characters");
|
|
}
|
|
}
|
|
const pathname = path.normalize(decodeURIComponent(url.pathname));
|
|
if (isWindows) {
|
|
if (url.hostname) return "\\\\" + url.hostname + pathname;
|
|
const letter = pathname.charCodeAt(1) | 32;
|
|
if (letter < 97 || letter > 122 || pathname.charCodeAt(2) !== 58) {
|
|
throw errors.INVALID_FILE_URL_PATH("The file: URL path must be absolute");
|
|
}
|
|
return pathname.slice(1);
|
|
}
|
|
return pathname;
|
|
};
|
|
exports.pathToFileURL = function pathToFileURL(pathname) {
|
|
let resolved = path.resolve(pathname);
|
|
if (pathname[pathname.length - 1] === "/") {
|
|
resolved += "/";
|
|
} else if (isWindows && pathname[pathname.length - 1] === "\\") {
|
|
resolved += "\\";
|
|
}
|
|
resolved = resolved.replaceAll("%", "%25").replaceAll("#", "%23").replaceAll("?", "%3f").replaceAll("\n", "%0a").replaceAll("\r", "%0d").replaceAll(" ", "%09");
|
|
if (!isWindows) {
|
|
resolved = resolved.replaceAll("\\", "%5c");
|
|
}
|
|
return new URL2("file:" + resolved);
|
|
};
|
|
exports.format = function format(parts) {
|
|
const { protocol, auth, host, hostname, port, pathname, search, query, hash, slashes } = parts;
|
|
let result = "";
|
|
if (typeof protocol === "string") {
|
|
result += protocol;
|
|
if (protocol[protocol.length - 1] !== ":") {
|
|
result += ":";
|
|
}
|
|
if (slashes === true || /https?|ftp|gopher|file/.test(protocol)) {
|
|
result += "//";
|
|
}
|
|
}
|
|
if (typeof auth === "string") {
|
|
if (host || hostname) result += auth + "@";
|
|
}
|
|
if (typeof host === "string") result += host;
|
|
else {
|
|
result += hostname;
|
|
if (port) result += ":" + port;
|
|
}
|
|
if (typeof pathname === "string" && pathname !== "") {
|
|
if (pathname[0] !== "/") result += "/";
|
|
result += pathname;
|
|
}
|
|
if (typeof search === "string") {
|
|
if (search[0] !== "?") result += "?";
|
|
result += search;
|
|
} else if (typeof query === "object" && query !== null) {
|
|
result += "?" + new URLSearchParams(query);
|
|
}
|
|
if (typeof hash === "string") {
|
|
if (hash[0] !== "#") result += "#";
|
|
result += hash;
|
|
}
|
|
return result;
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-buffer/binding.js
|
|
var require_binding4 = __commonJS({
|
|
"../../node_modules/bare-buffer/binding.js"(exports, module) {
|
|
module.exports = __require.addon();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-buffer/lib/constants.js
|
|
var require_constants3 = __commonJS({
|
|
"../../node_modules/bare-buffer/lib/constants.js"(exports, module) {
|
|
var binding = require_binding4();
|
|
module.exports = binding.constants;
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-buffer/lib/ascii.js
|
|
var require_ascii = __commonJS({
|
|
"../../node_modules/bare-buffer/lib/ascii.js"(exports) {
|
|
var binding = require_binding4();
|
|
exports.byteLength = function byteLength(string) {
|
|
return string.length;
|
|
};
|
|
exports.toString = function toString(buffer) {
|
|
const len = buffer.byteLength;
|
|
let result = "";
|
|
for (let i = 0; i < len; i++) {
|
|
result += String.fromCharCode(buffer[i] & 127);
|
|
}
|
|
return result;
|
|
};
|
|
exports.write = function write(buffer, string) {
|
|
const len = buffer.byteLength;
|
|
for (let i = 0; i < len; i++) {
|
|
buffer[i] = string.charCodeAt(i);
|
|
}
|
|
return len;
|
|
};
|
|
exports.validate = function validate(buffer) {
|
|
return binding.validateAscii(buffer.buffer, buffer.byteLength);
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-buffer/lib/base64.js
|
|
var require_base64 = __commonJS({
|
|
"../../node_modules/bare-buffer/lib/base64.js"(exports) {
|
|
var binding = require_binding4();
|
|
exports.byteLength = function byteLength(string) {
|
|
let len = string.length;
|
|
if (string.charCodeAt(len - 1) === 61) len--;
|
|
if (len > 1 && string.charCodeAt(len - 1) === 61) len--;
|
|
return len * 3 >>> 2;
|
|
};
|
|
exports.toString = function toString(buffer) {
|
|
return binding.toStringBase64(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
};
|
|
exports.write = function write(buffer, string) {
|
|
return binding.writeBase64(buffer.buffer, buffer.byteOffset, buffer.byteLength, string);
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-buffer/lib/base64url.js
|
|
var require_base64url = __commonJS({
|
|
"../../node_modules/bare-buffer/lib/base64url.js"(exports) {
|
|
var binding = require_binding4();
|
|
exports.byteLength = function byteLength(string) {
|
|
let len = string.length;
|
|
if (string.charCodeAt(len - 1) === 61) len--;
|
|
if (len > 1 && string.charCodeAt(len - 1) === 61) len--;
|
|
return len * 3 >>> 2;
|
|
};
|
|
exports.toString = function toString(buffer) {
|
|
return binding.toStringBase64URL(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
};
|
|
exports.write = function write(buffer, string) {
|
|
return binding.writeBase64(buffer.buffer, buffer.byteOffset, buffer.byteLength, string);
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-buffer/lib/hex.js
|
|
var require_hex = __commonJS({
|
|
"../../node_modules/bare-buffer/lib/hex.js"(exports) {
|
|
var binding = require_binding4();
|
|
exports.byteLength = function byteLength(string) {
|
|
return string.length >>> 1;
|
|
};
|
|
exports.toString = function toString(buffer) {
|
|
return binding.toStringHex(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
};
|
|
exports.write = function write(buffer, string) {
|
|
return binding.writeHex(buffer.buffer, buffer.byteOffset, buffer.byteLength, string);
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-buffer/lib/utf8.js
|
|
var require_utf8 = __commonJS({
|
|
"../../node_modules/bare-buffer/lib/utf8.js"(exports) {
|
|
var binding = require_binding4();
|
|
exports.byteLength = function byteLength(string) {
|
|
return binding.byteLengthUTF8(string);
|
|
};
|
|
exports.toString = function toString(buffer) {
|
|
return binding.toStringUTF8(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
};
|
|
exports.write = function write(buffer, string) {
|
|
return binding.writeUTF8(buffer.buffer, buffer.byteOffset, buffer.byteLength, string);
|
|
};
|
|
exports.validate = function validate(buffer) {
|
|
return binding.validateUTF8(buffer.buffer, buffer.byteLength);
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-buffer/lib/utf16le.js
|
|
var require_utf16le = __commonJS({
|
|
"../../node_modules/bare-buffer/lib/utf16le.js"(exports) {
|
|
var binding = require_binding4();
|
|
exports.byteLength = function byteLength(string) {
|
|
return string.length * 2;
|
|
};
|
|
exports.toString = function toString(buffer) {
|
|
return binding.toStringUTF16LE(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
};
|
|
exports.write = function write(buffer, string) {
|
|
return binding.writeUTF16LE(buffer.buffer, buffer.byteOffset, buffer.byteLength, string);
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-buffer/lib/latin1.js
|
|
var require_latin1 = __commonJS({
|
|
"../../node_modules/bare-buffer/lib/latin1.js"(exports) {
|
|
var binding = require_binding4();
|
|
exports.byteLength = function byteLength(string) {
|
|
return string.length;
|
|
};
|
|
exports.toString = function toString(buffer) {
|
|
return binding.toStringLatin1(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
};
|
|
exports.write = function write(buffer, string) {
|
|
return binding.writeLatin1(buffer.buffer, buffer.byteOffset, buffer.byteLength, string);
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-buffer/index.js
|
|
var require_bare_buffer = __commonJS({
|
|
"../../node_modules/bare-buffer/index.js"(exports, module) {
|
|
var constants = require_constants3();
|
|
var ascii = require_ascii();
|
|
var base64 = require_base64();
|
|
var base64url = require_base64url();
|
|
var hex = require_hex();
|
|
var utf8 = require_utf8();
|
|
var utf16le = require_utf16le();
|
|
var latin1 = require_latin1();
|
|
var binding = require_binding4();
|
|
var kind = Symbol.for("bare.buffer.kind");
|
|
var poolSize = 0;
|
|
module.exports = exports = class Buffer3 extends Uint8Array {
|
|
static get [kind]() {
|
|
return 0;
|
|
}
|
|
static get poolSize() {
|
|
return poolSize;
|
|
}
|
|
static set poolSize(value) {
|
|
poolSize = Math.max(0, value);
|
|
}
|
|
constructor(arrayBuffer, offset, length, opts = {}) {
|
|
if (typeof arrayBuffer === "number") {
|
|
opts = offset || {};
|
|
const { uninitialized = false } = opts;
|
|
offset = 0;
|
|
length = arrayBuffer;
|
|
if (length > constants.MAX_LENGTH) {
|
|
throw new RangeError(`Buffer length must be at most ${constants.MAX_LENGTH}`);
|
|
}
|
|
arrayBuffer = uninitialized ? binding.allocUnsafe(length) : binding.alloc(length);
|
|
} else {
|
|
if (length > constants.MAX_LENGTH) {
|
|
throw new RangeError(`Buffer length must be at most ${constants.MAX_LENGTH}`);
|
|
}
|
|
if (typeof offset === "object" && offset !== null) {
|
|
opts = offset;
|
|
offset = 0;
|
|
length = arrayBuffer.byteLength;
|
|
} else if (typeof length === "length" && length !== null) {
|
|
opts = length;
|
|
length = arrayBuffer.byteLength - offset;
|
|
}
|
|
}
|
|
super(arrayBuffer, offset, length);
|
|
}
|
|
get [kind]() {
|
|
return Buffer3[kind];
|
|
}
|
|
copy(target, targetStart = 0, sourceStart = 0, sourceEnd = this.byteLength) {
|
|
let source = this;
|
|
if (targetStart < 0) targetStart = 0;
|
|
if (targetStart >= target.byteLength) return 0;
|
|
const targetLength = target.byteLength - targetStart;
|
|
if (sourceStart < 0) sourceStart = 0;
|
|
if (sourceStart >= source.byteLength) return 0;
|
|
if (sourceEnd <= sourceStart) return 0;
|
|
if (sourceEnd > source.byteLength) sourceEnd = source.byteLength;
|
|
if (sourceEnd - sourceStart > targetLength) {
|
|
sourceEnd = sourceStart + targetLength;
|
|
}
|
|
const sourceLength = sourceEnd - sourceStart;
|
|
if (source === target) {
|
|
target.copyWithin(targetStart, sourceStart, sourceEnd);
|
|
} else {
|
|
if (sourceStart !== 0 || sourceEnd !== source.byteLength) {
|
|
source = source.subarray(sourceStart, sourceEnd);
|
|
}
|
|
target.set(source, targetStart);
|
|
}
|
|
return sourceLength;
|
|
}
|
|
equals(target) {
|
|
const source = this;
|
|
if (source === target) return true;
|
|
if (source.byteLength !== target.byteLength) return false;
|
|
return binding.compare(
|
|
source.buffer,
|
|
source.byteOffset,
|
|
source.byteLength,
|
|
target.buffer,
|
|
target.byteOffset,
|
|
target.byteLength
|
|
) === 0;
|
|
}
|
|
compare(target, targetStart = 0, targetEnd = target.byteLength, sourceStart = 0, sourceEnd = this.byteLength) {
|
|
let source = this;
|
|
if (source === target) return 0;
|
|
if (arguments.length > 1) {
|
|
if (targetStart < 0) targetStart = 0;
|
|
if (targetStart > target.byteLength) targetStart = target.byteLength;
|
|
if (targetEnd < targetStart) targetEnd = targetStart;
|
|
if (targetEnd > target.byteLength) targetEnd = target.byteLength;
|
|
if (sourceStart < 0) sourceStart = 0;
|
|
if (sourceStart > source.byteLength) sourceStart = source.byteLength;
|
|
if (sourceEnd < sourceStart) sourceEnd = sourceStart;
|
|
if (sourceEnd > source.byteLength) sourceEnd = source.byteLength;
|
|
if (sourceStart !== 0 || sourceEnd !== source.byteLength) {
|
|
source = source.subarray(sourceStart, sourceEnd);
|
|
}
|
|
if (targetStart !== 0 || targetEnd !== target.byteLength) {
|
|
target = target.subarray(targetStart, targetEnd);
|
|
}
|
|
}
|
|
return binding.compare(
|
|
source.buffer,
|
|
source.byteOffset,
|
|
source.byteLength,
|
|
target.buffer,
|
|
target.byteOffset,
|
|
target.byteLength
|
|
);
|
|
}
|
|
fill(value, offset = 0, end = this.byteLength, encoding = "utf8") {
|
|
if (typeof value === "string") {
|
|
if (typeof offset === "string") {
|
|
encoding = offset;
|
|
offset = 0;
|
|
end = this.byteLength;
|
|
} else if (typeof end === "string") {
|
|
encoding = end;
|
|
end = this.byteLength;
|
|
}
|
|
} else if (typeof value === "number") {
|
|
value = value & 255;
|
|
} else if (typeof value === "boolean") {
|
|
value = +value;
|
|
}
|
|
if (offset < 0) offset = 0;
|
|
if (offset >= this.byteLength) return this;
|
|
if (end <= offset) return this;
|
|
if (end > this.byteLength) end = this.byteLength;
|
|
if (typeof value === "number") return super.fill(value, offset, end);
|
|
if (typeof value === "string") value = exports.from(value, encoding);
|
|
const length = value.byteLength;
|
|
for (let i = 0, n = end - offset; i < n; ++i) {
|
|
this[i + offset] = value[i % length];
|
|
}
|
|
return this;
|
|
}
|
|
includes(value, offset, encoding) {
|
|
return this.indexOf(value, offset, encoding) !== -1;
|
|
}
|
|
indexOf(value, offset = 0, encoding) {
|
|
if (typeof value === "boolean") value = +value;
|
|
if (typeof value === "number") {
|
|
return super.indexOf(value & 255, offset);
|
|
}
|
|
return bidirectionalIndexOf(
|
|
this,
|
|
value,
|
|
offset,
|
|
encoding,
|
|
true
|
|
/* first */
|
|
);
|
|
}
|
|
lastIndexOf(value, offset = this.byteLength - 1, encoding) {
|
|
if (typeof value === "boolean") value = +value;
|
|
if (typeof value === "number") {
|
|
return super.lastIndexOf(value & 255, offset);
|
|
}
|
|
return bidirectionalIndexOf(
|
|
this,
|
|
value,
|
|
offset,
|
|
encoding,
|
|
false
|
|
/* last */
|
|
);
|
|
}
|
|
swap16() {
|
|
const length = this.byteLength;
|
|
if (length % 2 !== 0) {
|
|
throw new RangeError("Buffer size must be a multiple of 16-bits");
|
|
}
|
|
for (let i = 0; i < length; i += 2) swap(this, i, i + 1);
|
|
return this;
|
|
}
|
|
swap32() {
|
|
const length = this.byteLength;
|
|
if (length % 4 !== 0) {
|
|
throw new RangeError("Buffer size must be a multiple of 32-bits");
|
|
}
|
|
for (let i = 0; i < length; i += 4) {
|
|
swap(this, i, i + 3);
|
|
swap(this, i + 1, i + 2);
|
|
}
|
|
return this;
|
|
}
|
|
swap64() {
|
|
const length = this.byteLength;
|
|
if (length % 8 !== 0) {
|
|
throw new RangeError("Buffer size must be a multiple of 64-bits");
|
|
}
|
|
for (let i = 0; i < length; i += 8) {
|
|
swap(this, i, i + 7);
|
|
swap(this, i + 1, i + 6);
|
|
swap(this, i + 2, i + 5);
|
|
swap(this, i + 3, i + 4);
|
|
}
|
|
return this;
|
|
}
|
|
toString(encoding = "utf8", start = 0, end = this.byteLength) {
|
|
if (arguments.length === 0) return utf8.toString(this);
|
|
if (arguments.length === 1) return codecFor(encoding).toString(this);
|
|
if (start < 0) start = 0;
|
|
if (start >= this.byteLength) return "";
|
|
if (end <= start) return "";
|
|
if (end > this.byteLength) end = this.byteLength;
|
|
let buffer = this;
|
|
if (start !== 0 || end !== this.byteLength) {
|
|
buffer = buffer.subarray(start, end);
|
|
}
|
|
return codecFor(encoding).toString(buffer);
|
|
}
|
|
toJSON() {
|
|
return Array.from(this);
|
|
}
|
|
write(string, offset = 0, length = this.byteLength - offset, encoding = "utf8") {
|
|
if (arguments.length === 1) return utf8.write(this, string);
|
|
if (typeof offset === "string") {
|
|
encoding = offset;
|
|
offset = 0;
|
|
length = this.byteLength;
|
|
} else if (typeof length === "string") {
|
|
encoding = length;
|
|
length = this.byteLength - offset;
|
|
}
|
|
length = Math.min(length, exports.byteLength(string, encoding));
|
|
let start = offset;
|
|
if (start < 0) start = 0;
|
|
if (start >= this.byteLength) return 0;
|
|
let end = offset + length;
|
|
if (end <= start) return 0;
|
|
if (end > this.byteLength) end = this.byteLength;
|
|
let buffer = this;
|
|
if (start !== 0 || end !== this.byteLength) {
|
|
buffer = buffer.subarray(start, end);
|
|
}
|
|
return codecFor(encoding).write(buffer, string);
|
|
}
|
|
readBigInt64BE(offset = 0) {
|
|
return viewOf(this).getBigInt64(offset, false);
|
|
}
|
|
readBigInt64LE(offset = 0) {
|
|
return viewOf(this).getBigInt64(offset, true);
|
|
}
|
|
readBigUint64BE(offset = 0) {
|
|
return viewOf(this).getBigUint64(offset, false);
|
|
}
|
|
readBigUint64LE(offset = 0) {
|
|
return viewOf(this).getBigUint64(offset, true);
|
|
}
|
|
readDoubleBE(offset = 0) {
|
|
return viewOf(this).getFloat64(offset, false);
|
|
}
|
|
readDoubleLE(offset = 0) {
|
|
return viewOf(this).getFloat64(offset, true);
|
|
}
|
|
readFloatBE(offset = 0) {
|
|
return viewOf(this).getFloat32(offset, false);
|
|
}
|
|
readFloatLE(offset = 0) {
|
|
return viewOf(this).getFloat32(offset, true);
|
|
}
|
|
readInt8(offset = 0) {
|
|
return viewOf(this).getInt8(offset);
|
|
}
|
|
readInt16BE(offset = 0) {
|
|
return viewOf(this).getInt16(offset, false);
|
|
}
|
|
readInt16LE(offset = 0) {
|
|
return viewOf(this).getInt16(offset, true);
|
|
}
|
|
readInt32BE(offset = 0) {
|
|
return viewOf(this).getInt32(offset, false);
|
|
}
|
|
readInt32LE(offset = 0) {
|
|
return viewOf(this).getInt32(offset, true);
|
|
}
|
|
readIntBE(offset, byteLength) {
|
|
if (byteLength === 6) return readInt48BE(viewOf(this), offset);
|
|
if (byteLength === 5) return readInt40BE(viewOf(this), offset);
|
|
if (byteLength === 3) return readInt24BE(viewOf(this), offset);
|
|
if (byteLength === 4) return this.readInt32BE(offset);
|
|
if (byteLength === 2) return this.readInt16BE(offset);
|
|
if (byteLength === 1) return this.readInt8(offset);
|
|
throw new RangeError(`Byte length must be between 1 and 6`);
|
|
}
|
|
readIntLE(offset, byteLength) {
|
|
if (byteLength === 6) return readInt48LE(viewOf(this), offset);
|
|
if (byteLength === 5) return readInt40LE(viewOf(this), offset);
|
|
if (byteLength === 3) return readInt24LE(viewOf(this), offset);
|
|
if (byteLength === 4) return this.readInt32LE(offset);
|
|
if (byteLength === 2) return this.readInt16LE(offset);
|
|
if (byteLength === 1) return this.readInt8(offset);
|
|
throw new RangeError(`Byte length must be between 1 and 6`);
|
|
}
|
|
readUint8(offset = 0) {
|
|
return viewOf(this).getUint8(offset);
|
|
}
|
|
readUint16BE(offset = 0) {
|
|
return viewOf(this).getUint16(offset, false);
|
|
}
|
|
readUint16LE(offset = 0) {
|
|
return viewOf(this).getUint16(offset, true);
|
|
}
|
|
readUint32BE(offset = 0) {
|
|
return viewOf(this).getUint32(offset, false);
|
|
}
|
|
readUint32LE(offset = 0) {
|
|
return viewOf(this).getUint32(offset, true);
|
|
}
|
|
readUintBE(offset, byteLength) {
|
|
if (byteLength === 6) return readUint48BE(viewOf(this), offset);
|
|
if (byteLength === 5) return readUint40BE(viewOf(this), offset);
|
|
if (byteLength === 3) return readUint24BE(viewOf(this), offset);
|
|
if (byteLength === 4) return this.readUint32BE(offset);
|
|
if (byteLength === 2) return this.readUint16BE(offset);
|
|
if (byteLength === 1) return this.readUint8(offset);
|
|
throw new RangeError(`Byte length must be between 1 and 6`);
|
|
}
|
|
readUintLE(offset, byteLength) {
|
|
if (byteLength === 6) return readUint48LE(viewOf(this), offset);
|
|
if (byteLength === 5) return readUint40LE(viewOf(this), offset);
|
|
if (byteLength === 3) return readUint24LE(viewOf(this), offset);
|
|
if (byteLength === 4) return this.readUint32LE(offset);
|
|
if (byteLength === 2) return this.readUint16LE(offset);
|
|
if (byteLength === 1) return this.readUint8(offset);
|
|
throw new RangeError(`Byte length must be between 1 and 6`);
|
|
}
|
|
readBigUInt64BE(...args) {
|
|
return this.readBigUint64BE(...args);
|
|
}
|
|
readBigUInt64LE(...args) {
|
|
return this.readBigUint64LE(...args);
|
|
}
|
|
readUInt8(...args) {
|
|
return this.readUint8(...args);
|
|
}
|
|
readUInt16BE(...args) {
|
|
return this.readUint16BE(...args);
|
|
}
|
|
readUInt16LE(...args) {
|
|
return this.readUint16LE(...args);
|
|
}
|
|
readUInt32BE(...args) {
|
|
return this.readUint32BE(...args);
|
|
}
|
|
readUInt32LE(...args) {
|
|
return this.readUint32LE(...args);
|
|
}
|
|
readUIntBE(...args) {
|
|
return this.readUintBE(...args);
|
|
}
|
|
readUIntLE(...args) {
|
|
return this.readUintLE(...args);
|
|
}
|
|
writeBigInt64BE(value, offset = 0) {
|
|
viewOf(this).setBigInt64(offset, value, false);
|
|
return offset + 8;
|
|
}
|
|
writeBigInt64LE(value, offset = 0) {
|
|
viewOf(this).setBigInt64(offset, value, true);
|
|
return offset + 8;
|
|
}
|
|
writeBigUint64BE(value, offset = 0) {
|
|
viewOf(this).setBigUint64(offset, value, false);
|
|
return offset + 8;
|
|
}
|
|
writeBigUint64LE(value, offset = 0) {
|
|
viewOf(this).setBigUint64(offset, value, true);
|
|
return offset + 8;
|
|
}
|
|
writeDoubleBE(value, offset = 0) {
|
|
viewOf(this).setFloat64(offset, value, false);
|
|
return offset + 8;
|
|
}
|
|
writeDoubleLE(value, offset = 0) {
|
|
viewOf(this).setFloat64(offset, value, true);
|
|
return offset + 8;
|
|
}
|
|
writeFloatBE(value, offset = 0) {
|
|
viewOf(this).setFloat32(offset, value, false);
|
|
return offset + 4;
|
|
}
|
|
writeFloatLE(value, offset = 0) {
|
|
viewOf(this).setFloat32(offset, value, true);
|
|
return offset + 4;
|
|
}
|
|
writeInt8(value, offset = 0) {
|
|
viewOf(this).setInt8(offset, value);
|
|
return offset + 1;
|
|
}
|
|
writeInt16BE(value, offset = 0) {
|
|
viewOf(this).setInt16(offset, value, false);
|
|
return offset + 2;
|
|
}
|
|
writeInt16LE(value, offset = 0) {
|
|
viewOf(this).setInt16(offset, value, true);
|
|
return offset + 2;
|
|
}
|
|
writeInt32BE(value, offset = 0) {
|
|
viewOf(this).setInt32(offset, value, false);
|
|
return offset + 4;
|
|
}
|
|
writeInt32LE(value, offset = 0) {
|
|
viewOf(this).setInt32(offset, value, true);
|
|
return offset + 4;
|
|
}
|
|
writeIntBE(value, offset, byteLength) {
|
|
if (byteLength === 6) return writeInt48BE(value, viewOf(this), offset);
|
|
if (byteLength === 5) return writeInt40BE(value, viewOf(this), offset);
|
|
if (byteLength === 3) return writeInt24BE(value, viewOf(this), offset);
|
|
if (byteLength === 4) return this.writeInt32BE(value, offset);
|
|
if (byteLength === 2) return this.writeInt16BE(value, offset);
|
|
if (byteLength === 1) return this.writeInt8(value, offset);
|
|
throw new RangeError(`Byte length must be between 1 and 6`);
|
|
}
|
|
writeIntLE(value, offset, byteLength) {
|
|
if (byteLength === 6) return writeInt48LE(value, viewOf(this), offset);
|
|
if (byteLength === 5) return writeInt40LE(value, viewOf(this), offset);
|
|
if (byteLength === 3) return writeInt24LE(value, viewOf(this), offset);
|
|
if (byteLength === 4) return this.writeInt32LE(value, offset);
|
|
if (byteLength === 2) return this.writeInt16LE(value, offset);
|
|
if (byteLength === 1) return this.writeInt8(value, offset);
|
|
throw new RangeError(`Byte length must be between 1 and 6`);
|
|
}
|
|
writeUint8(value, offset = 0) {
|
|
viewOf(this).setUint8(offset, value, true);
|
|
return offset + 1;
|
|
}
|
|
writeUint16BE(value, offset = 0) {
|
|
viewOf(this).setUint16(offset, value, false);
|
|
return offset + 2;
|
|
}
|
|
writeUint16LE(value, offset = 0) {
|
|
viewOf(this).setUint16(offset, value, true);
|
|
return offset + 2;
|
|
}
|
|
writeUint32LE(value, offset = 0) {
|
|
viewOf(this).setUint32(offset, value, true);
|
|
return offset + 4;
|
|
}
|
|
writeUint32BE(value, offset = 0) {
|
|
viewOf(this).setUint32(offset, value, false);
|
|
return offset + 4;
|
|
}
|
|
writeUintBE(value, offset, byteLength) {
|
|
if (byteLength === 6) return writeUint48BE(value, viewOf(this), offset);
|
|
if (byteLength === 5) return writeUint40BE(value, viewOf(this), offset);
|
|
if (byteLength === 3) return writeUint24BE(value, viewOf(this), offset);
|
|
if (byteLength === 4) return this.writeUint32BE(value, offset);
|
|
if (byteLength === 2) return this.writeUint16BE(value, offset);
|
|
if (byteLength === 1) return this.writeUint8(value, offset);
|
|
throw new RangeError(`Byte length must be between 1 and 6`);
|
|
}
|
|
writeUintLE(value, offset, byteLength) {
|
|
if (byteLength === 6) return writeUint48LE(value, viewOf(this), offset);
|
|
if (byteLength === 5) return writeUint40LE(value, viewOf(this), offset);
|
|
if (byteLength === 3) return writeUint24LE(value, viewOf(this), offset);
|
|
if (byteLength === 4) return this.writeUint32LE(value, offset);
|
|
if (byteLength === 2) return this.writeUint16LE(value, offset);
|
|
if (byteLength === 1) return this.writeUint8(value, offset);
|
|
throw new RangeError(`Byte length must be between 1 and 6`);
|
|
}
|
|
writeBigUInt64BE(...args) {
|
|
return this.writeBigUint64BE(...args);
|
|
}
|
|
writeBigUInt64LE(...args) {
|
|
return this.writeBigUint64LE(...args);
|
|
}
|
|
writeUInt8(...args) {
|
|
return this.writeUint8(...args);
|
|
}
|
|
writeUInt16BE(...args) {
|
|
return this.writeUint16BE(...args);
|
|
}
|
|
writeUInt16LE(...args) {
|
|
return this.writeUint16LE(...args);
|
|
}
|
|
writeUInt32BE(...args) {
|
|
return this.writeUint32BE(...args);
|
|
}
|
|
writeUInt32LE(...args) {
|
|
return this.writeUint32LE(...args);
|
|
}
|
|
writeUIntBE(...args) {
|
|
return this.writeUintBE(...args);
|
|
}
|
|
writeUIntLE(...args) {
|
|
return this.writeUintLE(...args);
|
|
}
|
|
};
|
|
var Buffer2 = exports;
|
|
exports.Buffer = Buffer2;
|
|
exports.constants = constants;
|
|
var codecs = /* @__PURE__ */ Object.create(null);
|
|
codecs.ascii = ascii;
|
|
codecs.base64 = base64;
|
|
codecs.base64url = base64url;
|
|
codecs.hex = hex;
|
|
codecs.utf8 = codecs["utf-8"] = utf8;
|
|
codecs.utf16le = codecs.ucs2 = codecs["utf-16le"] = codecs["ucs-2"] = utf16le;
|
|
codecs.latin1 = codecs.binary = latin1;
|
|
function codecFor(encoding = "utf8") {
|
|
if (encoding in codecs) return codecs[encoding];
|
|
encoding = encoding.toLowerCase();
|
|
if (encoding in codecs) return codecs[encoding];
|
|
throw new Error(`Unknown encoding '${encoding}'`);
|
|
}
|
|
var views = /* @__PURE__ */ new WeakMap();
|
|
function viewOf(buffer) {
|
|
let view = views.get(buffer);
|
|
if (view === void 0) {
|
|
view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
views.set(buffer, view);
|
|
}
|
|
return view;
|
|
}
|
|
exports.isBuffer = function isBuffer(value) {
|
|
if (value instanceof Buffer2) return true;
|
|
return typeof value === "object" && value !== null && value[kind] === Buffer2[kind];
|
|
};
|
|
exports.isEncoding = function isEncoding(encoding) {
|
|
try {
|
|
codecFor(encoding);
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
};
|
|
exports.isASCII = function isASCII(buffer) {
|
|
return ascii.validate(buffer);
|
|
};
|
|
exports.isAscii = exports.isASCII;
|
|
exports.isUTF8 = function isUTF8(buffer) {
|
|
return utf8.validate(buffer);
|
|
};
|
|
exports.isUtf8 = exports.isUTF8;
|
|
exports.alloc = function alloc(size, fill, encoding) {
|
|
const buffer = new Buffer2(size);
|
|
if (fill !== void 0) buffer.fill(fill, 0, buffer.byteLength, encoding);
|
|
return buffer;
|
|
};
|
|
exports.allocUnsafe = function allocUnsafe(size) {
|
|
return new Buffer2(size, { uninitialized: true });
|
|
};
|
|
exports.allocUnsafeSlow = function allocUnsafeSlow(size) {
|
|
return exports.allocUnsafe(size);
|
|
};
|
|
exports.byteLength = function byteLength(string, encoding) {
|
|
if (typeof string === "string") {
|
|
return codecFor(encoding).byteLength(string);
|
|
}
|
|
return string.byteLength;
|
|
};
|
|
exports.compare = function compare(a, b) {
|
|
return binding.compare(a.buffer, a.byteOffset, a.byteLength, b.buffer, b.byteOffset, b.byteLength);
|
|
};
|
|
exports.concat = function concat(buffers, length) {
|
|
if (length === void 0) {
|
|
length = buffers.reduce((length2, buffer) => length2 + buffer.byteLength, 0);
|
|
}
|
|
const result = new Buffer2(length);
|
|
for (let i = 0, n = buffers.length, offset = 0; i < n; i++) {
|
|
const buffer = buffers[i];
|
|
if (offset + buffer.byteLength > result.byteLength) {
|
|
result.set(buffer.subarray(0, result.byteLength - offset), offset);
|
|
return result;
|
|
}
|
|
result.set(buffer, offset);
|
|
offset += buffer.byteLength;
|
|
}
|
|
return result;
|
|
};
|
|
exports.coerce = function coerce(buffer) {
|
|
if (exports.isBuffer(buffer)) return buffer;
|
|
return new Buffer2(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
};
|
|
exports.copyBytesFrom = function copyBytesFrom(view, offset = 0, length = view.length - offset) {
|
|
if (offset + length > view.length) {
|
|
throw new RangeError("View length is out of range");
|
|
}
|
|
if (offset !== 0 || length !== view.length) {
|
|
view = view.subarray(offset, offset + length);
|
|
}
|
|
return new Buffer2(view.buffer.slice(view.byteOffset, view.byteOffset + view.byteLength));
|
|
};
|
|
exports.from = function from(value, encodingOrOffset, length) {
|
|
if (typeof value === "string") return fromString(value, encodingOrOffset);
|
|
if (Array.isArray(value)) return fromArray(value);
|
|
if (ArrayBuffer.isView(value)) return fromBuffer(value);
|
|
return fromArrayBuffer(value, encodingOrOffset, length);
|
|
};
|
|
function fromString(string, encoding) {
|
|
const codec = codecFor(encoding);
|
|
const buffer = new Buffer2(codec.byteLength(string));
|
|
codec.write(buffer, string);
|
|
return buffer;
|
|
}
|
|
function fromArray(array) {
|
|
const buffer = new Buffer2(array.length);
|
|
buffer.set(array);
|
|
return buffer;
|
|
}
|
|
function fromBuffer(buffer) {
|
|
const copy = new Buffer2(buffer.byteLength);
|
|
copy.set(buffer);
|
|
return copy;
|
|
}
|
|
function fromArrayBuffer(arrayBuffer, offset, length) {
|
|
return new Buffer2(arrayBuffer, offset, length);
|
|
}
|
|
function bidirectionalIndexOf(buffer, value, offset, encoding, first) {
|
|
if (buffer.byteLength === 0) return -1;
|
|
if (typeof offset === "string") {
|
|
encoding = offset;
|
|
offset = 0;
|
|
} else if (offset === void 0) {
|
|
offset = first ? 0 : buffer.byteLength - 1;
|
|
} else if (offset < 0) {
|
|
offset += buffer.byteLength;
|
|
}
|
|
if (offset >= buffer.byteLength) {
|
|
if (first) return -1;
|
|
else offset = buffer.byteLength - 1;
|
|
} else if (offset < 0) {
|
|
if (first) offset = 0;
|
|
else return -1;
|
|
}
|
|
if (typeof value === "string") value = exports.from(value, encoding);
|
|
if (value.byteLength === 0) return -1;
|
|
if (first) {
|
|
let foundIndex = -1;
|
|
for (let i = offset; i < buffer.byteLength; i++) {
|
|
if (buffer[i] === value[foundIndex === -1 ? 0 : i - foundIndex]) {
|
|
if (foundIndex === -1) foundIndex = i;
|
|
if (i - foundIndex + 1 === value.byteLength) return foundIndex;
|
|
} else {
|
|
if (foundIndex !== -1) i -= i - foundIndex;
|
|
foundIndex = -1;
|
|
}
|
|
}
|
|
} else {
|
|
if (offset + value.byteLength > buffer.byteLength) {
|
|
offset = buffer.byteLength - value.byteLength;
|
|
}
|
|
for (let i = offset; i >= 0; i--) {
|
|
let found = true;
|
|
for (let j = 0; j < value.byteLength; j++) {
|
|
if (buffer[i + j] !== value[j]) {
|
|
found = false;
|
|
break;
|
|
}
|
|
}
|
|
if (found) return i;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
function swap(buffer, n, m) {
|
|
const i = buffer[n];
|
|
buffer[n] = buffer[m];
|
|
buffer[m] = i;
|
|
}
|
|
exports.atob = function atob(data) {
|
|
return Buffer2.from(data, "base64").toString("latin1");
|
|
};
|
|
exports.btoa = function btoa(data) {
|
|
if (typeof data !== "string") data = String(data);
|
|
return Buffer2.from(data, "latin1").toString("base64");
|
|
};
|
|
exports.transcode = function transcode(buffer, from, to) {
|
|
return Buffer2.from(buffer.toString(from), to);
|
|
};
|
|
function readInt48BE(view, offset) {
|
|
const hi = view.getUint16(offset, false);
|
|
const lo = view.getUint32(offset + 2, false);
|
|
let value = lo + hi * 4294967296;
|
|
if (hi & 32768) value -= 281474976710656;
|
|
return value;
|
|
}
|
|
function readInt48LE(view, offset) {
|
|
const lo = view.getUint32(offset, true);
|
|
const hi = view.getUint16(offset + 4, true);
|
|
let value = lo + hi * 4294967296;
|
|
if (hi & 32768) value -= 281474976710656;
|
|
return value;
|
|
}
|
|
function readInt40BE(view, offset) {
|
|
const hi = view.getUint8(offset);
|
|
const lo = view.getUint32(offset + 1, false);
|
|
let value = lo + hi * 4294967296;
|
|
if (hi & 128) value -= 1099511627776;
|
|
return value;
|
|
}
|
|
function readInt40LE(view, offset) {
|
|
const lo = view.getUint32(offset, true);
|
|
const hi = view.getUint8(offset + 4);
|
|
let value = lo + hi * 4294967296;
|
|
if (hi & 128) value -= 1099511627776;
|
|
return value;
|
|
}
|
|
function readInt24BE(view, offset) {
|
|
const value = view.getUint8(offset) << 16 | view.getUint8(offset + 1) << 8 | view.getUint8(offset + 2);
|
|
return value & 8388608 ? value - 16777216 : value;
|
|
}
|
|
function readInt24LE(view, offset) {
|
|
const value = view.getUint8(offset) | view.getUint8(offset + 1) << 8 | view.getUint8(offset + 2) << 16;
|
|
return value & 8388608 ? value - 16777216 : value;
|
|
}
|
|
function readUint48BE(view, offset) {
|
|
const hi = view.getUint16(offset, false);
|
|
const lo = view.getUint32(offset + 2, false);
|
|
return lo + hi * 4294967296;
|
|
}
|
|
function readUint48LE(view, offset) {
|
|
const lo = view.getUint32(offset, true);
|
|
const hi = view.getUint16(offset + 4, true);
|
|
return lo + hi * 4294967296;
|
|
}
|
|
function readUint40BE(view, offset) {
|
|
const hi = view.getUint8(offset);
|
|
const lo = view.getUint32(offset + 1, false);
|
|
return lo + hi * 4294967296;
|
|
}
|
|
function readUint40LE(view, offset) {
|
|
const lo = view.getUint32(offset, true);
|
|
const hi = view.getUint8(offset + 4);
|
|
return lo + hi * 4294967296;
|
|
}
|
|
function readUint24BE(view, offset) {
|
|
return view.getUint8(offset) << 16 | view.getUint8(offset + 1) << 8 | view.getUint8(offset + 2);
|
|
}
|
|
function readUint24LE(view, offset) {
|
|
return view.getUint8(offset) | view.getUint8(offset + 1) << 8 | view.getUint8(offset + 2) << 16;
|
|
}
|
|
function writeInt48BE(value, view, offset) {
|
|
if (value < 0) value += 281474976710656;
|
|
const hi = Math.floor(value / 4294967296);
|
|
const lo = value >>> 0;
|
|
view.setUint16(offset, hi, false);
|
|
view.setUint32(offset + 2, lo, false);
|
|
return offset + 6;
|
|
}
|
|
function writeInt48LE(value, view, offset) {
|
|
if (value < 0) value += 281474976710656;
|
|
const hi = Math.floor(value / 4294967296);
|
|
const lo = value >>> 0;
|
|
view.setUint32(offset, lo, true);
|
|
view.setUint16(offset + 4, hi, true);
|
|
return offset + 6;
|
|
}
|
|
function writeInt40BE(value, view, offset) {
|
|
if (value < 0) value += 1099511627776;
|
|
const hi = Math.floor(value / 4294967296);
|
|
const lo = value >>> 0;
|
|
view.setUint8(offset, hi);
|
|
view.setUint32(offset + 1, lo, false);
|
|
return offset + 5;
|
|
}
|
|
function writeInt40LE(value, view, offset) {
|
|
if (value < 0) value += 1099511627776;
|
|
const hi = Math.floor(value / 4294967296);
|
|
const lo = value >>> 0;
|
|
view.setUint32(offset, lo, true);
|
|
view.setUint8(offset + 4, hi);
|
|
return offset + 5;
|
|
}
|
|
function writeInt24BE(value, view, offset) {
|
|
if (value < 0) value += 16777216;
|
|
view.setUint8(offset, value >> 16 & 255);
|
|
view.setUint8(offset + 1, value >> 8 & 255);
|
|
view.setUint8(offset + 2, value & 255);
|
|
return offset + 3;
|
|
}
|
|
function writeInt24LE(value, view, offset) {
|
|
if (value < 0) value += 16777216;
|
|
view.setUint8(offset, value & 255);
|
|
view.setUint8(offset + 1, value >> 8 & 255);
|
|
view.setUint8(offset + 2, value >> 16 & 255);
|
|
return offset + 3;
|
|
}
|
|
function writeUint48BE(value, view, offset) {
|
|
const hi = Math.floor(value / 4294967296);
|
|
const lo = value >>> 0;
|
|
view.setUint16(offset, hi, false);
|
|
view.setUint32(offset + 2, lo, false);
|
|
return offset + 6;
|
|
}
|
|
function writeUint48LE(value, view, offset) {
|
|
const hi = Math.floor(value / 4294967296);
|
|
const lo = value >>> 0;
|
|
view.setUint32(offset, lo, true);
|
|
view.setUint16(offset + 4, hi, true);
|
|
return offset + 6;
|
|
}
|
|
function writeUint40BE(value, view, offset) {
|
|
const hi = Math.floor(value / 4294967296);
|
|
const lo = value >>> 0;
|
|
view.setUint8(offset, hi);
|
|
view.setUint32(offset + 1, lo, false);
|
|
return offset + 5;
|
|
}
|
|
function writeUint40LE(value, view, offset) {
|
|
const hi = Math.floor(value / 4294967296);
|
|
const lo = value >>> 0;
|
|
view.setUint32(offset, lo, true);
|
|
view.setUint8(offset + 4, hi);
|
|
return offset + 5;
|
|
}
|
|
function writeUint24BE(value, view, offset) {
|
|
view.setUint8(offset, value >> 16 & 255);
|
|
view.setUint8(offset + 1, value >> 8 & 255);
|
|
view.setUint8(offset + 2, value & 255);
|
|
return offset + 3;
|
|
}
|
|
function writeUint24LE(value, view, offset) {
|
|
view.setUint8(offset, value & 255);
|
|
view.setUint8(offset + 1, value >> 8 & 255);
|
|
view.setUint8(offset + 2, value >> 16 & 255);
|
|
return offset + 3;
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/compact-encoding/endian.js
|
|
var require_endian = __commonJS({
|
|
"../../node_modules/compact-encoding/endian.js"(exports) {
|
|
var LE = exports.LE = new Uint8Array(new Uint16Array([255]).buffer)[0] === 255;
|
|
exports.BE = !LE;
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/compact-encoding/raw.js
|
|
var require_raw = __commonJS({
|
|
"../../node_modules/compact-encoding/raw.js"(exports, module) {
|
|
var b4a = require_b4a();
|
|
var { BE } = require_endian();
|
|
exports = module.exports = {
|
|
preencode(state, b) {
|
|
state.end += b.byteLength;
|
|
},
|
|
encode(state, b) {
|
|
state.buffer.set(b, state.start);
|
|
state.start += b.byteLength;
|
|
},
|
|
decode(state) {
|
|
const b = state.buffer.subarray(state.start, state.end);
|
|
state.start = state.end;
|
|
return b;
|
|
}
|
|
};
|
|
var buffer = exports.buffer = {
|
|
preencode(state, b) {
|
|
if (b) uint8array.preencode(state, b);
|
|
else state.end++;
|
|
},
|
|
encode(state, b) {
|
|
if (b) uint8array.encode(state, b);
|
|
else state.buffer[state.start++] = 0;
|
|
},
|
|
decode(state) {
|
|
const b = state.buffer.subarray(state.start);
|
|
if (b.byteLength === 0) return null;
|
|
state.start = state.end;
|
|
return b;
|
|
}
|
|
};
|
|
exports.binary = {
|
|
...buffer,
|
|
preencode(state, b) {
|
|
if (typeof b === "string") utf8.preencode(state, b);
|
|
else buffer.preencode(state, b);
|
|
},
|
|
encode(state, b) {
|
|
if (typeof b === "string") utf8.encode(state, b);
|
|
else buffer.encode(state, b);
|
|
}
|
|
};
|
|
exports.arraybuffer = {
|
|
preencode(state, b) {
|
|
state.end += b.byteLength;
|
|
},
|
|
encode(state, b) {
|
|
const view = new Uint8Array(b);
|
|
state.buffer.set(view, state.start);
|
|
state.start += b.byteLength;
|
|
},
|
|
decode(state) {
|
|
const b = new ArrayBuffer(state.end - state.start);
|
|
const view = new Uint8Array(b);
|
|
view.set(state.buffer.subarray(state.start));
|
|
state.start = state.end;
|
|
return b;
|
|
}
|
|
};
|
|
function typedarray(TypedArray, swap) {
|
|
const n = TypedArray.BYTES_PER_ELEMENT;
|
|
return {
|
|
preencode(state, b) {
|
|
state.end += b.byteLength;
|
|
},
|
|
encode(state, b) {
|
|
const view = new Uint8Array(b.buffer, b.byteOffset, b.byteLength);
|
|
if (BE && swap) swap(view);
|
|
state.buffer.set(view, state.start);
|
|
state.start += b.byteLength;
|
|
},
|
|
decode(state) {
|
|
let b = state.buffer.subarray(state.start);
|
|
if (b.byteOffset % n !== 0) b = new Uint8Array(b);
|
|
if (BE && swap) swap(b);
|
|
state.start = state.end;
|
|
return new TypedArray(b.buffer, b.byteOffset, b.byteLength / n);
|
|
}
|
|
};
|
|
}
|
|
var uint8array = exports.uint8array = typedarray(Uint8Array);
|
|
exports.uint16array = typedarray(Uint16Array, b4a.swap16);
|
|
exports.uint32array = typedarray(Uint32Array, b4a.swap32);
|
|
exports.int8array = typedarray(Int8Array);
|
|
exports.int16array = typedarray(Int16Array, b4a.swap16);
|
|
exports.int32array = typedarray(Int32Array, b4a.swap32);
|
|
exports.biguint64array = typedarray(BigUint64Array, b4a.swap64);
|
|
exports.bigint64array = typedarray(BigInt64Array, b4a.swap64);
|
|
exports.float32array = typedarray(Float32Array, b4a.swap32);
|
|
exports.float64array = typedarray(Float64Array, b4a.swap64);
|
|
function string(encoding) {
|
|
return {
|
|
preencode(state, s) {
|
|
state.end += b4a.byteLength(s, encoding);
|
|
},
|
|
encode(state, s) {
|
|
state.start += b4a.write(state.buffer, s, state.start, encoding);
|
|
},
|
|
decode(state) {
|
|
const s = b4a.toString(state.buffer, encoding, state.start);
|
|
state.start = state.end;
|
|
return s;
|
|
}
|
|
};
|
|
}
|
|
var utf8 = exports.string = exports.utf8 = string("utf-8");
|
|
exports.ascii = string("ascii");
|
|
exports.hex = string("hex");
|
|
exports.base64 = string("base64");
|
|
exports.ucs2 = exports.utf16le = string("utf16le");
|
|
exports.array = function array(enc) {
|
|
return {
|
|
preencode(state, list) {
|
|
for (const value of list) enc.preencode(state, value);
|
|
},
|
|
encode(state, list) {
|
|
for (const value of list) enc.encode(state, value);
|
|
},
|
|
decode(state) {
|
|
const arr = [];
|
|
while (state.start < state.end) arr.push(enc.decode(state));
|
|
return arr;
|
|
}
|
|
};
|
|
};
|
|
exports.json = {
|
|
preencode(state, v) {
|
|
utf8.preencode(state, JSON.stringify(v));
|
|
},
|
|
encode(state, v) {
|
|
utf8.encode(state, JSON.stringify(v));
|
|
},
|
|
decode(state) {
|
|
return JSON.parse(utf8.decode(state));
|
|
}
|
|
};
|
|
exports.ndjson = {
|
|
preencode(state, v) {
|
|
utf8.preencode(state, JSON.stringify(v) + "\n");
|
|
},
|
|
encode(state, v) {
|
|
utf8.encode(state, JSON.stringify(v) + "\n");
|
|
},
|
|
decode(state) {
|
|
return JSON.parse(utf8.decode(state));
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/compact-encoding/lexint.js
|
|
var require_lexint = __commonJS({
|
|
"../../node_modules/compact-encoding/lexint.js"(exports, module) {
|
|
module.exports = {
|
|
preencode,
|
|
encode,
|
|
decode
|
|
};
|
|
function preencode(state, num) {
|
|
if (num < 251) {
|
|
state.end++;
|
|
} else if (num < 256) {
|
|
state.end += 2;
|
|
} else if (num < 65536) {
|
|
state.end += 3;
|
|
} else if (num < 16777216) {
|
|
state.end += 4;
|
|
} else if (num < 4294967296) {
|
|
state.end += 5;
|
|
} else {
|
|
state.end++;
|
|
const exp = Math.floor(Math.log(num) / Math.log(2)) - 32;
|
|
preencode(state, exp);
|
|
state.end += 6;
|
|
}
|
|
}
|
|
function encode(state, num) {
|
|
const max = 251;
|
|
const x = num - max;
|
|
if (num < max) {
|
|
state.buffer[state.start++] = num;
|
|
} else if (num < 256) {
|
|
state.buffer[state.start++] = max;
|
|
state.buffer[state.start++] = x;
|
|
} else if (num < 65536) {
|
|
state.buffer[state.start++] = max + 1;
|
|
state.buffer[state.start++] = x >> 8 & 255;
|
|
state.buffer[state.start++] = x & 255;
|
|
} else if (num < 16777216) {
|
|
state.buffer[state.start++] = max + 2;
|
|
state.buffer[state.start++] = x >> 16;
|
|
state.buffer[state.start++] = x >> 8 & 255;
|
|
state.buffer[state.start++] = x & 255;
|
|
} else if (num < 4294967296) {
|
|
state.buffer[state.start++] = max + 3;
|
|
state.buffer[state.start++] = x >> 24;
|
|
state.buffer[state.start++] = x >> 16 & 255;
|
|
state.buffer[state.start++] = x >> 8 & 255;
|
|
state.buffer[state.start++] = x & 255;
|
|
} else {
|
|
const exp = Math.floor(Math.log(x) / Math.log(2)) - 32;
|
|
state.buffer[state.start++] = 255;
|
|
encode(state, exp);
|
|
const rem = x / Math.pow(2, exp - 11);
|
|
for (let i = 5; i >= 0; i--) {
|
|
state.buffer[state.start++] = rem / Math.pow(2, 8 * i) & 255;
|
|
}
|
|
}
|
|
}
|
|
function decode(state) {
|
|
const max = 251;
|
|
if (state.end - state.start < 1) throw new Error("Out of bounds");
|
|
const flag = state.buffer[state.start++];
|
|
if (flag < max) return flag;
|
|
if (state.end - state.start < flag - max + 1) {
|
|
throw new Error("Out of bounds.");
|
|
}
|
|
if (flag < 252) {
|
|
return state.buffer[state.start++] + max;
|
|
}
|
|
if (flag < 253) {
|
|
return (state.buffer[state.start++] << 8) + state.buffer[state.start++] + max;
|
|
}
|
|
if (flag < 254) {
|
|
return (state.buffer[state.start++] << 16) + (state.buffer[state.start++] << 8) + state.buffer[state.start++] + max;
|
|
}
|
|
if (flag < 255) {
|
|
return state.buffer[state.start++] * 16777216 + (state.buffer[state.start++] << 16) + (state.buffer[state.start++] << 8) + state.buffer[state.start++] + max;
|
|
}
|
|
const exp = decode(state);
|
|
if (state.end - state.start < 6) throw new Error("Out of bounds");
|
|
let rem = 0;
|
|
for (let i = 5; i >= 0; i--) {
|
|
rem += state.buffer[state.start++] * Math.pow(2, 8 * i);
|
|
}
|
|
return rem * Math.pow(2, exp - 11) + max;
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/compact-encoding/index.js
|
|
var require_compact_encoding = __commonJS({
|
|
"../../node_modules/compact-encoding/index.js"(exports) {
|
|
var b4a = require_b4a();
|
|
var { BE } = require_endian();
|
|
exports.state = function(start = 0, end = 0, buffer2 = null) {
|
|
return { start, end, buffer: buffer2 };
|
|
};
|
|
var raw = exports.raw = require_raw();
|
|
var uint = exports.uint = {
|
|
preencode(state, n) {
|
|
state.end += n <= 252 ? 1 : n <= 65535 ? 3 : n <= 4294967295 ? 5 : 9;
|
|
},
|
|
encode(state, n) {
|
|
if (n <= 252) uint8.encode(state, n);
|
|
else if (n <= 65535) {
|
|
state.buffer[state.start++] = 253;
|
|
uint16.encode(state, n);
|
|
} else if (n <= 4294967295) {
|
|
state.buffer[state.start++] = 254;
|
|
uint32.encode(state, n);
|
|
} else {
|
|
state.buffer[state.start++] = 255;
|
|
uint64.encode(state, n);
|
|
}
|
|
},
|
|
decode(state) {
|
|
const a = uint8.decode(state);
|
|
if (a <= 252) return a;
|
|
if (a === 253) return uint16.decode(state);
|
|
if (a === 254) return uint32.decode(state);
|
|
return uint64.decode(state);
|
|
}
|
|
};
|
|
var uint8 = exports.uint8 = {
|
|
preencode(state, n) {
|
|
state.end += 1;
|
|
},
|
|
encode(state, n) {
|
|
validateUint(n);
|
|
state.buffer[state.start++] = n;
|
|
},
|
|
decode(state) {
|
|
if (state.start >= state.end) throw new Error("Out of bounds");
|
|
return state.buffer[state.start++];
|
|
}
|
|
};
|
|
var uint16 = exports.uint16 = {
|
|
preencode(state, n) {
|
|
state.end += 2;
|
|
},
|
|
encode(state, n) {
|
|
validateUint(n);
|
|
state.buffer[state.start++] = n;
|
|
state.buffer[state.start++] = n >>> 8;
|
|
},
|
|
decode(state) {
|
|
if (state.end - state.start < 2) throw new Error("Out of bounds");
|
|
return state.buffer[state.start++] + state.buffer[state.start++] * 256;
|
|
}
|
|
};
|
|
var uint24 = exports.uint24 = {
|
|
preencode(state, n) {
|
|
state.end += 3;
|
|
},
|
|
encode(state, n) {
|
|
validateUint(n);
|
|
state.buffer[state.start++] = n;
|
|
state.buffer[state.start++] = n >>> 8;
|
|
state.buffer[state.start++] = n >>> 16;
|
|
},
|
|
decode(state) {
|
|
if (state.end - state.start < 3) throw new Error("Out of bounds");
|
|
return state.buffer[state.start++] + state.buffer[state.start++] * 256 + state.buffer[state.start++] * 65536;
|
|
}
|
|
};
|
|
var uint32 = exports.uint32 = {
|
|
preencode(state, n) {
|
|
state.end += 4;
|
|
},
|
|
encode(state, n) {
|
|
validateUint(n);
|
|
state.buffer[state.start++] = n;
|
|
state.buffer[state.start++] = n >>> 8;
|
|
state.buffer[state.start++] = n >>> 16;
|
|
state.buffer[state.start++] = n >>> 24;
|
|
},
|
|
decode(state) {
|
|
if (state.end - state.start < 4) throw new Error("Out of bounds");
|
|
return state.buffer[state.start++] + state.buffer[state.start++] * 256 + state.buffer[state.start++] * 65536 + state.buffer[state.start++] * 16777216;
|
|
}
|
|
};
|
|
var uint40 = exports.uint40 = {
|
|
preencode(state, n) {
|
|
state.end += 5;
|
|
},
|
|
encode(state, n) {
|
|
validateUint(n);
|
|
const r = Math.floor(n / 256);
|
|
uint8.encode(state, n);
|
|
uint32.encode(state, r);
|
|
},
|
|
decode(state) {
|
|
if (state.end - state.start < 5) throw new Error("Out of bounds");
|
|
return uint8.decode(state) + 256 * uint32.decode(state);
|
|
}
|
|
};
|
|
var uint48 = exports.uint48 = {
|
|
preencode(state, n) {
|
|
state.end += 6;
|
|
},
|
|
encode(state, n) {
|
|
validateUint(n);
|
|
const r = Math.floor(n / 65536);
|
|
uint16.encode(state, n);
|
|
uint32.encode(state, r);
|
|
},
|
|
decode(state) {
|
|
if (state.end - state.start < 6) throw new Error("Out of bounds");
|
|
return uint16.decode(state) + 65536 * uint32.decode(state);
|
|
}
|
|
};
|
|
var uint56 = exports.uint56 = {
|
|
preencode(state, n) {
|
|
state.end += 7;
|
|
},
|
|
encode(state, n) {
|
|
validateUint(n);
|
|
const r = Math.floor(n / 16777216);
|
|
uint24.encode(state, n);
|
|
uint32.encode(state, r);
|
|
},
|
|
decode(state) {
|
|
if (state.end - state.start < 7) throw new Error("Out of bounds");
|
|
return uint24.decode(state) + 16777216 * uint32.decode(state);
|
|
}
|
|
};
|
|
var uint64 = exports.uint64 = {
|
|
preencode(state, n) {
|
|
state.end += 8;
|
|
},
|
|
encode(state, n) {
|
|
validateUint(n);
|
|
const r = Math.floor(n / 4294967296);
|
|
uint32.encode(state, n);
|
|
uint32.encode(state, r);
|
|
},
|
|
decode(state) {
|
|
if (state.end - state.start < 8) throw new Error("Out of bounds");
|
|
return uint32.decode(state) + 4294967296 * uint32.decode(state);
|
|
}
|
|
};
|
|
var int = exports.int = zigZagInt(uint);
|
|
exports.int8 = zigZagInt(uint8);
|
|
exports.int16 = zigZagInt(uint16);
|
|
exports.int24 = zigZagInt(uint24);
|
|
exports.int32 = zigZagInt(uint32);
|
|
exports.int40 = zigZagInt(uint40);
|
|
exports.int48 = zigZagInt(uint48);
|
|
exports.int56 = zigZagInt(uint56);
|
|
exports.int64 = zigZagInt(uint64);
|
|
var biguint64 = exports.biguint64 = {
|
|
preencode(state, n) {
|
|
state.end += 8;
|
|
},
|
|
encode(state, n) {
|
|
const view = new DataView(
|
|
state.buffer.buffer,
|
|
state.start + state.buffer.byteOffset,
|
|
8
|
|
);
|
|
view.setBigUint64(0, n, true);
|
|
state.start += 8;
|
|
},
|
|
decode(state) {
|
|
if (state.end - state.start < 8) throw new Error("Out of bounds");
|
|
const view = new DataView(
|
|
state.buffer.buffer,
|
|
state.start + state.buffer.byteOffset,
|
|
8
|
|
);
|
|
const n = view.getBigUint64(0, true);
|
|
state.start += 8;
|
|
return n;
|
|
}
|
|
};
|
|
exports.bigint64 = zigZagBigInt(biguint64);
|
|
var biguint = exports.biguint = {
|
|
preencode(state, n) {
|
|
let len = 0;
|
|
for (let m = n; m; m = m >> 64n) len++;
|
|
uint.preencode(state, len);
|
|
state.end += 8 * len;
|
|
},
|
|
encode(state, n) {
|
|
let len = 0;
|
|
for (let m = n; m; m = m >> 64n) len++;
|
|
uint.encode(state, len);
|
|
const view = new DataView(
|
|
state.buffer.buffer,
|
|
state.start + state.buffer.byteOffset,
|
|
8 * len
|
|
);
|
|
for (let m = n, i = 0; m; m = m >> 64n, i += 8) {
|
|
view.setBigUint64(i, BigInt.asUintN(64, m), true);
|
|
}
|
|
state.start += 8 * len;
|
|
},
|
|
decode(state) {
|
|
const len = uint.decode(state);
|
|
if (state.end - state.start < 8 * len) throw new Error("Out of bounds");
|
|
const view = new DataView(
|
|
state.buffer.buffer,
|
|
state.start + state.buffer.byteOffset,
|
|
8 * len
|
|
);
|
|
let n = 0n;
|
|
for (let i = len - 1; i >= 0; i--)
|
|
n = (n << 64n) + view.getBigUint64(i * 8, true);
|
|
state.start += 8 * len;
|
|
return n;
|
|
}
|
|
};
|
|
exports.bigint = zigZagBigInt(biguint);
|
|
exports.lexint = require_lexint();
|
|
exports.float32 = {
|
|
preencode(state, n) {
|
|
state.end += 4;
|
|
},
|
|
encode(state, n) {
|
|
const view = new DataView(
|
|
state.buffer.buffer,
|
|
state.start + state.buffer.byteOffset,
|
|
4
|
|
);
|
|
view.setFloat32(0, n, true);
|
|
state.start += 4;
|
|
},
|
|
decode(state) {
|
|
if (state.end - state.start < 4) throw new Error("Out of bounds");
|
|
const view = new DataView(
|
|
state.buffer.buffer,
|
|
state.start + state.buffer.byteOffset,
|
|
4
|
|
);
|
|
const float = view.getFloat32(0, true);
|
|
state.start += 4;
|
|
return float;
|
|
}
|
|
};
|
|
exports.float64 = {
|
|
preencode(state, n) {
|
|
state.end += 8;
|
|
},
|
|
encode(state, n) {
|
|
const view = new DataView(
|
|
state.buffer.buffer,
|
|
state.start + state.buffer.byteOffset,
|
|
8
|
|
);
|
|
view.setFloat64(0, n, true);
|
|
state.start += 8;
|
|
},
|
|
decode(state) {
|
|
if (state.end - state.start < 8) throw new Error("Out of bounds");
|
|
const view = new DataView(
|
|
state.buffer.buffer,
|
|
state.start + state.buffer.byteOffset,
|
|
8
|
|
);
|
|
const float = view.getFloat64(0, true);
|
|
state.start += 8;
|
|
return float;
|
|
}
|
|
};
|
|
var buffer = exports.buffer = {
|
|
preencode(state, b) {
|
|
if (b) uint8array.preencode(state, b);
|
|
else state.end++;
|
|
},
|
|
encode(state, b) {
|
|
if (b) uint8array.encode(state, b);
|
|
else state.buffer[state.start++] = 0;
|
|
},
|
|
decode(state) {
|
|
const len = uint.decode(state);
|
|
if (len === 0) return null;
|
|
if (state.end - state.start < len) throw new Error("Out of bounds");
|
|
return state.buffer.subarray(state.start, state.start += len);
|
|
}
|
|
};
|
|
exports.binary = {
|
|
...buffer,
|
|
preencode(state, b) {
|
|
if (typeof b === "string") utf8.preencode(state, b);
|
|
else buffer.preencode(state, b);
|
|
},
|
|
encode(state, b) {
|
|
if (typeof b === "string") utf8.encode(state, b);
|
|
else buffer.encode(state, b);
|
|
}
|
|
};
|
|
exports.arraybuffer = {
|
|
preencode(state, b) {
|
|
uint.preencode(state, b.byteLength);
|
|
state.end += b.byteLength;
|
|
},
|
|
encode(state, b) {
|
|
uint.encode(state, b.byteLength);
|
|
const view = new Uint8Array(b);
|
|
state.buffer.set(view, state.start);
|
|
state.start += b.byteLength;
|
|
},
|
|
decode(state) {
|
|
const len = uint.decode(state);
|
|
const b = new ArrayBuffer(len);
|
|
const view = new Uint8Array(b);
|
|
view.set(state.buffer.subarray(state.start, state.start += len));
|
|
return b;
|
|
}
|
|
};
|
|
function typedarray(TypedArray, swap) {
|
|
const n = TypedArray.BYTES_PER_ELEMENT;
|
|
return {
|
|
preencode(state, b) {
|
|
uint.preencode(state, b.length);
|
|
state.end += b.byteLength;
|
|
},
|
|
encode(state, b) {
|
|
uint.encode(state, b.length);
|
|
const view = new Uint8Array(b.buffer, b.byteOffset, b.byteLength);
|
|
if (BE && swap) swap(view);
|
|
state.buffer.set(view, state.start);
|
|
state.start += b.byteLength;
|
|
},
|
|
decode(state) {
|
|
const len = uint.decode(state);
|
|
let b = state.buffer.subarray(state.start, state.start += len * n);
|
|
if (b.byteLength !== len * n) throw new Error("Out of bounds");
|
|
if (b.byteOffset % n !== 0) b = new Uint8Array(b);
|
|
if (BE && swap) swap(b);
|
|
return new TypedArray(b.buffer, b.byteOffset, b.byteLength / n);
|
|
}
|
|
};
|
|
}
|
|
var uint8array = exports.uint8array = typedarray(Uint8Array);
|
|
exports.uint16array = typedarray(Uint16Array, b4a.swap16);
|
|
exports.uint32array = typedarray(Uint32Array, b4a.swap32);
|
|
exports.int8array = typedarray(Int8Array);
|
|
exports.int16array = typedarray(Int16Array, b4a.swap16);
|
|
exports.int32array = typedarray(Int32Array, b4a.swap32);
|
|
exports.biguint64array = typedarray(BigUint64Array, b4a.swap64);
|
|
exports.bigint64array = typedarray(BigInt64Array, b4a.swap64);
|
|
exports.float32array = typedarray(Float32Array, b4a.swap32);
|
|
exports.float64array = typedarray(Float64Array, b4a.swap64);
|
|
function string(encoding) {
|
|
return {
|
|
preencode(state, s) {
|
|
const len = b4a.byteLength(s, encoding);
|
|
uint.preencode(state, len);
|
|
state.end += len;
|
|
},
|
|
encode(state, s) {
|
|
const len = b4a.byteLength(s, encoding);
|
|
uint.encode(state, len);
|
|
b4a.write(state.buffer, s, state.start, encoding);
|
|
state.start += len;
|
|
},
|
|
decode(state) {
|
|
const len = uint.decode(state);
|
|
if (state.end - state.start < len) throw new Error("Out of bounds");
|
|
return b4a.toString(
|
|
state.buffer,
|
|
encoding,
|
|
state.start,
|
|
state.start += len
|
|
);
|
|
},
|
|
fixed(n) {
|
|
return {
|
|
preencode(state) {
|
|
state.end += n;
|
|
},
|
|
encode(state, s) {
|
|
b4a.write(state.buffer, s, state.start, n, encoding);
|
|
state.start += n;
|
|
},
|
|
decode(state) {
|
|
if (state.end - state.start < n) throw new Error("Out of bounds");
|
|
return b4a.toString(
|
|
state.buffer,
|
|
encoding,
|
|
state.start,
|
|
state.start += n
|
|
);
|
|
}
|
|
};
|
|
}
|
|
};
|
|
}
|
|
var utf8 = exports.string = exports.utf8 = string("utf-8");
|
|
exports.ascii = string("ascii");
|
|
exports.hex = string("hex");
|
|
exports.base64 = string("base64");
|
|
exports.ucs2 = exports.utf16le = string("utf16le");
|
|
exports.bool = {
|
|
preencode(state, b) {
|
|
state.end++;
|
|
},
|
|
encode(state, b) {
|
|
state.buffer[state.start++] = b ? 1 : 0;
|
|
},
|
|
decode(state) {
|
|
if (state.start >= state.end) throw Error("Out of bounds");
|
|
return state.buffer[state.start++] === 1;
|
|
}
|
|
};
|
|
var fixed = exports.fixed = function fixed2(n) {
|
|
return {
|
|
preencode(state, s) {
|
|
if (s.byteLength !== n) throw new Error("Incorrect buffer size");
|
|
state.end += n;
|
|
},
|
|
encode(state, s) {
|
|
state.buffer.set(s, state.start);
|
|
state.start += n;
|
|
},
|
|
decode(state) {
|
|
if (state.end - state.start < n) throw new Error("Out of bounds");
|
|
return state.buffer.subarray(state.start, state.start += n);
|
|
}
|
|
};
|
|
};
|
|
exports.fixed32 = fixed(32);
|
|
exports.fixed64 = fixed(64);
|
|
exports.array = function array(enc) {
|
|
return {
|
|
preencode(state, list) {
|
|
uint.preencode(state, list.length);
|
|
for (let i = 0; i < list.length; i++) enc.preencode(state, list[i]);
|
|
},
|
|
encode(state, list) {
|
|
uint.encode(state, list.length);
|
|
for (let i = 0; i < list.length; i++) enc.encode(state, list[i]);
|
|
},
|
|
decode(state) {
|
|
const len = uint.decode(state);
|
|
if (len > 1048576) throw new Error("Array is too big");
|
|
const arr = new Array(len);
|
|
for (let i = 0; i < len; i++) arr[i] = enc.decode(state);
|
|
return arr;
|
|
}
|
|
};
|
|
};
|
|
exports.frame = function frame(enc) {
|
|
const dummy = exports.state();
|
|
return {
|
|
preencode(state, m) {
|
|
const end = state.end;
|
|
enc.preencode(state, m);
|
|
uint.preencode(state, state.end - end);
|
|
},
|
|
encode(state, m) {
|
|
dummy.end = 0;
|
|
enc.preencode(dummy, m);
|
|
uint.encode(state, dummy.end);
|
|
enc.encode(state, m);
|
|
},
|
|
decode(state) {
|
|
const end = state.end;
|
|
const len = uint.decode(state);
|
|
state.end = state.start + len;
|
|
const m = enc.decode(state);
|
|
state.start = state.end;
|
|
state.end = end;
|
|
return m;
|
|
}
|
|
};
|
|
};
|
|
exports.date = {
|
|
preencode(state, d) {
|
|
int.preencode(state, d.getTime());
|
|
},
|
|
encode(state, d) {
|
|
int.encode(state, d.getTime());
|
|
},
|
|
decode(state, d) {
|
|
return new Date(int.decode(state));
|
|
}
|
|
};
|
|
exports.json = {
|
|
preencode(state, v) {
|
|
utf8.preencode(state, JSON.stringify(v));
|
|
},
|
|
encode(state, v) {
|
|
utf8.encode(state, JSON.stringify(v));
|
|
},
|
|
decode(state) {
|
|
return JSON.parse(utf8.decode(state));
|
|
}
|
|
};
|
|
exports.ndjson = {
|
|
preencode(state, v) {
|
|
utf8.preencode(state, JSON.stringify(v) + "\n");
|
|
},
|
|
encode(state, v) {
|
|
utf8.encode(state, JSON.stringify(v) + "\n");
|
|
},
|
|
decode(state) {
|
|
return JSON.parse(utf8.decode(state));
|
|
}
|
|
};
|
|
exports.none = {
|
|
preencode(state, n) {
|
|
},
|
|
encode(state, n) {
|
|
},
|
|
decode(state) {
|
|
return null;
|
|
}
|
|
};
|
|
var anyArray = {
|
|
preencode(state, arr) {
|
|
uint.preencode(state, arr.length);
|
|
for (let i = 0; i < arr.length; i++) {
|
|
any.preencode(state, arr[i]);
|
|
}
|
|
},
|
|
encode(state, arr) {
|
|
uint.encode(state, arr.length);
|
|
for (let i = 0; i < arr.length; i++) {
|
|
any.encode(state, arr[i]);
|
|
}
|
|
},
|
|
decode(state) {
|
|
const arr = [];
|
|
let len = uint.decode(state);
|
|
while (len-- > 0) {
|
|
arr.push(any.decode(state));
|
|
}
|
|
return arr;
|
|
}
|
|
};
|
|
var anyObject = {
|
|
preencode(state, o) {
|
|
const keys = Object.keys(o);
|
|
uint.preencode(state, keys.length);
|
|
for (const key of keys) {
|
|
utf8.preencode(state, key);
|
|
any.preencode(state, o[key]);
|
|
}
|
|
},
|
|
encode(state, o) {
|
|
const keys = Object.keys(o);
|
|
uint.encode(state, keys.length);
|
|
for (const key of keys) {
|
|
utf8.encode(state, key);
|
|
any.encode(state, o[key]);
|
|
}
|
|
},
|
|
decode(state) {
|
|
let len = uint.decode(state);
|
|
const o = {};
|
|
while (len-- > 0) {
|
|
const key = utf8.decode(state);
|
|
o[key] = any.decode(state);
|
|
}
|
|
return o;
|
|
}
|
|
};
|
|
var anyTypes = [
|
|
exports.none,
|
|
exports.bool,
|
|
exports.string,
|
|
exports.buffer,
|
|
exports.uint,
|
|
exports.int,
|
|
exports.float64,
|
|
anyArray,
|
|
anyObject,
|
|
exports.date
|
|
];
|
|
var any = exports.any = {
|
|
preencode(state, o) {
|
|
const t = getType(o);
|
|
uint.preencode(state, t);
|
|
anyTypes[t].preencode(state, o);
|
|
},
|
|
encode(state, o) {
|
|
const t = getType(o);
|
|
uint.encode(state, t);
|
|
anyTypes[t].encode(state, o);
|
|
},
|
|
decode(state) {
|
|
const t = uint.decode(state);
|
|
if (t >= anyTypes.length) throw new Error("Unknown type: " + t);
|
|
return anyTypes[t].decode(state);
|
|
}
|
|
};
|
|
var port = exports.port = uint16;
|
|
var address = (host, family) => {
|
|
return {
|
|
preencode(state, m) {
|
|
host.preencode(state, m.host);
|
|
port.preencode(state, m.port);
|
|
},
|
|
encode(state, m) {
|
|
host.encode(state, m.host);
|
|
port.encode(state, m.port);
|
|
},
|
|
decode(state) {
|
|
return {
|
|
host: host.decode(state),
|
|
family,
|
|
port: port.decode(state)
|
|
};
|
|
}
|
|
};
|
|
};
|
|
var ipv4 = exports.ipv4 = {
|
|
preencode(state) {
|
|
state.end += 4;
|
|
},
|
|
encode(state, string2) {
|
|
const start = state.start;
|
|
const end = start + 4;
|
|
let i = 0;
|
|
while (i < string2.length) {
|
|
let n = 0;
|
|
let c;
|
|
while (i < string2.length && (c = string2.charCodeAt(i++)) !== /* . */
|
|
46) {
|
|
n = n * 10 + (c - /* 0 */
|
|
48);
|
|
}
|
|
state.buffer[state.start++] = n;
|
|
}
|
|
state.start = end;
|
|
},
|
|
decode(state) {
|
|
if (state.end - state.start < 4) throw new Error("Out of bounds");
|
|
return state.buffer[state.start++] + "." + state.buffer[state.start++] + "." + state.buffer[state.start++] + "." + state.buffer[state.start++];
|
|
}
|
|
};
|
|
exports.ipv4Address = address(ipv4, 4);
|
|
var ipv6 = exports.ipv6 = {
|
|
preencode(state) {
|
|
state.end += 16;
|
|
},
|
|
encode(state, string2) {
|
|
const start = state.start;
|
|
const end = start + 16;
|
|
let i = 0;
|
|
let split = null;
|
|
while (i < string2.length) {
|
|
let n = 0;
|
|
let c;
|
|
while (i < string2.length && (c = string2.charCodeAt(i++)) !== /* : */
|
|
58) {
|
|
if (c >= 48 && c <= 57) n = n * 16 + (c - /* 0 */
|
|
48);
|
|
else if (c >= 65 && c <= 70) n = n * 16 + (c - /* A */
|
|
65 + 10);
|
|
else if (c >= 97 && c <= 102) n = n * 16 + (c - /* a */
|
|
97 + 10);
|
|
}
|
|
state.buffer[state.start++] = n >>> 8;
|
|
state.buffer[state.start++] = n;
|
|
if (i < string2.length && string2.charCodeAt(i) === /* : */
|
|
58) {
|
|
i++;
|
|
split = state.start;
|
|
}
|
|
}
|
|
if (split !== null) {
|
|
const offset = end - state.start;
|
|
state.buffer.copyWithin(split + offset, split).fill(0, split, split + offset);
|
|
}
|
|
state.start = end;
|
|
},
|
|
decode(state) {
|
|
if (state.end - state.start < 16) throw new Error("Out of bounds");
|
|
return (state.buffer[state.start++] * 256 + state.buffer[state.start++]).toString(16) + ":" + (state.buffer[state.start++] * 256 + state.buffer[state.start++]).toString(16) + ":" + (state.buffer[state.start++] * 256 + state.buffer[state.start++]).toString(16) + ":" + (state.buffer[state.start++] * 256 + state.buffer[state.start++]).toString(16) + ":" + (state.buffer[state.start++] * 256 + state.buffer[state.start++]).toString(16) + ":" + (state.buffer[state.start++] * 256 + state.buffer[state.start++]).toString(16) + ":" + (state.buffer[state.start++] * 256 + state.buffer[state.start++]).toString(16) + ":" + (state.buffer[state.start++] * 256 + state.buffer[state.start++]).toString(16);
|
|
}
|
|
};
|
|
exports.ipv6Address = address(ipv6, 6);
|
|
var ip = exports.ip = {
|
|
preencode(state, string2) {
|
|
const family = string2.includes(":") ? 6 : 4;
|
|
uint8.preencode(state, family);
|
|
if (family === 4) ipv4.preencode(state);
|
|
else ipv6.preencode(state);
|
|
},
|
|
encode(state, string2) {
|
|
const family = string2.includes(":") ? 6 : 4;
|
|
uint8.encode(state, family);
|
|
if (family === 4) ipv4.encode(state, string2);
|
|
else ipv6.encode(state, string2);
|
|
},
|
|
decode(state) {
|
|
const family = uint8.decode(state);
|
|
if (family === 4) return ipv4.decode(state);
|
|
else return ipv6.decode(state);
|
|
}
|
|
};
|
|
exports.ipAddress = {
|
|
preencode(state, m) {
|
|
ip.preencode(state, m.host);
|
|
port.preencode(state, m.port);
|
|
},
|
|
encode(state, m) {
|
|
ip.encode(state, m.host);
|
|
port.encode(state, m.port);
|
|
},
|
|
decode(state) {
|
|
const family = uint8.decode(state);
|
|
return {
|
|
host: family === 4 ? ipv4.decode(state) : ipv6.decode(state),
|
|
family,
|
|
port: port.decode(state)
|
|
};
|
|
}
|
|
};
|
|
var record = exports.record = function(keyEncoding, valueEncoding) {
|
|
return {
|
|
preencode(state, v) {
|
|
const keys = Object.keys(v);
|
|
uint.preencode(state, keys.length);
|
|
for (const k of keys) {
|
|
keyEncoding.preencode(state, k);
|
|
valueEncoding.preencode(state, v[k]);
|
|
}
|
|
},
|
|
encode(state, v) {
|
|
const keys = Object.keys(v);
|
|
uint.encode(state, keys.length);
|
|
for (const k of keys) {
|
|
keyEncoding.encode(state, k);
|
|
valueEncoding.encode(state, v[k]);
|
|
}
|
|
},
|
|
decode(state) {
|
|
const out = /* @__PURE__ */ Object.create(null);
|
|
const keys = uint.decode(state);
|
|
for (let i = 0; i < keys; i++) {
|
|
out[keyEncoding.decode(state)] = valueEncoding.decode(state);
|
|
}
|
|
return out;
|
|
}
|
|
};
|
|
};
|
|
exports.stringRecord = record(utf8, utf8);
|
|
function getType(o) {
|
|
if (o === null || o === void 0) return 0;
|
|
if (typeof o === "boolean") return 1;
|
|
if (typeof o === "string") return 2;
|
|
if (b4a.isBuffer(o)) return 3;
|
|
if (typeof o === "number") {
|
|
if (Number.isInteger(o)) return o >= 0 ? 4 : 5;
|
|
return 6;
|
|
}
|
|
if (Array.isArray(o)) return 7;
|
|
if (o instanceof Date) return 9;
|
|
if (typeof o === "object") return 8;
|
|
throw new Error("Unsupported type for " + o);
|
|
}
|
|
exports.from = function from(enc) {
|
|
if (typeof enc === "string") return fromNamed(enc);
|
|
if (enc.preencode) return enc;
|
|
if (enc.encodingLength) return fromAbstractEncoder(enc);
|
|
return fromCodec(enc);
|
|
};
|
|
function fromNamed(enc) {
|
|
switch (enc) {
|
|
case "ascii":
|
|
return raw.ascii;
|
|
case "utf-8":
|
|
case "utf8":
|
|
return raw.utf8;
|
|
case "hex":
|
|
return raw.hex;
|
|
case "base64":
|
|
return raw.base64;
|
|
case "utf16-le":
|
|
case "utf16le":
|
|
case "ucs-2":
|
|
case "ucs2":
|
|
return raw.ucs2;
|
|
case "ndjson":
|
|
return raw.ndjson;
|
|
case "json":
|
|
return raw.json;
|
|
case "binary":
|
|
default:
|
|
return raw.binary;
|
|
}
|
|
}
|
|
function fromCodec(enc) {
|
|
let tmpM = null;
|
|
let tmpBuf = null;
|
|
return {
|
|
preencode(state, m) {
|
|
tmpM = m;
|
|
tmpBuf = enc.encode(m);
|
|
state.end += tmpBuf.byteLength;
|
|
},
|
|
encode(state, m) {
|
|
raw.encode(state, m === tmpM ? tmpBuf : enc.encode(m));
|
|
tmpM = tmpBuf = null;
|
|
},
|
|
decode(state) {
|
|
return enc.decode(raw.decode(state));
|
|
}
|
|
};
|
|
}
|
|
function fromAbstractEncoder(enc) {
|
|
return {
|
|
preencode(state, m) {
|
|
state.end += enc.encodingLength(m);
|
|
},
|
|
encode(state, m) {
|
|
enc.encode(m, state.buffer, state.start);
|
|
state.start += enc.encode.bytes;
|
|
},
|
|
decode(state) {
|
|
const m = enc.decode(state.buffer, state.start, state.end);
|
|
state.start += enc.decode.bytes;
|
|
return m;
|
|
}
|
|
};
|
|
}
|
|
exports.encode = function encode(enc, m) {
|
|
const state = exports.state();
|
|
enc.preencode(state, m);
|
|
state.buffer = b4a.allocUnsafe(state.end);
|
|
enc.encode(state, m);
|
|
return state.buffer;
|
|
};
|
|
exports.decode = function decode(enc, buffer2) {
|
|
return enc.decode(exports.state(0, buffer2.byteLength, buffer2));
|
|
};
|
|
function zigZagInt(enc) {
|
|
return {
|
|
preencode(state, n) {
|
|
enc.preencode(state, zigZagEncodeInt(n));
|
|
},
|
|
encode(state, n) {
|
|
enc.encode(state, zigZagEncodeInt(n));
|
|
},
|
|
decode(state) {
|
|
return zigZagDecodeInt(enc.decode(state));
|
|
}
|
|
};
|
|
}
|
|
function zigZagDecodeInt(n) {
|
|
return n === 0 ? n : (n & 1) === 0 ? n / 2 : -(n + 1) / 2;
|
|
}
|
|
function zigZagEncodeInt(n) {
|
|
return n < 0 ? 2 * -n - 1 : n === 0 ? 0 : 2 * n;
|
|
}
|
|
function zigZagBigInt(enc) {
|
|
return {
|
|
preencode(state, n) {
|
|
enc.preencode(state, zigZagEncodeBigInt(n));
|
|
},
|
|
encode(state, n) {
|
|
enc.encode(state, zigZagEncodeBigInt(n));
|
|
},
|
|
decode(state) {
|
|
return zigZagDecodeBigInt(enc.decode(state));
|
|
}
|
|
};
|
|
}
|
|
function zigZagDecodeBigInt(n) {
|
|
return n === 0n ? n : (n & 1n) === 0n ? n / 2n : -(n + 1n) / 2n;
|
|
}
|
|
function zigZagEncodeBigInt(n) {
|
|
return n < 0n ? 2n * -n - 1n : n === 0n ? 0n : 2n * n;
|
|
}
|
|
function validateUint(n) {
|
|
if (n >= 0 === false)
|
|
throw new Error("uint must be positive");
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-structured-clone/lib/constants.js
|
|
var require_constants4 = __commonJS({
|
|
"../../node_modules/bare-structured-clone/lib/constants.js"(exports, module) {
|
|
module.exports = {
|
|
VERSION: 0,
|
|
type: {
|
|
// Primitive types
|
|
UNDEFINED: 0,
|
|
NULL: 1,
|
|
TRUE: 2,
|
|
FALSE: 3,
|
|
NUMBER: 4,
|
|
BIGINT: 5,
|
|
STRING: 6,
|
|
// Builtin objects
|
|
DATE: 7,
|
|
REGEXP: 8,
|
|
ERROR: 9,
|
|
// Builtin binary data objects
|
|
ARRAYBUFFER: 10,
|
|
RESIZABLEARRAYBUFFER: 11,
|
|
SHAREDARRAYBUFFER: 12,
|
|
GROWABLESHAREDARRAYBUFFER: 13,
|
|
TYPEDARRAY: 14,
|
|
DATAVIEW: 15,
|
|
// Builtin composite objects
|
|
MAP: 16,
|
|
SET: 17,
|
|
ARRAY: 18,
|
|
OBJECT: 19,
|
|
// Object references
|
|
REFERENCE: 20,
|
|
// Object transfers
|
|
TRANSFER: 21,
|
|
// Platform objects
|
|
URL: 22,
|
|
BUFFER: 23,
|
|
EXTERNAL: 24,
|
|
SERIALIZABLE: 25,
|
|
TRANSFERABLE: 26,
|
|
typedarray: {
|
|
UINT8ARRAY: 1,
|
|
UINT8CLAMPEDARRAY: 2,
|
|
INT8ARRAY: 3,
|
|
UINT16ARRAY: 4,
|
|
INT16ARRAY: 5,
|
|
UINT32ARRAY: 6,
|
|
INT32ARRAY: 7,
|
|
BIGUINT64ARRAY: 8,
|
|
BIGINT64ARRAY: 9,
|
|
FLOAT16ARRAY: 12,
|
|
FLOAT32ARRAY: 10,
|
|
FLOAT64ARRAY: 11
|
|
},
|
|
error: {
|
|
AGGREGATE: 1,
|
|
EVAL: 2,
|
|
RANGE: 3,
|
|
REFERENCE: 4,
|
|
SYNTAX: 5,
|
|
TYPE: 6,
|
|
URI: 7
|
|
}
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-structured-clone/lib/errors.js
|
|
var require_errors4 = __commonJS({
|
|
"../../node_modules/bare-structured-clone/lib/errors.js"(exports, module) {
|
|
module.exports = class DataCloneError extends Error {
|
|
constructor(msg, code, fn = DataCloneError) {
|
|
super(`${code}: ${msg}`);
|
|
this.code = code;
|
|
if (Error.captureStackTrace) {
|
|
Error.captureStackTrace(this, fn);
|
|
}
|
|
}
|
|
get name() {
|
|
return "DataCloneError";
|
|
}
|
|
static INVALID_VERSION(msg) {
|
|
return new DataCloneError(msg, "INVALID_VERSION", DataCloneError.INVALID_VERSION);
|
|
}
|
|
static UNSERIALIZABLE_TYPE(msg) {
|
|
return new DataCloneError(msg, "UNSERIALIZABLE_TYPE", DataCloneError.UNSERIALIZABLE_TYPE);
|
|
}
|
|
static UNTRANSFERABLE_TYPE(msg) {
|
|
return new DataCloneError(msg, "UNTRANSFERABLE_TYPE", DataCloneError.UNTRANSFERABLE_TYPE);
|
|
}
|
|
static ALREADY_TRANSFERRED(msg) {
|
|
return new DataCloneError(msg, "ALREADY_TRANSFERRED", DataCloneError.ALREADY_TRANSFERRED);
|
|
}
|
|
static INVALID_REFERENCE(msg) {
|
|
return new DataCloneError(msg, "INVALID_REFERENCE", DataCloneError.INVALID_REFERENCE);
|
|
}
|
|
static INVALID_INTERFACE(msg) {
|
|
return new DataCloneError(msg, "INVALID_INTERFACE", DataCloneError.INVALID_INTERFACE);
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-structured-clone/binding.js
|
|
var require_binding5 = __commonJS({
|
|
"../../node_modules/bare-structured-clone/binding.js"(exports, module) {
|
|
module.exports = __require.addon();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-structured-clone/index.js
|
|
var require_bare_structured_clone = __commonJS({
|
|
"../../node_modules/bare-structured-clone/index.js"(exports, module) {
|
|
var getType = require_bare_type();
|
|
var { isURL } = require_bare_url();
|
|
var { isBuffer } = require_bare_buffer();
|
|
var c = require_compact_encoding();
|
|
var constants = require_constants4();
|
|
var errors = require_errors4();
|
|
var binding = require_binding5();
|
|
var t = constants.type;
|
|
module.exports = exports = function structuredClone(value2, opts = {}) {
|
|
return exports.deserializeWithTransfer(
|
|
exports.serializeWithTransfer(value2, opts.transfer, opts.interfaces),
|
|
opts.interfaces
|
|
);
|
|
};
|
|
exports.serialize = function serialize(value2, forStorage = false, interfaces = []) {
|
|
return serializeValue(value2, forStorage, new InterfaceMap(interfaces), new ReferenceMap());
|
|
};
|
|
exports.serializeWithTransfer = function serializeWithTransfer(value2, transferList = [], interfaces = []) {
|
|
return serializeValueWithTransfer(value2, transferList, new InterfaceMap(interfaces));
|
|
};
|
|
exports.deserialize = function deserialize(serialized, interfaces = []) {
|
|
return deserializeValue(serialized, new InterfaceMap(interfaces), /* @__PURE__ */ new Map());
|
|
};
|
|
exports.deserializeWithTransfer = function deserializeWithTransfer(serialized, interfaces = []) {
|
|
return deserializeValueWithTransfer(serialized, new InterfaceMap(interfaces));
|
|
};
|
|
exports.constants = constants;
|
|
exports.errors = errors;
|
|
exports.symbols = {
|
|
serialize: Symbol.for("bare.serialize"),
|
|
deserialize: Symbol.for("bare.deserialize"),
|
|
detach: Symbol.for("bare.detach"),
|
|
attach: Symbol.for("bare.attach")
|
|
};
|
|
exports.Serializable = class Serializable {
|
|
[exports.symbols.serialize](forStorage) {
|
|
}
|
|
static [exports.symbols.deserialize](serialized) {
|
|
}
|
|
};
|
|
exports.Transferable = class Transferable {
|
|
constructor() {
|
|
this.detached = false;
|
|
}
|
|
[exports.symbols.detach]() {
|
|
this.detached = true;
|
|
}
|
|
static [exports.symbols.attach](serialized) {
|
|
}
|
|
};
|
|
var InterfaceMap = class {
|
|
constructor(interfaces) {
|
|
this.ids = /* @__PURE__ */ new WeakMap();
|
|
this.interfaces = /* @__PURE__ */ new Map();
|
|
let nextId = 1;
|
|
for (const constructor of interfaces) {
|
|
const id = nextId++;
|
|
this.ids.set(constructor, id);
|
|
this.interfaces.set(id, constructor);
|
|
}
|
|
}
|
|
id(constructor) {
|
|
const id = this.ids.get(constructor);
|
|
if (!id) {
|
|
throw errors.INVALID_INTERFACE(
|
|
`Class '${constructor.name}' is not registered as a serializable or transferable interface`
|
|
);
|
|
}
|
|
return id;
|
|
}
|
|
get(id) {
|
|
const constructor = this.interfaces.get(id);
|
|
if (!constructor) {
|
|
throw errors.INVALID_INTERFACE(`Interface with ID '${id}' was not found`);
|
|
}
|
|
return constructor;
|
|
}
|
|
};
|
|
var ReferenceMap = class {
|
|
constructor() {
|
|
this.ids = /* @__PURE__ */ new WeakMap();
|
|
this.nextId = 1;
|
|
}
|
|
id(object) {
|
|
let id = this.ids.get(object);
|
|
if (id) return id;
|
|
id = this.nextId++;
|
|
this.ids.set(object, id);
|
|
return id;
|
|
}
|
|
has(object) {
|
|
return this.ids.has(object);
|
|
}
|
|
};
|
|
function serializeValue(value2, forStorage, interfaces, references) {
|
|
const type = getType(value2);
|
|
if (type.isUndefined()) return { type: t.UNDEFINED };
|
|
if (type.isNull()) return { type: t.NULL };
|
|
if (type.isBoolean()) return { type: value2 ? t.TRUE : t.FALSE };
|
|
if (type.isNumber()) return { type: t.NUMBER, value: value2 };
|
|
if (type.isBigInt()) return { type: t.BIGINT, value: value2 };
|
|
if (type.isString()) return serializeString(value2);
|
|
if (type.isSymbol()) return serializeSymbol(value2);
|
|
if (type.isObject())
|
|
return serializeReferenceable(type, value2, forStorage, interfaces, references);
|
|
if (type.isFunction()) return serializeFunction(value2);
|
|
if (type.isExternal()) return serializeExternal(value2, forStorage, references);
|
|
}
|
|
function serializeString(value2) {
|
|
return { type: t.STRING, value: value2 };
|
|
}
|
|
function serializeSymbol(value2) {
|
|
throw errors.UNSERIALIZABLE_TYPE(`Symbol '${value2.description}' cannot be serialized`);
|
|
}
|
|
function serializeFunction(value2) {
|
|
throw errors.UNSERIALIZABLE_TYPE(`Function '${value2.name}' cannot be serialized`);
|
|
}
|
|
function serializeReferenceable(type, value2, forStorage, interfaces, references) {
|
|
if (references.has(value2)) return serializeReference(value2, references);
|
|
if (isURL(value2)) return serializeURL(value2, references);
|
|
if (isBuffer(value2)) return serializeBuffer(value2, forStorage, interfaces, references);
|
|
if (type.isArray()) return serializeArray(value2, forStorage, interfaces, references);
|
|
if (type.isDate()) return serializeDate(value2, references);
|
|
if (type.isRegExp()) return serializeRegExp(value2, references);
|
|
if (type.isError()) return serializeError(value2, forStorage, interfaces, references);
|
|
if (type.isMap()) return serializeMap(value2, forStorage, interfaces, references);
|
|
if (type.isSet()) return serializeSet(value2, forStorage, interfaces, references);
|
|
if (type.isArrayBuffer()) return serializeArrayBuffer(value2, references);
|
|
if (type.isSharedArrayBuffer()) return serializeSharedArrayBuffer(value2, forStorage, references);
|
|
if (type.isTypedArray())
|
|
return serializeTypedArray(type, value2, forStorage, interfaces, references);
|
|
if (type.isDataView()) return serializeDataView(value2, forStorage, interfaces, references);
|
|
if (type.isPromise() || type.isProxy() || type.isWeakMap() || type.isWeakSet() || type.isWeakRef()) {
|
|
throw errors.UNSERIALIZABLE_TYPE(`${value2.constructor.name} cannot be serialized`);
|
|
}
|
|
const serialize = value2[Symbol.for("bare.serialize")];
|
|
if (serialize) return serializeSerializable(value2, serialize, forStorage, interfaces, references);
|
|
return serializeObject(value2, forStorage, interfaces, references);
|
|
}
|
|
function serializeReference(value2, references) {
|
|
return { type: t.REFERENCE, id: references.id(value2) };
|
|
}
|
|
function serializeDate(value2, references) {
|
|
return { type: t.DATE, id: references.id(value2), value: value2.getTime() };
|
|
}
|
|
function serializeRegExp(value2, references) {
|
|
return {
|
|
type: t.REGEXP,
|
|
id: references.id(value2),
|
|
source: value2.source,
|
|
flags: value2.flags
|
|
};
|
|
}
|
|
function serializeError(value2, forStorage, interfaces, references) {
|
|
let name = 0;
|
|
switch (value2.name) {
|
|
case "AggregateError":
|
|
name = t.error.AGGREGATE;
|
|
break;
|
|
case "EvalError":
|
|
name = t.error.EVAL;
|
|
break;
|
|
case "RangeError":
|
|
name = t.error.RANGE;
|
|
break;
|
|
case "ReferenceError":
|
|
name = t.error.REFERENCE;
|
|
break;
|
|
case "SyntaxError":
|
|
name = t.error.SYNTAX;
|
|
break;
|
|
case "TypeError":
|
|
name = t.error.TYPE;
|
|
break;
|
|
case "URIError":
|
|
name = t.error.URI;
|
|
break;
|
|
}
|
|
const serialized = {
|
|
type: t.ERROR,
|
|
id: references.id(value2),
|
|
name,
|
|
message: value2.message.toString(),
|
|
stack: serializeValue(value2.stack, forStorage, interfaces, references)
|
|
};
|
|
if ("cause" in value2) {
|
|
serialized.cause = serializeValue(value2.cause, forStorage, interfaces, references);
|
|
}
|
|
if (name === t.error.AGGREGATE) {
|
|
serialized.errors = value2.errors.map(
|
|
(err) => serializeValue(err, forStorage, interfaces, references)
|
|
);
|
|
}
|
|
return serialized;
|
|
}
|
|
function serializeArrayBuffer(value2, references) {
|
|
if (value2.detached) {
|
|
throw errors.UNSERIALIZABLE_TYPE("Detached ArrayBuffer cannot be serialized");
|
|
}
|
|
const id = references.id(value2);
|
|
if (value2.resizable) {
|
|
return {
|
|
type: t.RESIZABLEARRAYBUFFER,
|
|
id,
|
|
owned: false,
|
|
data: value2,
|
|
maxByteLength: value2.maxByteLength
|
|
};
|
|
}
|
|
return {
|
|
type: t.ARRAYBUFFER,
|
|
id,
|
|
owned: false,
|
|
data: value2
|
|
};
|
|
}
|
|
function serializeSharedArrayBuffer(value2, forStorage, references) {
|
|
if (forStorage) {
|
|
throw errors.UNSERIALIZABLE_TYPE("SharedArrayBuffer cannot be serialized to storage");
|
|
}
|
|
const id = references.id(value2);
|
|
const backingStore = binding.getSharedArrayBufferBackingStore(value2);
|
|
if (value2.growable) {
|
|
return {
|
|
type: t.GROWABLESHAREDARRAYBUFFER,
|
|
id,
|
|
backingStore,
|
|
maxByteLength: value2.maxByteLength
|
|
};
|
|
}
|
|
return {
|
|
type: t.SHAREDARRAYBUFFER,
|
|
id,
|
|
backingStore
|
|
};
|
|
}
|
|
function serializeTypedArray(type, value2, forStorage, interfaces, references) {
|
|
let view;
|
|
if (type.isUint8Array()) {
|
|
view = t.typedarray.UINT8ARRAY;
|
|
} else if (type.isUint8ClampedArray()) {
|
|
view = t.typedarray.UINT8CLAMPEDARRAY;
|
|
} else if (type.isInt8Array()) {
|
|
view = t.typedarray.INT8ARRAY;
|
|
} else if (type.isUint16Array()) {
|
|
view = t.typedarray.UINT16ARRAY;
|
|
} else if (type.isInt16Array()) {
|
|
view = t.typedarray.INT16ARRAY;
|
|
} else if (type.isUint32Array()) {
|
|
view = t.typedarray.UINT32ARRAY;
|
|
} else if (type.isInt32Array()) {
|
|
view = t.typedarray.INT32ARRAY;
|
|
} else if (type.isBigUint64Array()) {
|
|
view = t.typedarray.BIGUINT64ARRAY;
|
|
} else if (type.isBigInt64Array()) {
|
|
view = t.typedarray.BIGINT64ARRAY;
|
|
} else if (type.isFloat16Array()) {
|
|
view = t.typedarray.FLOAT16ARRAY;
|
|
} else if (type.isFloat32Array()) {
|
|
view = t.typedarray.FLOAT32ARRAY;
|
|
} else if (type.isFloat64Array()) {
|
|
view = t.typedarray.FLOAT64ARRAY;
|
|
}
|
|
return {
|
|
type: t.TYPEDARRAY,
|
|
id: references.id(value2),
|
|
view,
|
|
buffer: serializeValue(value2.buffer, forStorage, interfaces, references),
|
|
byteOffset: value2.byteOffset,
|
|
byteLength: value2.byteLength,
|
|
length: value2.length
|
|
};
|
|
}
|
|
function serializeDataView(value2, forStorage, interfaces, references) {
|
|
return {
|
|
type: t.DATAVIEW,
|
|
id: references.id(references),
|
|
buffer: serializeValue(value2.buffer, forStorage, interfaces, references),
|
|
byteOffset: value2.byteOffset,
|
|
byteLength: value2.byteLength
|
|
};
|
|
}
|
|
function serializeMap(value2, forStorage, interfaces, references) {
|
|
const id = references.id(value2);
|
|
const data = [];
|
|
for (const entry2 of value2) {
|
|
const [key, value3] = entry2;
|
|
data.push({
|
|
key: serializeValue(key, forStorage, interfaces, references),
|
|
value: serializeValue(value3, forStorage, interfaces, references)
|
|
});
|
|
}
|
|
return { type: t.MAP, id, data };
|
|
}
|
|
function serializeSet(value2, forStorage, interfaces, references) {
|
|
const id = references.id(value2);
|
|
const data = [];
|
|
for (const entry2 of value2) {
|
|
data.push(serializeValue(entry2, forStorage, interfaces, references));
|
|
}
|
|
return { type: t.SET, id, data };
|
|
}
|
|
function serializeArray(value2, forStorage, interfaces, references) {
|
|
const id = references.id(value2);
|
|
const properties2 = [];
|
|
for (const entry2 of Object.entries(value2)) {
|
|
const [key, value3] = entry2;
|
|
properties2.push({
|
|
key,
|
|
value: serializeValue(value3, forStorage, interfaces, references)
|
|
});
|
|
}
|
|
return { type: t.ARRAY, id, length: value2.length, properties: properties2 };
|
|
}
|
|
function serializeObject(value2, forStorage, interfaces, references) {
|
|
const id = references.id(value2);
|
|
const properties2 = [];
|
|
for (const entry2 of Object.entries(value2)) {
|
|
const [key, value3] = entry2;
|
|
properties2.push({
|
|
key,
|
|
value: serializeValue(value3, forStorage, interfaces, references)
|
|
});
|
|
}
|
|
return { type: t.OBJECT, id, properties: properties2 };
|
|
}
|
|
function serializeURL(value2, references) {
|
|
return { type: t.URL, id: references.id(value2), href: value2.href };
|
|
}
|
|
function serializeBuffer(value2, forStorage, interfaces, references) {
|
|
if (value2.detached) {
|
|
throw errors.UNSERIALIZABLE_TYPE("Detached Buffer cannot be serialized");
|
|
}
|
|
return {
|
|
type: t.BUFFER,
|
|
id: references.id(value2),
|
|
buffer: serializeValue(value2.buffer, forStorage, interfaces, references),
|
|
byteOffset: value2.byteOffset,
|
|
byteLength: value2.byteLength
|
|
};
|
|
}
|
|
function serializeExternal(value2, forStorage) {
|
|
if (forStorage) {
|
|
throw errors.UNSERIALIZABLE_TYPE("External pointer cannot be serialized to storage");
|
|
}
|
|
return {
|
|
type: t.EXTERNAL,
|
|
pointer: binding.getExternal(value2)
|
|
};
|
|
}
|
|
function serializeSerializable(value2, serializer, forStorage, interfaces, references) {
|
|
return {
|
|
type: t.SERIALIZABLE,
|
|
id: references.id(value2),
|
|
interface: interfaces.id(value2.constructor),
|
|
value: serializeValue(serializer.call(value2, forStorage), forStorage, interfaces, references)
|
|
};
|
|
}
|
|
function serializeValueWithTransfer(value2, transferList, interfaces) {
|
|
const references = new ReferenceMap();
|
|
for (const transferable of transferList) {
|
|
const type = getType(transferable);
|
|
if (type.isArrayBuffer()) {
|
|
if (transferable.detached) {
|
|
throw errors.UNTRANSFERABLE_TYPE("Detached 'ArrayBuffer' cannot be transferred");
|
|
}
|
|
if (references.has(transferable)) {
|
|
throw errors.ALREADY_TRANSFERRED("'ArrayBuffer' has already been transferred");
|
|
}
|
|
references.id(transferable);
|
|
} else {
|
|
const detach = transferable[exports.symbols.detach];
|
|
if (detach) {
|
|
if (transferable.detached) {
|
|
throw errors.UNTRANSFERABLE_TYPE(
|
|
`Detached '${transferable.constructor.name}' cannot be transferred`
|
|
);
|
|
}
|
|
if (references.has(transferable)) {
|
|
throw errors.ALREADY_TRANSFERRED(
|
|
`'${transferable.constructor.name}' has already been transferred`
|
|
);
|
|
}
|
|
references.id(transferable);
|
|
} else {
|
|
throw errors.UNTRANSFERABLE_TYPE("Value cannot be transferred");
|
|
}
|
|
}
|
|
}
|
|
const serialized = serializeValue(value2, false, interfaces, references);
|
|
const transfers2 = [];
|
|
for (const transferable of transferList) {
|
|
const type = getType(transferable);
|
|
if (type.isArrayBuffer()) {
|
|
if (transferable.detached) {
|
|
throw errors.UNTRANSFERABLE_TYPE("Detached ArrayBuffer cannot be transferred");
|
|
}
|
|
const backingStore = binding.getArrayBufferBackingStore(transferable);
|
|
const id = references.id(transferable);
|
|
let transfer2;
|
|
if (value2.resizable) {
|
|
transfer2 = {
|
|
type: t.RESIZABLEARRAYBUFFER,
|
|
id,
|
|
backingStore,
|
|
maxByteLength: value2.maxByteLength
|
|
};
|
|
} else {
|
|
transfer2 = { type: t.ARRAYBUFFER, id, backingStore };
|
|
}
|
|
transfers2.push(transfer2);
|
|
binding.detachArrayBuffer(transferable);
|
|
} else {
|
|
if (transferable.detached) {
|
|
throw errors.UNTRANSFERABLE_TYPE(
|
|
`Detached '${transferable.constructor.name}' cannot be transferred`
|
|
);
|
|
}
|
|
const detach = transferable[exports.symbols.detach];
|
|
const transfer2 = {
|
|
type: t.TRANSFERABLE,
|
|
id: references.id(transferable),
|
|
interface: interfaces.id(transferable.constructor),
|
|
value: serializeValue(detach.call(transferable), false, interfaces, references)
|
|
};
|
|
transfers2.push(transfer2);
|
|
}
|
|
}
|
|
return { type: t.TRANSFER, transfers: transfers2, value: serialized };
|
|
}
|
|
function deserializeValue(serialized, interfaces, references) {
|
|
let value2;
|
|
switch (serialized.type) {
|
|
case t.UNDEFINED:
|
|
return void 0;
|
|
case t.NULL:
|
|
return null;
|
|
case t.TRUE:
|
|
return true;
|
|
case t.FALSE:
|
|
return false;
|
|
case t.NUMBER:
|
|
case t.BIGINT:
|
|
case t.STRING:
|
|
return serialized.value;
|
|
case t.EXTERNAL:
|
|
return binding.createExternal(serialized.pointer);
|
|
case t.DATE:
|
|
value2 = new Date(serialized.value);
|
|
break;
|
|
case t.REGEXP:
|
|
value2 = new RegExp(serialized.source, serialized.flags);
|
|
break;
|
|
case t.ERROR: {
|
|
const options = {};
|
|
if ("cause" in serialized) {
|
|
options.case = deserializeValue(serialized.cause, interfaces, references);
|
|
}
|
|
switch (serialized.name) {
|
|
case t.error.AGGREGATE:
|
|
value2 = new AggregateError(
|
|
serialized.errors.map((err) => deserializeValue(err, interfaces, references)),
|
|
serialized.message,
|
|
options
|
|
);
|
|
break;
|
|
case t.error.EVAL:
|
|
value2 = new EvalError(serialized.message, options);
|
|
break;
|
|
case t.error.RANGE:
|
|
value2 = new RangeError(serialized.message, options);
|
|
break;
|
|
case t.error.REFERENCE:
|
|
value2 = new ReferenceError(serialized.message, options);
|
|
break;
|
|
case t.error.SYNTAX:
|
|
value2 = new SyntaxError(serialized.message, options);
|
|
break;
|
|
case t.error.TYPE:
|
|
value2 = new TypeError(serialized.message, options);
|
|
break;
|
|
default:
|
|
value2 = new Error(serialized.message, options);
|
|
}
|
|
value2.stack = deserializeValue(serialized.stack, interfaces, references);
|
|
break;
|
|
}
|
|
case t.ARRAYBUFFER:
|
|
if (serialized.owned) value2 = serialized.data;
|
|
else {
|
|
value2 = new ArrayBuffer(serialized.data.byteLength);
|
|
Buffer.from(value2).set(Buffer.from(serialized.data));
|
|
}
|
|
break;
|
|
case t.RESIZABLEARRAYBUFFER:
|
|
if (serialized.owned) value2 = serialized.data;
|
|
else {
|
|
value2 = new ArrayBuffer(serialized.data.byteLength, {
|
|
maxByteLength: serialized.maxByteLength
|
|
});
|
|
Buffer.from(value2).set(Buffer.from(serialized.data));
|
|
}
|
|
break;
|
|
case t.SHAREDARRAYBUFFER:
|
|
case t.GROWABLESHAREDARRAYBUFFER:
|
|
value2 = binding.createSharedArrayBuffer(serialized.backingStore);
|
|
Buffer.from(serialized.backingStore).fill(0);
|
|
break;
|
|
case t.TYPEDARRAY: {
|
|
const buffer = deserializeValue(serialized.buffer, interfaces, references);
|
|
switch (serialized.view) {
|
|
case t.typedarray.UINT8ARRAY:
|
|
value2 = new Uint8Array(buffer, serialized.byteOffset, serialized.length);
|
|
break;
|
|
case t.typedarray.UINT8CLAMPEDARRAY:
|
|
value2 = new Uint8ClampedArray(buffer, serialized.byteOffset, serialized.length);
|
|
break;
|
|
case t.typedarray.INT8ARRAY:
|
|
value2 = new Int8Array(buffer, serialized.byteOffset, serialized.length);
|
|
break;
|
|
case t.typedarray.UINT16ARRAY:
|
|
value2 = new Uint16Array(buffer, serialized.byteOffset, serialized.length);
|
|
break;
|
|
case t.typedarray.INT16ARRAY:
|
|
value2 = new Int16Array(buffer, serialized.byteOffset, serialized.length);
|
|
break;
|
|
case t.typedarray.UINT32ARRAY:
|
|
value2 = new Uint32Array(buffer, serialized.byteOffset, serialized.length);
|
|
break;
|
|
case t.typedarray.INT32ARRAY:
|
|
value2 = new Int32Array(buffer, serialized.byteOffset, serialized.length);
|
|
break;
|
|
case t.typedarray.BIGUINT64ARRAY:
|
|
value2 = new BigUint64Array(buffer, serialized.byteOffset, serialized.length);
|
|
break;
|
|
case t.typedarray.BIGINT64ARRAY:
|
|
value2 = new BigInt64Array(buffer, serialized.byteOffset, serialized.length);
|
|
break;
|
|
case t.typedarray.FLOAT16ARRAY:
|
|
value2 = new Float16Array(buffer, serialized.byteOffset, serialized.length);
|
|
break;
|
|
case t.typedarray.FLOAT32ARRAY:
|
|
value2 = new Float32Array(buffer, serialized.byteOffset, serialized.length);
|
|
break;
|
|
case t.typedarray.FLOAT64ARRAY:
|
|
value2 = new Float64Array(buffer, serialized.byteOffset, serialized.length);
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
case t.DATAVIEW:
|
|
value2 = new DataView(
|
|
deserializeValue(serialized.buffer, interfaces, references),
|
|
serialized.byteOffset,
|
|
serialized.byteLength
|
|
);
|
|
break;
|
|
case t.MAP:
|
|
value2 = /* @__PURE__ */ new Map();
|
|
break;
|
|
case t.SET:
|
|
value2 = /* @__PURE__ */ new Set();
|
|
break;
|
|
case t.ARRAY:
|
|
value2 = new Array(serialized.length);
|
|
break;
|
|
case t.OBJECT:
|
|
value2 = {};
|
|
break;
|
|
case t.REFERENCE:
|
|
if (references.has(serialized.id)) value2 = references.get(serialized.id);
|
|
else {
|
|
throw errors.INVALID_REFERENCE(`Object with ID '${serialized.id}' was not found`);
|
|
}
|
|
return value2;
|
|
case t.URL:
|
|
return new URL(serialized.href);
|
|
case t.BUFFER:
|
|
value2 = Buffer.from(
|
|
deserializeValue(serialized.buffer, interfaces, references),
|
|
serialized.byteOffset,
|
|
serialized.byteLength
|
|
);
|
|
break;
|
|
case t.SERIALIZABLE: {
|
|
const constructor = interfaces.get(serialized.interface);
|
|
const deserialize = constructor[exports.symbols.deserialize];
|
|
value2 = deserialize.call(
|
|
constructor,
|
|
deserializeValue(serialized.value, interfaces, references)
|
|
);
|
|
break;
|
|
}
|
|
}
|
|
references.set(serialized.id, value2);
|
|
switch (serialized.type) {
|
|
case t.MAP:
|
|
for (const entry2 of serialized.data) {
|
|
value2.set(
|
|
deserializeValue(entry2.key, interfaces, references),
|
|
deserializeValue(entry2.value, interfaces, references)
|
|
);
|
|
}
|
|
break;
|
|
case t.SET:
|
|
for (const entry2 of serialized.data) {
|
|
value2.add(deserializeValue(entry2, interfaces, references));
|
|
}
|
|
break;
|
|
case t.ARRAY:
|
|
case t.OBJECT:
|
|
for (const entry2 of serialized.properties) {
|
|
value2[entry2.key] = deserializeValue(entry2.value, interfaces, references);
|
|
}
|
|
break;
|
|
}
|
|
return value2;
|
|
}
|
|
function deserializeValueWithTransfer(serialized, interfaces) {
|
|
const references = /* @__PURE__ */ new Map();
|
|
for (const transfer2 of serialized.transfers) {
|
|
switch (transfer2.type) {
|
|
case t.ARRAYBUFFER:
|
|
case t.RESIZABLEARRAYBUFFER:
|
|
references.set(transfer2.id, binding.createArrayBuffer(transfer2.backingStore));
|
|
break;
|
|
case t.TRANSFERABLE: {
|
|
const constructor = interfaces.get(transfer2.interface);
|
|
const attach = constructor[exports.symbols.attach];
|
|
references.set(
|
|
transfer2.id,
|
|
attach.call(constructor, deserializeValue(transfer2.value, interfaces, references))
|
|
);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return deserializeValue(serialized.value, interfaces, references);
|
|
}
|
|
var header = {
|
|
preencode(state) {
|
|
c.uint.preencode(state, constants.VERSION);
|
|
c.uint.preencode(state, 0);
|
|
},
|
|
encode(state) {
|
|
c.uint.encode(state, constants.VERSION);
|
|
c.uint.encode(state, 0);
|
|
},
|
|
decode(state) {
|
|
const version = c.uint.decode(state);
|
|
if (version !== constants.VERSION) {
|
|
throw errors.INVALID_VERSION(`Invalid ABI version '${version}'`);
|
|
}
|
|
c.uint.decode(state);
|
|
}
|
|
};
|
|
var property = {
|
|
preencode(state, m) {
|
|
c.string.preencode(state, m.key);
|
|
value.preencode(state, m.value);
|
|
},
|
|
encode(state, m) {
|
|
c.string.encode(state, m.key);
|
|
value.encode(state, m.value);
|
|
},
|
|
decode(state) {
|
|
return {
|
|
key: c.string.decode(state),
|
|
value: value.decode(state)
|
|
};
|
|
}
|
|
};
|
|
var properties = c.array(property);
|
|
var entry = {
|
|
preencode(state, m) {
|
|
value.preencode(state, m.key);
|
|
value.preencode(state, m.value);
|
|
},
|
|
encode(state, m) {
|
|
value.encode(state, m.key);
|
|
value.encode(state, m.value);
|
|
},
|
|
decode(state) {
|
|
return {
|
|
key: value.decode(state),
|
|
value: value.decode(state)
|
|
};
|
|
}
|
|
};
|
|
var entries = c.array(entry);
|
|
var transfer = {
|
|
preencode(state, m) {
|
|
c.uint.preencode(state, m.type);
|
|
c.uint.preencode(state, m.id);
|
|
switch (m.type) {
|
|
case t.ARRAYBUFFER:
|
|
c.arraybuffer.preencode(state, m.backingStore);
|
|
break;
|
|
case t.RESIZABLEARRAYBUFFER:
|
|
c.arraybuffer.preencode(state, m.backingStore);
|
|
c.uint.preencode(state, m.maxByteLength);
|
|
break;
|
|
case t.TRANSFERABLE:
|
|
c.uint.preencode(state, m.interface);
|
|
value.preencode(state, m.value);
|
|
break;
|
|
}
|
|
},
|
|
encode(state, m) {
|
|
c.uint.encode(state, m.type);
|
|
c.uint.encode(state, m.id);
|
|
switch (m.type) {
|
|
case t.ARRAYBUFFER:
|
|
c.arraybuffer.encode(state, m.backingStore);
|
|
break;
|
|
case t.RESIZABLEARRAYBUFFER:
|
|
c.arraybuffer.encode(state, m.backingStore);
|
|
c.uint.encode(state, m.maxByteLength);
|
|
break;
|
|
case t.TRANSFERABLE:
|
|
c.uint.encode(state, m.interface);
|
|
value.encode(state, m.value);
|
|
break;
|
|
}
|
|
},
|
|
decode(state) {
|
|
const type = c.uint.decode(state);
|
|
const id = c.uint.decode(state);
|
|
switch (type) {
|
|
case t.ARRAYBUFFER:
|
|
return {
|
|
type,
|
|
id,
|
|
backingStore: c.arraybuffer.decode(state)
|
|
};
|
|
case t.RESIZABLEARRAYBUFFER:
|
|
return {
|
|
type,
|
|
id,
|
|
backingStore: c.arraybuffer.decode(state),
|
|
maxByteLength: c.uint.decode(state)
|
|
};
|
|
case t.TRANSFERABLE:
|
|
return {
|
|
type,
|
|
id,
|
|
interface: c.uint.decode(state),
|
|
value: value.decode(state)
|
|
};
|
|
}
|
|
}
|
|
};
|
|
var transfers = c.array(transfer);
|
|
var value = {
|
|
preencode(state, m) {
|
|
c.uint.preencode(state, m.type);
|
|
switch (m.type) {
|
|
case t.UNDEFINED:
|
|
case t.NULL:
|
|
case t.TRUE:
|
|
case t.FALSE:
|
|
return;
|
|
case t.NUMBER:
|
|
return c.float64.preencode(state, m.value);
|
|
case t.BIGINT:
|
|
return c.bigint.preencode(state, m.value);
|
|
case t.STRING:
|
|
return c.string.preencode(state, m.value);
|
|
case t.EXTERNAL:
|
|
return c.arraybuffer.preencode(state, m.pointer);
|
|
case t.TRANSFER:
|
|
transfers.preencode(state, m.transfers);
|
|
value.preencode(state, m.value);
|
|
return;
|
|
}
|
|
c.uint.preencode(state, m.type);
|
|
switch (m.type) {
|
|
case t.DATE:
|
|
c.int.preencode(state, m.value);
|
|
break;
|
|
case t.REGEXP:
|
|
c.string.preencode(state, m.source);
|
|
c.string.preencode(state, m.flags);
|
|
break;
|
|
case t.ERROR:
|
|
c.uint.preencode(state, 0);
|
|
c.uint.preencode(state, m.name);
|
|
c.string.preencode(state, m.message);
|
|
value.preencode(state, m.stack);
|
|
if ("cause" in m) value.preencode(state, m.cause);
|
|
if (m.name === t.error.AGGREGATE) values.preencode(state, m.errors);
|
|
break;
|
|
case t.ARRAYBUFFER:
|
|
c.arraybuffer.preencode(state, m.data);
|
|
break;
|
|
case t.RESIZABLEARRAYBUFFER:
|
|
c.arraybuffer.preencode(state, m.data);
|
|
c.uint.preencode(state, m.maxByteLength);
|
|
break;
|
|
case t.SHAREDARRAYBUFFER:
|
|
c.arraybuffer.preencode(state, m.backingStore);
|
|
break;
|
|
case t.GROWABLESHAREDARRAYBUFFER:
|
|
c.arraybuffer.preencode(state, m.backingStore);
|
|
c.uint.preencode(state, m.maxByteLength);
|
|
break;
|
|
case t.TYPEDARRAY:
|
|
c.uint.preencode(state, m.view);
|
|
value.preencode(state, m.buffer);
|
|
c.uint.preencode(state, m.byteOffset);
|
|
c.uint.preencode(state, m.byteLength);
|
|
c.uint.preencode(state, m.length);
|
|
break;
|
|
case t.DATAVIEW:
|
|
value.preencode(state, m.buffer);
|
|
c.uint.preencode(state, m.byteOffset);
|
|
c.uint.preencode(state, m.byteLength);
|
|
break;
|
|
case t.MAP:
|
|
entries.preencode(state, m.data);
|
|
break;
|
|
case t.SET:
|
|
values.preencode(state, m.data);
|
|
break;
|
|
case t.ARRAY:
|
|
c.uint.preencode(state, m.length);
|
|
properties.preencode(state, m.properties);
|
|
break;
|
|
case t.OBJECT:
|
|
properties.preencode(state, m.properties);
|
|
break;
|
|
case t.REFERENCE:
|
|
break;
|
|
case t.URL:
|
|
c.string.preencode(state, m.href);
|
|
break;
|
|
case t.BUFFER:
|
|
value.preencode(state, m.buffer);
|
|
c.uint.preencode(state, m.byteOffset);
|
|
c.uint.preencode(state, m.byteLength);
|
|
break;
|
|
case t.SERIALIZABLE:
|
|
c.uint.preencode(state, m.interface);
|
|
value.preencode(state, m.value);
|
|
break;
|
|
}
|
|
},
|
|
encode(state, m) {
|
|
c.uint.encode(state, m.type);
|
|
switch (m.type) {
|
|
case t.UNDEFINED:
|
|
case t.NULL:
|
|
case t.TRUE:
|
|
case t.FALSE:
|
|
return;
|
|
case t.NUMBER:
|
|
return c.float64.encode(state, m.value);
|
|
case t.BIGINT:
|
|
return c.bigint.encode(state, m.value);
|
|
case t.STRING:
|
|
return c.string.encode(state, m.value);
|
|
case t.EXTERNAL:
|
|
return c.arraybuffer.encode(state, m.pointer);
|
|
case t.TRANSFER:
|
|
transfers.encode(state, m.transfers);
|
|
value.encode(state, m.value);
|
|
return;
|
|
}
|
|
c.uint.encode(state, m.id);
|
|
switch (m.type) {
|
|
case t.DATE:
|
|
c.int.encode(state, m.value);
|
|
break;
|
|
case t.REGEXP:
|
|
c.string.encode(state, m.source);
|
|
c.string.encode(state, m.flags);
|
|
break;
|
|
case t.ERROR:
|
|
c.uint.encode(state, "cause" in m ? 1 : 0);
|
|
c.uint.encode(state, m.name);
|
|
c.string.encode(state, m.message);
|
|
value.encode(state, m.stack);
|
|
if ("cause" in m) value.encode(state, m.cause);
|
|
if (m.name === t.error.AGGREGATE) values.encode(state, m.errors);
|
|
break;
|
|
case t.ARRAYBUFFER:
|
|
c.arraybuffer.encode(state, m.data);
|
|
break;
|
|
case t.RESIZABLEARRAYBUFFER:
|
|
c.arraybuffer.encode(state, m.data);
|
|
c.uint.encode(state, m.maxByteLength);
|
|
break;
|
|
case t.SHAREDARRAYBUFFER:
|
|
c.arraybuffer.encode(state, m.backingStore);
|
|
break;
|
|
case t.GROWABLESHAREDARRAYBUFFER:
|
|
c.arraybuffer.encode(state, m.backingStore);
|
|
c.uint.encode(state, m.maxByteLength);
|
|
break;
|
|
case t.TYPEDARRAY:
|
|
c.uint.encode(state, m.view);
|
|
value.encode(state, m.buffer);
|
|
c.uint.encode(state, m.byteOffset);
|
|
c.uint.encode(state, m.byteLength);
|
|
c.uint.encode(state, m.length);
|
|
break;
|
|
case t.DATAVIEW:
|
|
value.encode(state, m.buffer);
|
|
c.uint.encode(state, m.byteOffset);
|
|
c.uint.encode(state, m.byteLength);
|
|
break;
|
|
case t.MAP:
|
|
entries.encode(state, m.data);
|
|
break;
|
|
case t.SET:
|
|
values.encode(state, m.data);
|
|
break;
|
|
case t.ARRAY:
|
|
c.uint.encode(state, m.length);
|
|
properties.encode(state, m.properties);
|
|
break;
|
|
case t.OBJECT:
|
|
properties.encode(state, m.properties);
|
|
break;
|
|
case t.REFERENCE:
|
|
break;
|
|
case t.URL:
|
|
c.string.encode(state, m.href);
|
|
break;
|
|
case t.BUFFER:
|
|
value.encode(state, m.buffer);
|
|
c.uint.encode(state, m.byteOffset);
|
|
c.uint.encode(state, m.byteLength);
|
|
break;
|
|
case t.SERIALIZABLE:
|
|
c.uint.encode(state, m.interface);
|
|
value.encode(state, m.value);
|
|
break;
|
|
}
|
|
},
|
|
decode(state) {
|
|
const type = c.uint.decode(state);
|
|
switch (type) {
|
|
case t.UNDEFINED:
|
|
case t.NULL:
|
|
case t.TRUE:
|
|
case t.FALSE:
|
|
return {
|
|
type
|
|
};
|
|
case t.NUMBER:
|
|
return {
|
|
type,
|
|
value: c.float64.decode(state)
|
|
};
|
|
case t.BIGINT:
|
|
return {
|
|
type,
|
|
value: c.bigint.decode(state)
|
|
};
|
|
case t.STRING:
|
|
return {
|
|
type,
|
|
value: c.string.decode(state)
|
|
};
|
|
case t.EXTERNAL:
|
|
return {
|
|
type,
|
|
pointer: c.arraybuffer.decode(state)
|
|
};
|
|
case t.TRANSFER:
|
|
return {
|
|
type,
|
|
transfers: transfers.decode(state),
|
|
value: value.decode(state)
|
|
};
|
|
}
|
|
const id = c.uint.decode(state);
|
|
switch (type) {
|
|
case t.DATE:
|
|
return {
|
|
type,
|
|
id,
|
|
value: c.int.decode(state)
|
|
};
|
|
case t.REGEXP:
|
|
return {
|
|
type,
|
|
id,
|
|
source: c.string.decode(state),
|
|
flags: c.string.decode(state)
|
|
};
|
|
case t.ERROR: {
|
|
const flags = c.uint.decode(state);
|
|
const hasCause = (flags & 1) !== 0;
|
|
const m = {
|
|
type,
|
|
id,
|
|
name: c.uint.decode(state),
|
|
message: c.string.decode(state),
|
|
stack: value.decode(state)
|
|
};
|
|
if (hasCause) m.cause = value.decode(state);
|
|
if (m.name === t.error.AGGREGATE) m.errors = values.decode(state);
|
|
return m;
|
|
}
|
|
case t.ARRAYBUFFER:
|
|
return {
|
|
type,
|
|
id,
|
|
owned: true,
|
|
data: c.arraybuffer.decode(state)
|
|
};
|
|
case t.RESIZABLEARRAYBUFFER:
|
|
return {
|
|
type,
|
|
id,
|
|
owned: true,
|
|
data: c.arraybuffer.decode(state),
|
|
maxByteLength: c.uint.decode(state)
|
|
};
|
|
case t.SHAREDARRAYBUFFER:
|
|
return {
|
|
type,
|
|
id,
|
|
backingStore: c.arraybuffer.decode(state)
|
|
};
|
|
case t.GROWABLESHAREDARRAYBUFFER:
|
|
return {
|
|
type,
|
|
id,
|
|
backingStore: c.arraybuffer.decode(state),
|
|
maxByteLength: c.uint.decode(state)
|
|
};
|
|
case t.TYPEDARRAY:
|
|
return {
|
|
type,
|
|
id,
|
|
view: c.uint.decode(state),
|
|
buffer: value.decode(state),
|
|
byteOffset: c.uint.decode(state),
|
|
byteLength: c.uint.decode(state),
|
|
length: c.uint.decode(state)
|
|
};
|
|
case t.DATAVIEW:
|
|
return {
|
|
type,
|
|
id,
|
|
buffer: value.decode(state),
|
|
byteOffset: c.uint.decode(state),
|
|
byteLength: c.uint.decode(state)
|
|
};
|
|
case t.MAP:
|
|
return {
|
|
type,
|
|
id,
|
|
data: entries.decode(state)
|
|
};
|
|
case t.SET:
|
|
return {
|
|
type,
|
|
id,
|
|
data: values.decode(state)
|
|
};
|
|
case t.ARRAY:
|
|
return {
|
|
type,
|
|
id,
|
|
length: c.uint.decode(state),
|
|
properties: properties.decode(state)
|
|
};
|
|
case t.OBJECT:
|
|
return {
|
|
type,
|
|
id,
|
|
properties: properties.decode(state)
|
|
};
|
|
case t.REFERENCE:
|
|
return {
|
|
type,
|
|
id
|
|
};
|
|
case t.URL:
|
|
return {
|
|
type,
|
|
id,
|
|
href: c.string.decode(state)
|
|
};
|
|
case t.BUFFER:
|
|
return {
|
|
type,
|
|
id,
|
|
buffer: value.decode(state),
|
|
byteOffset: c.uint.decode(state),
|
|
byteLength: c.uint.decode(state)
|
|
};
|
|
case t.SERIALIZABLE:
|
|
return {
|
|
type,
|
|
id,
|
|
interface: c.uint.decode(state),
|
|
value: value.decode(state)
|
|
};
|
|
}
|
|
}
|
|
};
|
|
var values = c.array(value);
|
|
exports.preencode = function preencode(state, m) {
|
|
header.preencode(state);
|
|
value.preencode(state, m);
|
|
};
|
|
exports.encode = function encode(state, m) {
|
|
header.encode(state);
|
|
value.encode(state, m);
|
|
};
|
|
exports.decode = function decode(state) {
|
|
header.decode(state);
|
|
return value.decode(state);
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-channel/binding.js
|
|
var require_binding6 = __commonJS({
|
|
"../../node_modules/bare-channel/binding.js"(exports, module) {
|
|
module.exports = __require.addon();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-channel/lib/queue.js
|
|
var require_queue = __commonJS({
|
|
"../../node_modules/bare-channel/lib/queue.js"(exports, module) {
|
|
module.exports = class Queue {
|
|
constructor(capacity = 128) {
|
|
this._data = new Array(capacity);
|
|
this._mask = capacity - 1;
|
|
this._length = 0;
|
|
this._read = 0;
|
|
this._write = 0;
|
|
}
|
|
get length() {
|
|
return this._length;
|
|
}
|
|
get capacity() {
|
|
return this._data.length;
|
|
}
|
|
shift() {
|
|
const value = this._data[this._read];
|
|
if (value === void 0) return void 0;
|
|
this._data[this._read] = void 0;
|
|
this._read = this._read + 1 & this._mask;
|
|
this._length--;
|
|
return value;
|
|
}
|
|
push(value) {
|
|
if (this._data[this._write] !== void 0) {
|
|
throw new RangeError("Queue is full");
|
|
}
|
|
this._data[this._write] = value;
|
|
this._write = this._write + 1 & this._mask;
|
|
this._length++;
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-channel/index.js
|
|
var require_bare_channel = __commonJS({
|
|
"../../node_modules/bare-channel/index.js"(exports, module) {
|
|
var EventEmitter = require_bare_events();
|
|
var { Readable, Writable, Duplex } = require_bare_stream();
|
|
var structuredClone = require_bare_structured_clone();
|
|
var binding = require_binding6();
|
|
var Queue = require_queue();
|
|
var ENDED = 1;
|
|
var REMOTE_ENDED = 2;
|
|
module.exports = exports = class Channel {
|
|
constructor(opts = {}) {
|
|
const { handle = binding.channelInit(), interfaces = [] } = opts;
|
|
this.handle = handle;
|
|
this.interfaces = interfaces;
|
|
}
|
|
connect() {
|
|
return new Port(this);
|
|
}
|
|
static from(handle, opts = {}) {
|
|
return new Channel({ ...opts, handle });
|
|
}
|
|
};
|
|
var Port = class extends EventEmitter {
|
|
constructor(channel) {
|
|
super();
|
|
this._channel = channel;
|
|
this._state = 0;
|
|
this._queue = new Queue();
|
|
this._backpressured = false;
|
|
this._drain = null;
|
|
this._flush = null;
|
|
this._end = null;
|
|
this._remoteend = null;
|
|
this._close = null;
|
|
this._id = binding.portInit(
|
|
channel.handle,
|
|
this,
|
|
this._ondrain,
|
|
this._onflush,
|
|
this._onend,
|
|
this._onremoteend,
|
|
this._onclose
|
|
);
|
|
}
|
|
async read() {
|
|
while (this._flush !== null) await this._flush.promise;
|
|
while (true) {
|
|
if (this._backpressured) this._onflush();
|
|
if (this._queue.length > 0) return this._queue.shift();
|
|
if (this._state & REMOTE_ENDED) return null;
|
|
this._flush = Promise.withResolvers();
|
|
await this._flush.promise;
|
|
}
|
|
}
|
|
readSync() {
|
|
while (true) {
|
|
if (this._queue.length > 0) return this._queue.shift();
|
|
if (this._state & REMOTE_ENDED) return null;
|
|
binding.portWaitFlush(this._channel.handle, this._id);
|
|
this._onflush();
|
|
}
|
|
}
|
|
async write(value, opts = {}) {
|
|
if (value === null) return false;
|
|
while (this._drain !== null) await this._drain.promise;
|
|
if (this._close !== null) return false;
|
|
const data = encode(this._channel, value, opts);
|
|
while (true) {
|
|
if (this._state & REMOTE_ENDED) return false;
|
|
const flushed = binding.portWrite(this._channel.handle, this._id, data);
|
|
if (flushed) return true;
|
|
this._drain = Promise.withResolvers();
|
|
await this._drain.promise;
|
|
}
|
|
}
|
|
writeSync(value, opts = {}) {
|
|
if (value === null) return false;
|
|
const data = encode(this._channel, value, opts);
|
|
while (true) {
|
|
if (this._state & REMOTE_ENDED) return false;
|
|
const flushed = binding.portWrite(this._channel.handle, this._id, data);
|
|
if (flushed) return true;
|
|
binding.portWaitDrain(this._channel.handle, this._id);
|
|
}
|
|
}
|
|
createReadStream(opts) {
|
|
return new PortReadStream(this, opts);
|
|
}
|
|
createWriteStream(opts) {
|
|
return new PortWriteStream(this, opts);
|
|
}
|
|
createStream(opts) {
|
|
return new PortDuplexStream(this, opts);
|
|
}
|
|
async close() {
|
|
while (this._drain !== null) await this._drain.promise;
|
|
if (this._close !== null) return this._close.promise;
|
|
this._state |= ENDED;
|
|
this._close = Promise.withResolvers();
|
|
while (true) {
|
|
const flushed = binding.portEnd(this._channel.handle, this._id);
|
|
if (flushed) break;
|
|
this._drain = Promise.withResolvers();
|
|
await this._drain.promise;
|
|
}
|
|
if (this._end === null) this._end = Promise.withResolvers();
|
|
if (this._remoteend === null) this._remoteend = Promise.withResolvers();
|
|
await this._end.promise;
|
|
await this._remoteend.promise;
|
|
binding.portClose(this._channel.handle, this._id);
|
|
await this._close.promise;
|
|
}
|
|
ref() {
|
|
if (this._close !== null) return;
|
|
binding.portRef(this._channel.handle, this._id);
|
|
}
|
|
unref() {
|
|
if (this._close !== null) return;
|
|
binding.portUnref(this._channel.handle, this._id);
|
|
}
|
|
*[Symbol.iterator]() {
|
|
while (true) {
|
|
const data = this.readSync();
|
|
if (data === null) break;
|
|
yield data;
|
|
}
|
|
}
|
|
async *[Symbol.asyncIterator]() {
|
|
while (true) {
|
|
const data = await this.read();
|
|
if (data === null) break;
|
|
yield data;
|
|
}
|
|
}
|
|
_ondrain() {
|
|
if (this._drain === null) return;
|
|
const draining = this._drain;
|
|
this._drain = null;
|
|
draining.resolve();
|
|
}
|
|
_onflush() {
|
|
while (this._queue.length < this._queue.capacity) {
|
|
const data = binding.portRead(this._channel.handle, this._id);
|
|
if (data === null) break;
|
|
this._queue.push(decode(this._channel, data));
|
|
}
|
|
this._backpressured = this._queue.length === this._queue.capacity;
|
|
if (this._flush === null) return;
|
|
const flushing = this._flush;
|
|
this._flush = null;
|
|
flushing.resolve();
|
|
}
|
|
_onend() {
|
|
if (this._end === null) this._end = Promise.withResolvers();
|
|
this._state |= ENDED;
|
|
this._end.resolve();
|
|
}
|
|
_onremoteend() {
|
|
if (this._remoteend === null) this._remoteend = Promise.withResolvers();
|
|
this._state |= REMOTE_ENDED;
|
|
this._remoteend.resolve();
|
|
this.close();
|
|
this.emit("end");
|
|
}
|
|
_onclose() {
|
|
if (this._close === null) this._close = Promise.withResolvers();
|
|
this._close.resolve();
|
|
this.emit("close");
|
|
}
|
|
};
|
|
var PortReadStream = class extends Readable {
|
|
constructor(port, opts) {
|
|
super(opts);
|
|
this._port = port;
|
|
}
|
|
async _read() {
|
|
try {
|
|
this.push(await this._port.read());
|
|
} catch (err) {
|
|
this.destroy(err);
|
|
}
|
|
}
|
|
};
|
|
var PortWriteStream = class extends Writable {
|
|
constructor(port, opts) {
|
|
super(opts);
|
|
this._port = port;
|
|
}
|
|
async _write(chunk, encoding, cb) {
|
|
let err = null;
|
|
try {
|
|
await this._port.write(chunk);
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
cb(err);
|
|
}
|
|
async _final(cb) {
|
|
let err = null;
|
|
try {
|
|
await this._port.close();
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
cb(err);
|
|
}
|
|
};
|
|
var PortDuplexStream = class extends Duplex {
|
|
constructor(port, opts) {
|
|
super(opts);
|
|
this._port = port;
|
|
}
|
|
async _read() {
|
|
try {
|
|
this.push(await this._port.read());
|
|
} catch (err) {
|
|
this.destroy(err);
|
|
}
|
|
}
|
|
async _write(chunk, encoding, cb) {
|
|
let err = null;
|
|
try {
|
|
await this._port.write(chunk);
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
cb(err);
|
|
}
|
|
async _final(cb) {
|
|
let err = null;
|
|
try {
|
|
await this._port.close();
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
cb(err);
|
|
}
|
|
};
|
|
function encode(channel, value, opts) {
|
|
const serialized = structuredClone.serializeWithTransfer(value, opts.transfer, channel.interfaces);
|
|
const state = { start: 0, end: 0, buffer: null };
|
|
structuredClone.preencode(state, serialized);
|
|
const data = new ArrayBuffer(state.end);
|
|
state.buffer = Buffer.from(data);
|
|
structuredClone.encode(state, serialized);
|
|
return data;
|
|
}
|
|
function decode(channel, data) {
|
|
const state = {
|
|
start: 0,
|
|
end: data.byteLength,
|
|
buffer: Buffer.from(data)
|
|
};
|
|
return structuredClone.deserializeWithTransfer(structuredClone.decode(state), channel.interfaces);
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../bare-lib-entry-bareChannel.js
|
|
var bare_lib_entry_bareChannel_exports = {};
|
|
__export(bare_lib_entry_bareChannel_exports, {
|
|
default: () => bare_lib_entry_bareChannel_default
|
|
});
|
|
var import_bare_channel = __toESM(require_bare_channel());
|
|
var bare_lib_entry_bareChannel_default = import_bare_channel.default;
|
|
return __toCommonJS(bare_lib_entry_bareChannel_exports);
|
|
})();
|
|
;(function(){var g=globalThis;var s="__bare_os_stdlib__";g[s]=g[s]||{};var e=typeof __bare_os_bundle_exports__!=="undefined"?__bare_os_bundle_exports__:void 0;var v=e!=null&&typeof e==="object"&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e;g[s]["bareChannel"]=v;})();
|