vlt
Version:
The vlt CLI
1,767 lines (1,742 loc) • 170 kB
JavaScript
var global = globalThis;
import {Buffer} from "node:buffer";
import {setTimeout,clearTimeout,setImmediate,clearImmediate,setInterval,clearInterval} from "node:timers";
import {createRequire as _vlt_createRequire} from "node:module";
var require = _vlt_createRequire(import.meta.filename);
import {
RegistryClient
} from "./chunk-OTLTOVZN.js";
import {
Monorepo,
PackageJson,
clone,
pickManifest,
resolve,
revs
} from "./chunk-GTAUGWLW.js";
import {
Spec2 as Spec
} from "./chunk-U5J4TCIV.js";
import {
rimraf
} from "./chunk-KPA4XNCN.js";
import {
Minipass
} from "./chunk-B4MAUXR2.js";
import {
asError,
asPackument,
isIntegrity
} from "./chunk-JBBINXAZ.js";
import {
XDG
} from "./chunk-BA67AKYJ.js";
import {
error
} from "./chunk-KVH5ECIG.js";
// ../../src/tar/src/unpack.ts
import { randomBytes } from "node:crypto";
import { lstat, mkdir, rename, writeFile } from "node:fs/promises";
import { basename as basename2, dirname, parse as parse2, resolve as resolve2 } from "node:path";
// ../../node_modules/.pnpm/tar@7.5.1/node_modules/tar/dist/esm/header.js
import { posix as pathModule } from "node:path";
// ../../node_modules/.pnpm/tar@7.5.1/node_modules/tar/dist/esm/large-numbers.js
var encode = (num, buf) => {
if (!Number.isSafeInteger(num)) {
throw Error("cannot encode number outside of javascript safe integer range");
} else if (num < 0) {
encodeNegative(num, buf);
} else {
encodePositive(num, buf);
}
return buf;
};
var encodePositive = (num, buf) => {
buf[0] = 128;
for (var i = buf.length; i > 1; i--) {
buf[i - 1] = num & 255;
num = Math.floor(num / 256);
}
};
var encodeNegative = (num, buf) => {
buf[0] = 255;
var flipped = false;
num = num * -1;
for (var i = buf.length; i > 1; i--) {
var byte = num & 255;
num = Math.floor(num / 256);
if (flipped) {
buf[i - 1] = onesComp(byte);
} else if (byte === 0) {
buf[i - 1] = 0;
} else {
flipped = true;
buf[i - 1] = twosComp(byte);
}
}
};
var parse = (buf) => {
const pre = buf[0];
const value = pre === 128 ? pos(buf.subarray(1, buf.length)) : pre === 255 ? twos(buf) : null;
if (value === null) {
throw Error("invalid base256 encoding");
}
if (!Number.isSafeInteger(value)) {
throw Error("parsed number outside of javascript safe integer range");
}
return value;
};
var twos = (buf) => {
var len = buf.length;
var sum = 0;
var flipped = false;
for (var i = len - 1; i > -1; i--) {
var byte = Number(buf[i]);
var f;
if (flipped) {
f = onesComp(byte);
} else if (byte === 0) {
f = byte;
} else {
flipped = true;
f = twosComp(byte);
}
if (f !== 0) {
sum -= f * Math.pow(256, len - i - 1);
}
}
return sum;
};
var pos = (buf) => {
var len = buf.length;
var sum = 0;
for (var i = len - 1; i > -1; i--) {
var byte = Number(buf[i]);
if (byte !== 0) {
sum += byte * Math.pow(256, len - i - 1);
}
}
return sum;
};
var onesComp = (byte) => (255 ^ byte) & 255;
var twosComp = (byte) => (255 ^ byte) + 1 & 255;
// ../../node_modules/.pnpm/tar@7.5.1/node_modules/tar/dist/esm/types.js
var isCode = (c) => name.has(c);
var name = /* @__PURE__ */ new Map([
["0", "File"],
// same as File
["", "OldFile"],
["1", "Link"],
["2", "SymbolicLink"],
// Devices and FIFOs aren't fully supported
// they are parsed, but skipped when unpacking
["3", "CharacterDevice"],
["4", "BlockDevice"],
["5", "Directory"],
["6", "FIFO"],
// same as File
["7", "ContiguousFile"],
// pax headers
["g", "GlobalExtendedHeader"],
["x", "ExtendedHeader"],
// vendor-specific stuff
// skip
["A", "SolarisACL"],
// like 5, but with data, which should be skipped
["D", "GNUDumpDir"],
// metadata only, skip
["I", "Inode"],
// data = link path of next file
["K", "NextFileHasLongLinkpath"],
// data = path of next file
["L", "NextFileHasLongPath"],
// skip
["M", "ContinuationFile"],
// like L
["N", "OldGnuLongPath"],
// skip
["S", "SparseFile"],
// skip
["V", "TapeVolumeHeader"],
// like x
["X", "OldExtendedHeader"]
]);
var code = new Map(Array.from(name).map((kv) => [kv[1], kv[0]]));
// ../../node_modules/.pnpm/tar@7.5.1/node_modules/tar/dist/esm/header.js
var Header = class {
cksumValid = false;
needPax = false;
nullBlock = false;
block;
path;
mode;
uid;
gid;
size;
cksum;
#type = "Unsupported";
linkpath;
uname;
gname;
devmaj = 0;
devmin = 0;
atime;
ctime;
mtime;
charset;
comment;
constructor(data, off = 0, ex, gex) {
if (Buffer.isBuffer(data)) {
this.decode(data, off || 0, ex, gex);
} else if (data) {
this.#slurp(data);
}
}
decode(buf, off, ex, gex) {
if (!off) {
off = 0;
}
if (!buf || !(buf.length >= off + 512)) {
throw new Error("need 512 bytes for header");
}
this.path = decString(buf, off, 100);
this.mode = decNumber(buf, off + 100, 8);
this.uid = decNumber(buf, off + 108, 8);
this.gid = decNumber(buf, off + 116, 8);
this.size = decNumber(buf, off + 124, 12);
this.mtime = decDate(buf, off + 136, 12);
this.cksum = decNumber(buf, off + 148, 12);
if (gex)
this.#slurp(gex, true);
if (ex)
this.#slurp(ex);
const t = decString(buf, off + 156, 1);
if (isCode(t)) {
this.#type = t || "0";
}
if (this.#type === "0" && this.path.slice(-1) === "/") {
this.#type = "5";
}
if (this.#type === "5") {
this.size = 0;
}
this.linkpath = decString(buf, off + 157, 100);
if (buf.subarray(off + 257, off + 265).toString() === "ustar\x0000") {
this.uname = decString(buf, off + 265, 32);
this.gname = decString(buf, off + 297, 32);
this.devmaj = decNumber(buf, off + 329, 8) ?? 0;
this.devmin = decNumber(buf, off + 337, 8) ?? 0;
if (buf[off + 475] !== 0) {
const prefix = decString(buf, off + 345, 155);
this.path = prefix + "/" + this.path;
} else {
const prefix = decString(buf, off + 345, 130);
if (prefix) {
this.path = prefix + "/" + this.path;
}
this.atime = decDate(buf, off + 476, 12);
this.ctime = decDate(buf, off + 488, 12);
}
}
let sum = 8 * 32;
for (let i = off; i < off + 148; i++) {
sum += buf[i];
}
for (let i = off + 156; i < off + 512; i++) {
sum += buf[i];
}
this.cksumValid = sum === this.cksum;
if (this.cksum === void 0 && sum === 8 * 32) {
this.nullBlock = true;
}
}
#slurp(ex, gex = false) {
Object.assign(this, Object.fromEntries(Object.entries(ex).filter(([k, v]) => {
return !(v === null || v === void 0 || k === "path" && gex || k === "linkpath" && gex || k === "global");
})));
}
encode(buf, off = 0) {
if (!buf) {
buf = this.block = Buffer.alloc(512);
}
if (this.#type === "Unsupported") {
this.#type = "0";
}
if (!(buf.length >= off + 512)) {
throw new Error("need 512 bytes for header");
}
const prefixSize = this.ctime || this.atime ? 130 : 155;
const split = splitPrefix(this.path || "", prefixSize);
const path8 = split[0];
const prefix = split[1];
this.needPax = !!split[2];
this.needPax = encString(buf, off, 100, path8) || this.needPax;
this.needPax = encNumber(buf, off + 100, 8, this.mode) || this.needPax;
this.needPax = encNumber(buf, off + 108, 8, this.uid) || this.needPax;
this.needPax = encNumber(buf, off + 116, 8, this.gid) || this.needPax;
this.needPax = encNumber(buf, off + 124, 12, this.size) || this.needPax;
this.needPax = encDate(buf, off + 136, 12, this.mtime) || this.needPax;
buf[off + 156] = this.#type.charCodeAt(0);
this.needPax = encString(buf, off + 157, 100, this.linkpath) || this.needPax;
buf.write("ustar\x0000", off + 257, 8);
this.needPax = encString(buf, off + 265, 32, this.uname) || this.needPax;
this.needPax = encString(buf, off + 297, 32, this.gname) || this.needPax;
this.needPax = encNumber(buf, off + 329, 8, this.devmaj) || this.needPax;
this.needPax = encNumber(buf, off + 337, 8, this.devmin) || this.needPax;
this.needPax = encString(buf, off + 345, prefixSize, prefix) || this.needPax;
if (buf[off + 475] !== 0) {
this.needPax = encString(buf, off + 345, 155, prefix) || this.needPax;
} else {
this.needPax = encString(buf, off + 345, 130, prefix) || this.needPax;
this.needPax = encDate(buf, off + 476, 12, this.atime) || this.needPax;
this.needPax = encDate(buf, off + 488, 12, this.ctime) || this.needPax;
}
let sum = 8 * 32;
for (let i = off; i < off + 148; i++) {
sum += buf[i];
}
for (let i = off + 156; i < off + 512; i++) {
sum += buf[i];
}
this.cksum = sum;
encNumber(buf, off + 148, 8, this.cksum);
this.cksumValid = true;
return this.needPax;
}
get type() {
return this.#type === "Unsupported" ? this.#type : name.get(this.#type);
}
get typeKey() {
return this.#type;
}
set type(type) {
const c = String(code.get(type));
if (isCode(c) || c === "Unsupported") {
this.#type = c;
} else if (isCode(type)) {
this.#type = type;
} else {
throw new TypeError("invalid entry type: " + type);
}
}
};
var splitPrefix = (p, prefixSize) => {
const pathSize = 100;
let pp = p;
let prefix = "";
let ret = void 0;
const root = pathModule.parse(p).root || ".";
if (Buffer.byteLength(pp) < pathSize) {
ret = [pp, prefix, false];
} else {
prefix = pathModule.dirname(pp);
pp = pathModule.basename(pp);
do {
if (Buffer.byteLength(pp) <= pathSize && Buffer.byteLength(prefix) <= prefixSize) {
ret = [pp, prefix, false];
} else if (Buffer.byteLength(pp) > pathSize && Buffer.byteLength(prefix) <= prefixSize) {
ret = [pp.slice(0, pathSize - 1), prefix, true];
} else {
pp = pathModule.join(pathModule.basename(prefix), pp);
prefix = pathModule.dirname(prefix);
}
} while (prefix !== root && ret === void 0);
if (!ret) {
ret = [p.slice(0, pathSize - 1), "", true];
}
}
return ret;
};
var decString = (buf, off, size) => buf.subarray(off, off + size).toString("utf8").replace(/\0.*/, "");
var decDate = (buf, off, size) => numToDate(decNumber(buf, off, size));
var numToDate = (num) => num === void 0 ? void 0 : new Date(num * 1e3);
var decNumber = (buf, off, size) => Number(buf[off]) & 128 ? parse(buf.subarray(off, off + size)) : decSmallNumber(buf, off, size);
var nanUndef = (value) => isNaN(value) ? void 0 : value;
var decSmallNumber = (buf, off, size) => nanUndef(parseInt(buf.subarray(off, off + size).toString("utf8").replace(/\0.*$/, "").trim(), 8));
var MAXNUM = {
12: 8589934591,
8: 2097151
};
var encNumber = (buf, off, size, num) => num === void 0 ? false : num > MAXNUM[size] || num < 0 ? (encode(num, buf.subarray(off, off + size)), true) : (encSmallNumber(buf, off, size, num), false);
var encSmallNumber = (buf, off, size, num) => buf.write(octalString(num, size), off, size, "ascii");
var octalString = (num, size) => padOctal(Math.floor(num).toString(8), size);
var padOctal = (str, size) => (str.length === size - 1 ? str : new Array(size - str.length - 1).join("0") + str + " ") + "\0";
var encDate = (buf, off, size, date) => date === void 0 ? false : encNumber(buf, off, size, date.getTime() / 1e3);
var NULLS = new Array(156).join("\0");
var encString = (buf, off, size, str) => str === void 0 ? false : (buf.write(str + NULLS, off, size, "utf8"), str.length !== Buffer.byteLength(str) || str.length > size);
// ../../node_modules/.pnpm/tar@7.5.1/node_modules/tar/dist/esm/pax.js
import { basename } from "node:path";
var Pax = class _Pax {
atime;
mtime;
ctime;
charset;
comment;
gid;
uid;
gname;
uname;
linkpath;
dev;
ino;
nlink;
path;
size;
mode;
global;
constructor(obj, global = false) {
this.atime = obj.atime;
this.charset = obj.charset;
this.comment = obj.comment;
this.ctime = obj.ctime;
this.dev = obj.dev;
this.gid = obj.gid;
this.global = global;
this.gname = obj.gname;
this.ino = obj.ino;
this.linkpath = obj.linkpath;
this.mtime = obj.mtime;
this.nlink = obj.nlink;
this.path = obj.path;
this.size = obj.size;
this.uid = obj.uid;
this.uname = obj.uname;
}
encode() {
const body = this.encodeBody();
if (body === "") {
return Buffer.allocUnsafe(0);
}
const bodyLen = Buffer.byteLength(body);
const bufLen = 512 * Math.ceil(1 + bodyLen / 512);
const buf = Buffer.allocUnsafe(bufLen);
for (let i = 0; i < 512; i++) {
buf[i] = 0;
}
new Header({
// XXX split the path
// then the path should be PaxHeader + basename, but less than 99,
// prepend with the dirname
/* c8 ignore start */
path: ("PaxHeader/" + basename(this.path ?? "")).slice(0, 99),
/* c8 ignore stop */
mode: this.mode || 420,
uid: this.uid,
gid: this.gid,
size: bodyLen,
mtime: this.mtime,
type: this.global ? "GlobalExtendedHeader" : "ExtendedHeader",
linkpath: "",
uname: this.uname || "",
gname: this.gname || "",
devmaj: 0,
devmin: 0,
atime: this.atime,
ctime: this.ctime
}).encode(buf);
buf.write(body, 512, bodyLen, "utf8");
for (let i = bodyLen + 512; i < buf.length; i++) {
buf[i] = 0;
}
return buf;
}
encodeBody() {
return this.encodeField("path") + this.encodeField("ctime") + this.encodeField("atime") + this.encodeField("dev") + this.encodeField("ino") + this.encodeField("nlink") + this.encodeField("charset") + this.encodeField("comment") + this.encodeField("gid") + this.encodeField("gname") + this.encodeField("linkpath") + this.encodeField("mtime") + this.encodeField("size") + this.encodeField("uid") + this.encodeField("uname");
}
encodeField(field) {
if (this[field] === void 0) {
return "";
}
const r = this[field];
const v = r instanceof Date ? r.getTime() / 1e3 : r;
const s = " " + (field === "dev" || field === "ino" || field === "nlink" ? "SCHILY." : "") + field + "=" + v + "\n";
const byteLen = Buffer.byteLength(s);
let digits = Math.floor(Math.log(byteLen) / Math.log(10)) + 1;
if (byteLen + digits >= Math.pow(10, digits)) {
digits += 1;
}
const len = digits + byteLen;
return len + s;
}
static parse(str, ex, g = false) {
return new _Pax(merge(parseKV(str), ex), g);
}
};
var merge = (a, b) => b ? Object.assign({}, b, a) : a;
var parseKV = (str) => str.replace(/\n$/, "").split("\n").reduce(parseKVLine, /* @__PURE__ */ Object.create(null));
var parseKVLine = (set, line) => {
const n = parseInt(line, 10);
if (n !== Buffer.byteLength(line) + 1) {
return set;
}
line = line.slice((n + " ").length);
const kv = line.split("=");
const r = kv.shift();
if (!r) {
return set;
}
const k = r.replace(/^SCHILY\.(dev|ino|nlink)/, "$1");
const v = kv.join("=");
set[k] = /^([A-Z]+\.)?([mac]|birth|creation)time$/.test(k) ? new Date(Number(v) * 1e3) : /^[0-9]+$/.test(v) ? +v : v;
return set;
};
// ../../src/tar/src/unpack.ts
import { unzip as unzipCB } from "node:zlib";
// ../../src/tar/src/find-tar-dir.ts
var findTarDir = (path8, tarDir) => {
if (tarDir !== void 0) return tarDir;
if (!path8) return void 0;
const i = path8.indexOf("/", path8.startsWith("./") ? 2 : 0);
if (i === -1) return void 0;
const chomp = path8.substring(0, i);
if (chomp === "." || chomp === ".." || chomp === "" || chomp === "./." || chomp === "./.." || chomp === "./") {
return void 0;
}
return chomp + "/";
};
// ../../src/tar/src/unpack.ts
var unzip = async (input) => new Promise(
(res, rej) => (
/* c8 ignore start */
unzipCB(input, (er, result) => er ? rej(er) : res(result))
)
/* c8 ignore stop */
);
var exists = async (path8) => {
try {
await lstat(path8);
return true;
} catch {
return false;
}
};
var id = 1;
var tmp = randomBytes(6).toString("hex") + ".";
var tmpSuffix = () => tmp + String(id++);
var checkFs = (h, tarDir) => {
if (!h.path) return false;
if (!tarDir) return false;
h.path = h.path.replace(/[\\/]+/g, "/");
const parsed = parse2(h.path);
if (parsed.root) return false;
const p = h.path.replace(/\\/, "/");
if (/(\/|)^\.\.(\/|$)/.test(p)) return false;
if (!p.startsWith(tarDir)) return false;
return true;
};
var write = async (path8, body, executable = false) => {
await mkdirp(dirname(path8));
await writeFile(path8, body, {
mode: executable ? 511 : 438
});
};
var made = /* @__PURE__ */ new Set();
var making = /* @__PURE__ */ new Map();
var mkdirp = async (d) => {
if (!made.has(d)) {
const m = making.get(d) ?? mkdir(d, { recursive: true, mode: 511 }).then(
() => making.delete(d)
);
making.set(d, m);
await m;
made.add(d);
}
};
var unpack = async (tarData, target) => {
const isGzip = tarData[0] === 31 && tarData[1] === 139;
await unpackUnzipped(
isGzip ? await unzip(tarData) : tarData,
target
);
};
var unpackUnzipped = async (buffer, target) => {
const isGzip = buffer[0] === 31 && buffer[1] === 139;
if (isGzip) {
throw error("still gzipped after unzipping", {
found: isGzip,
wanted: false
});
}
if (buffer.length % 512 !== 0) {
throw error("Invalid tarball: length not divisible by 512", {
found: buffer.length
});
}
if (buffer.length < 1024) {
throw error(
"Invalid tarball: not terminated by 1024 null bytes",
{ found: buffer.length }
);
}
for (let i = buffer.length - 1024; i < buffer.length; i++) {
if (buffer[i] !== 0) {
throw error(
"Invalid tarball: not terminated by 1024 null bytes",
{ found: buffer.subarray(i, i + 10) }
);
}
}
const tmp2 = dirname(target) + "/." + basename2(target) + "." + tmpSuffix();
const og = tmp2 + ".ORIGINAL";
await Promise.all([rimraf(tmp2), rimraf(og)]);
let succeeded = false;
try {
let tarDir = void 0;
let offset = 0;
let h;
let ex = void 0;
let gex = void 0;
while (offset < buffer.length && !(h = new Header(buffer, offset, ex, gex)).nullBlock) {
offset += 512;
ex = void 0;
gex = void 0;
const size = h.size ?? 0;
const body = buffer.subarray(offset, offset + size);
if (!h.cksumValid) continue;
offset += 512 * Math.ceil(size / 512);
switch (h.type) {
case "File":
if (!tarDir) tarDir = findTarDir(h.path, tarDir);
if (!tarDir) continue;
if (!checkFs(h, tarDir)) continue;
await write(
resolve2(tmp2, h.path.substring(tarDir.length)),
body,
// if it's world-executable, it's an executable
// otherwise, make it read-only.
1 === ((h.mode ?? 1638) & 1)
);
break;
case "Directory":
if (!tarDir) tarDir = findTarDir(h.path, tarDir);
if (!tarDir) continue;
if (!checkFs(h, tarDir)) continue;
await mkdirp(resolve2(tmp2, h.path.substring(tarDir.length)));
break;
case "GlobalExtendedHeader":
gex = Pax.parse(body.toString(), gex, true);
break;
case "ExtendedHeader":
case "OldExtendedHeader":
ex = Pax.parse(body.toString(), ex, false);
break;
case "NextFileHasLongPath":
case "OldGnuLongPath":
ex ??= /* @__PURE__ */ Object.create(null);
ex.path = body.toString().replace(/\0.*/, "");
break;
}
}
const targetExists = await exists(target);
if (targetExists) await rename(target, og);
await rename(tmp2, target);
if (targetExists) await rimraf(og);
succeeded = true;
} finally {
if (!succeeded) {
if (await exists(og)) {
await rimraf(target);
await rename(og, target);
}
await rimraf(tmp2);
}
}
};
// ../../src/tar/src/pool.ts
import os from "node:os";
// ../../src/tar/src/unpack-request.ts
var ID = 1;
var UnpackRequest = class {
id = ID++;
tarData;
target;
resolve;
reject;
promise = new Promise((res, rej) => {
this.resolve = res;
this.reject = rej;
});
constructor(tarData, target) {
this.tarData = tarData;
this.target = target;
}
};
// ../../src/tar/src/worker.ts
var isObj = (o) => !!o && typeof o === "object";
var isResponseOK = (o) => isObj(o) && typeof o.id === "number" && o.ok === true;
var Worker = class {
onMessage;
constructor(onMessage) {
this.onMessage = onMessage;
}
async process(req) {
const { target, tarData, id: id2 } = req;
try {
await unpack(tarData, target);
const m = { id: id2, ok: true };
this.onMessage(m);
} catch (error2) {
const m = { id: id2, error: error2 };
this.onMessage(m);
}
}
};
// ../../src/tar/src/pool.ts
var Pool = class {
/**
* Number of workers to emplly. Defaults to 1 less than the number of
* CPUs, or 1.
*/
/* c8 ignore next */
jobs = 8 * (Math.max(os.availableParallelism(), 2) - 1);
/**
* Set of currently active worker threads
*/
workers = /* @__PURE__ */ new Set();
/**
* Queue of requests awaiting an available worker
*/
queue = [];
/**
* Requests that have been assigned to a worker, but have not yet
* been confirmed completed.
*/
pending = /* @__PURE__ */ new Map();
// handle a message from the worker
#onMessage(w, m) {
const { id: id2 } = m;
const ur = this.pending.get(id2);
if (!ur) return;
if (isResponseOK(m)) {
ur.resolve();
} else {
ur.reject(
error(
asError(m.error, "failed without error message").message,
{
found: m,
cause: m.error
}
)
);
}
const next = this.queue.shift();
if (!next) {
this.workers.delete(w);
} else {
void w.process(next);
}
}
// create a new worker
#createWorker(req) {
const w = new Worker(
(m) => this.#onMessage(w, m)
);
this.workers.add(w);
void w.process(req);
}
/**
* Provide the tardata to be unpacked, and the location where it's to be
* placed. Will create a new worker up to the `jobs` value, and then start
* pushing in the queue for workers to pick up as they become available.
*
* Returned promise resolves when the provided tarball has been extracted.
*/
async unpack(tarData, target) {
const ur = new UnpackRequest(tarData, target);
this.pending.set(ur.id, ur);
if (this.workers.size < this.jobs) {
this.#createWorker(ur);
} else {
this.queue.push(ur);
}
return ur.promise;
}
};
// ../../src/package-info/src/index.ts
import { randomBytes as randomBytes3 } from "node:crypto";
import {
mkdir as mkdir3,
readFile,
rm as rm2,
stat,
symlink,
unlink,
writeFile as writeFile2
} from "node:fs/promises";
import {
basename as basename3,
dirname as dirname3,
resolve as pathResolve,
relative
} from "node:path";
// ../../node_modules/.pnpm/@isaacs+fs-minipass@4.0.1/node_modules/@isaacs/fs-minipass/dist/esm/index.js
import EE from "node:events";
import fs from "node:fs";
var writev = fs.writev;
var _autoClose = Symbol("_autoClose");
var _close = Symbol("_close");
var _ended = Symbol("_ended");
var _fd = Symbol("_fd");
var _finished = Symbol("_finished");
var _flags = Symbol("_flags");
var _flush = Symbol("_flush");
var _handleChunk = Symbol("_handleChunk");
var _makeBuf = Symbol("_makeBuf");
var _mode = Symbol("_mode");
var _needDrain = Symbol("_needDrain");
var _onerror = Symbol("_onerror");
var _onopen = Symbol("_onopen");
var _onread = Symbol("_onread");
var _onwrite = Symbol("_onwrite");
var _open = Symbol("_open");
var _path = Symbol("_path");
var _pos = Symbol("_pos");
var _queue = Symbol("_queue");
var _read = Symbol("_read");
var _readSize = Symbol("_readSize");
var _reading = Symbol("_reading");
var _remain = Symbol("_remain");
var _size = Symbol("_size");
var _write = Symbol("_write");
var _writing = Symbol("_writing");
var _defaultFlag = Symbol("_defaultFlag");
var _errored = Symbol("_errored");
var ReadStream = class extends Minipass {
[_errored] = false;
[_fd];
[_path];
[_readSize];
[_reading] = false;
[_size];
[_remain];
[_autoClose];
constructor(path8, opt) {
opt = opt || {};
super(opt);
this.readable = true;
this.writable = false;
if (typeof path8 !== "string") {
throw new TypeError("path must be a string");
}
this[_errored] = false;
this[_fd] = typeof opt.fd === "number" ? opt.fd : void 0;
this[_path] = path8;
this[_readSize] = opt.readSize || 16 * 1024 * 1024;
this[_reading] = false;
this[_size] = typeof opt.size === "number" ? opt.size : Infinity;
this[_remain] = this[_size];
this[_autoClose] = typeof opt.autoClose === "boolean" ? opt.autoClose : true;
if (typeof this[_fd] === "number") {
this[_read]();
} else {
this[_open]();
}
}
get fd() {
return this[_fd];
}
get path() {
return this[_path];
}
//@ts-ignore
write() {
throw new TypeError("this is a readable stream");
}
//@ts-ignore
end() {
throw new TypeError("this is a readable stream");
}
[_open]() {
fs.open(this[_path], "r", (er, fd) => this[_onopen](er, fd));
}
[_onopen](er, fd) {
if (er) {
this[_onerror](er);
} else {
this[_fd] = fd;
this.emit("open", fd);
this[_read]();
}
}
[_makeBuf]() {
return Buffer.allocUnsafe(Math.min(this[_readSize], this[_remain]));
}
[_read]() {
if (!this[_reading]) {
this[_reading] = true;
const buf = this[_makeBuf]();
if (buf.length === 0) {
return process.nextTick(() => this[_onread](null, 0, buf));
}
fs.read(this[_fd], buf, 0, buf.length, null, (er, br, b) => this[_onread](er, br, b));
}
}
[_onread](er, br, buf) {
this[_reading] = false;
if (er) {
this[_onerror](er);
} else if (this[_handleChunk](br, buf)) {
this[_read]();
}
}
[_close]() {
if (this[_autoClose] && typeof this[_fd] === "number") {
const fd = this[_fd];
this[_fd] = void 0;
fs.close(fd, (er) => er ? this.emit("error", er) : this.emit("close"));
}
}
[_onerror](er) {
this[_reading] = true;
this[_close]();
this.emit("error", er);
}
[_handleChunk](br, buf) {
let ret = false;
this[_remain] -= br;
if (br > 0) {
ret = super.write(br < buf.length ? buf.subarray(0, br) : buf);
}
if (br === 0 || this[_remain] <= 0) {
ret = false;
this[_close]();
super.end();
}
return ret;
}
emit(ev, ...args) {
switch (ev) {
case "prefinish":
case "finish":
return false;
case "drain":
if (typeof this[_fd] === "number") {
this[_read]();
}
return false;
case "error":
if (this[_errored]) {
return false;
}
this[_errored] = true;
return super.emit(ev, ...args);
default:
return super.emit(ev, ...args);
}
}
};
var ReadStreamSync = class extends ReadStream {
[_open]() {
let threw = true;
try {
this[_onopen](null, fs.openSync(this[_path], "r"));
threw = false;
} finally {
if (threw) {
this[_close]();
}
}
}
[_read]() {
let threw = true;
try {
if (!this[_reading]) {
this[_reading] = true;
do {
const buf = this[_makeBuf]();
const br = buf.length === 0 ? 0 : fs.readSync(this[_fd], buf, 0, buf.length, null);
if (!this[_handleChunk](br, buf)) {
break;
}
} while (true);
this[_reading] = false;
}
threw = false;
} finally {
if (threw) {
this[_close]();
}
}
}
[_close]() {
if (this[_autoClose] && typeof this[_fd] === "number") {
const fd = this[_fd];
this[_fd] = void 0;
fs.closeSync(fd);
this.emit("close");
}
}
};
var WriteStream = class extends EE {
readable = false;
writable = true;
[_errored] = false;
[_writing] = false;
[_ended] = false;
[_queue] = [];
[_needDrain] = false;
[_path];
[_mode];
[_autoClose];
[_fd];
[_defaultFlag];
[_flags];
[_finished] = false;
[_pos];
constructor(path8, opt) {
opt = opt || {};
super(opt);
this[_path] = path8;
this[_fd] = typeof opt.fd === "number" ? opt.fd : void 0;
this[_mode] = opt.mode === void 0 ? 438 : opt.mode;
this[_pos] = typeof opt.start === "number" ? opt.start : void 0;
this[_autoClose] = typeof opt.autoClose === "boolean" ? opt.autoClose : true;
const defaultFlag = this[_pos] !== void 0 ? "r+" : "w";
this[_defaultFlag] = opt.flags === void 0;
this[_flags] = opt.flags === void 0 ? defaultFlag : opt.flags;
if (this[_fd] === void 0) {
this[_open]();
}
}
emit(ev, ...args) {
if (ev === "error") {
if (this[_errored]) {
return false;
}
this[_errored] = true;
}
return super.emit(ev, ...args);
}
get fd() {
return this[_fd];
}
get path() {
return this[_path];
}
[_onerror](er) {
this[_close]();
this[_writing] = true;
this.emit("error", er);
}
[_open]() {
fs.open(this[_path], this[_flags], this[_mode], (er, fd) => this[_onopen](er, fd));
}
[_onopen](er, fd) {
if (this[_defaultFlag] && this[_flags] === "r+" && er && er.code === "ENOENT") {
this[_flags] = "w";
this[_open]();
} else if (er) {
this[_onerror](er);
} else {
this[_fd] = fd;
this.emit("open", fd);
if (!this[_writing]) {
this[_flush]();
}
}
}
end(buf, enc) {
if (buf) {
this.write(buf, enc);
}
this[_ended] = true;
if (!this[_writing] && !this[_queue].length && typeof this[_fd] === "number") {
this[_onwrite](null, 0);
}
return this;
}
write(buf, enc) {
if (typeof buf === "string") {
buf = Buffer.from(buf, enc);
}
if (this[_ended]) {
this.emit("error", new Error("write() after end()"));
return false;
}
if (this[_fd] === void 0 || this[_writing] || this[_queue].length) {
this[_queue].push(buf);
this[_needDrain] = true;
return false;
}
this[_writing] = true;
this[_write](buf);
return true;
}
[_write](buf) {
fs.write(this[_fd], buf, 0, buf.length, this[_pos], (er, bw) => this[_onwrite](er, bw));
}
[_onwrite](er, bw) {
if (er) {
this[_onerror](er);
} else {
if (this[_pos] !== void 0 && typeof bw === "number") {
this[_pos] += bw;
}
if (this[_queue].length) {
this[_flush]();
} else {
this[_writing] = false;
if (this[_ended] && !this[_finished]) {
this[_finished] = true;
this[_close]();
this.emit("finish");
} else if (this[_needDrain]) {
this[_needDrain] = false;
this.emit("drain");
}
}
}
}
[_flush]() {
if (this[_queue].length === 0) {
if (this[_ended]) {
this[_onwrite](null, 0);
}
} else if (this[_queue].length === 1) {
this[_write](this[_queue].pop());
} else {
const iovec = this[_queue];
this[_queue] = [];
writev(this[_fd], iovec, this[_pos], (er, bw) => this[_onwrite](er, bw));
}
}
[_close]() {
if (this[_autoClose] && typeof this[_fd] === "number") {
const fd = this[_fd];
this[_fd] = void 0;
fs.close(fd, (er) => er ? this.emit("error", er) : this.emit("close"));
}
}
};
var WriteStreamSync = class extends WriteStream {
[_open]() {
let fd;
if (this[_defaultFlag] && this[_flags] === "r+") {
try {
fd = fs.openSync(this[_path], this[_flags], this[_mode]);
} catch (er) {
if (er?.code === "ENOENT") {
this[_flags] = "w";
return this[_open]();
} else {
throw er;
}
}
} else {
fd = fs.openSync(this[_path], this[_flags], this[_mode]);
}
this[_onopen](null, fd);
}
[_close]() {
if (this[_autoClose] && typeof this[_fd] === "number") {
const fd = this[_fd];
this[_fd] = void 0;
fs.closeSync(fd);
this.emit("close");
}
}
[_write](buf) {
let threw = true;
try {
this[_onwrite](null, fs.writeSync(this[_fd], buf, 0, buf.length, this[_pos]));
threw = false;
} finally {
if (threw) {
try {
this[_close]();
} catch {
}
}
}
}
};
// ../../node_modules/.pnpm/tar@7.5.1/node_modules/tar/dist/esm/create.js
import path3 from "node:path";
// ../../node_modules/.pnpm/tar@7.5.1/node_modules/tar/dist/esm/list.js
import fs2 from "node:fs";
import { dirname as dirname2, parse as parse3 } from "node:path";
// ../../node_modules/.pnpm/tar@7.5.1/node_modules/tar/dist/esm/options.js
var argmap = /* @__PURE__ */ new Map([
["C", "cwd"],
["f", "file"],
["z", "gzip"],
["P", "preservePaths"],
["U", "unlink"],
["strip-components", "strip"],
["stripComponents", "strip"],
["keep-newer", "newer"],
["keepNewer", "newer"],
["keep-newer-files", "newer"],
["keepNewerFiles", "newer"],
["k", "keep"],
["keep-existing", "keep"],
["keepExisting", "keep"],
["m", "noMtime"],
["no-mtime", "noMtime"],
["p", "preserveOwner"],
["L", "follow"],
["h", "follow"],
["onentry", "onReadEntry"]
]);
var isSyncFile = (o) => !!o.sync && !!o.file;
var isAsyncFile = (o) => !o.sync && !!o.file;
var isSyncNoFile = (o) => !!o.sync && !o.file;
var isAsyncNoFile = (o) => !o.sync && !o.file;
var isFile = (o) => !!o.file;
var dealiasKey = (k) => {
const d = argmap.get(k);
if (d)
return d;
return k;
};
var dealias = (opt = {}) => {
if (!opt)
return {};
const result = {};
for (const [key, v] of Object.entries(opt)) {
const k = dealiasKey(key);
result[k] = v;
}
if (result.chmod === void 0 && result.noChmod === false) {
result.chmod = true;
}
delete result.noChmod;
return result;
};
// ../../node_modules/.pnpm/tar@7.5.1/node_modules/tar/dist/esm/make-command.js
var makeCommand = (syncFile, asyncFile, syncNoFile, asyncNoFile, validate) => {
return Object.assign((opt_ = [], entries, cb) => {
if (Array.isArray(opt_)) {
entries = opt_;
opt_ = {};
}
if (typeof entries === "function") {
cb = entries;
entries = void 0;
}
if (!entries) {
entries = [];
} else {
entries = Array.from(entries);
}
const opt = dealias(opt_);
validate?.(opt, entries);
if (isSyncFile(opt)) {
if (typeof cb === "function") {
throw new TypeError("callback not supported for sync tar functions");
}
return syncFile(opt, entries);
} else if (isAsyncFile(opt)) {
const p = asyncFile(opt, entries);
const c = cb ? cb : void 0;
return c ? p.then(() => c(), c) : p;
} else if (isSyncNoFile(opt)) {
if (typeof cb === "function") {
throw new TypeError("callback not supported for sync tar functions");
}
return syncNoFile(opt, entries);
} else if (isAsyncNoFile(opt)) {
if (typeof cb === "function") {
throw new TypeError("callback only supported with file option");
}
return asyncNoFile(opt, entries);
} else {
throw new Error("impossible options??");
}
}, {
syncFile,
asyncFile,
syncNoFile,
asyncNoFile,
validate
});
};
// ../../node_modules/.pnpm/tar@7.5.1/node_modules/tar/dist/esm/parse.js
import { EventEmitter as EE2 } from "node:events";
// ../../node_modules/.pnpm/minizlib@3.1.0/node_modules/minizlib/dist/esm/index.js
import assert from "node:assert";
import { Buffer as Buffer2 } from "node:buffer";
import * as realZlib2 from "node:zlib";
// ../../node_modules/.pnpm/minizlib@3.1.0/node_modules/minizlib/dist/esm/constants.js
import realZlib from "node:zlib";
var realZlibConstants = realZlib.constants || { ZLIB_VERNUM: 4736 };
var constants = Object.freeze(Object.assign(/* @__PURE__ */ Object.create(null), {
Z_NO_FLUSH: 0,
Z_PARTIAL_FLUSH: 1,
Z_SYNC_FLUSH: 2,
Z_FULL_FLUSH: 3,
Z_FINISH: 4,
Z_BLOCK: 5,
Z_OK: 0,
Z_STREAM_END: 1,
Z_NEED_DICT: 2,
Z_ERRNO: -1,
Z_STREAM_ERROR: -2,
Z_DATA_ERROR: -3,
Z_MEM_ERROR: -4,
Z_BUF_ERROR: -5,
Z_VERSION_ERROR: -6,
Z_NO_COMPRESSION: 0,
Z_BEST_SPEED: 1,
Z_BEST_COMPRESSION: 9,
Z_DEFAULT_COMPRESSION: -1,
Z_FILTERED: 1,
Z_HUFFMAN_ONLY: 2,
Z_RLE: 3,
Z_FIXED: 4,
Z_DEFAULT_STRATEGY: 0,
DEFLATE: 1,
INFLATE: 2,
GZIP: 3,
GUNZIP: 4,
DEFLATERAW: 5,
INFLATERAW: 6,
UNZIP: 7,
BROTLI_DECODE: 8,
BROTLI_ENCODE: 9,
Z_MIN_WINDOWBITS: 8,
Z_MAX_WINDOWBITS: 15,
Z_DEFAULT_WINDOWBITS: 15,
Z_MIN_CHUNK: 64,
Z_MAX_CHUNK: Infinity,
Z_DEFAULT_CHUNK: 16384,
Z_MIN_MEMLEVEL: 1,
Z_MAX_MEMLEVEL: 9,
Z_DEFAULT_MEMLEVEL: 8,
Z_MIN_LEVEL: -1,
Z_MAX_LEVEL: 9,
Z_DEFAULT_LEVEL: -1,
BROTLI_OPERATION_PROCESS: 0,
BROTLI_OPERATION_FLUSH: 1,
BROTLI_OPERATION_FINISH: 2,
BROTLI_OPERATION_EMIT_METADATA: 3,
BROTLI_MODE_GENERIC: 0,
BROTLI_MODE_TEXT: 1,
BROTLI_MODE_FONT: 2,
BROTLI_DEFAULT_MODE: 0,
BROTLI_MIN_QUALITY: 0,
BROTLI_MAX_QUALITY: 11,
BROTLI_DEFAULT_QUALITY: 11,
BROTLI_MIN_WINDOW_BITS: 10,
BROTLI_MAX_WINDOW_BITS: 24,
BROTLI_LARGE_MAX_WINDOW_BITS: 30,
BROTLI_DEFAULT_WINDOW: 22,
BROTLI_MIN_INPUT_BLOCK_BITS: 16,
BROTLI_MAX_INPUT_BLOCK_BITS: 24,
BROTLI_PARAM_MODE: 0,
BROTLI_PARAM_QUALITY: 1,
BROTLI_PARAM_LGWIN: 2,
BROTLI_PARAM_LGBLOCK: 3,
BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING: 4,
BROTLI_PARAM_SIZE_HINT: 5,
BROTLI_PARAM_LARGE_WINDOW: 6,
BROTLI_PARAM_NPOSTFIX: 7,
BROTLI_PARAM_NDIRECT: 8,
BROTLI_DECODER_RESULT_ERROR: 0,
BROTLI_DECODER_RESULT_SUCCESS: 1,
BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT: 2,
BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT: 3,
BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION: 0,
BROTLI_DECODER_PARAM_LARGE_WINDOW: 1,
BROTLI_DECODER_NO_ERROR: 0,
BROTLI_DECODER_SUCCESS: 1,
BROTLI_DECODER_NEEDS_MORE_INPUT: 2,
BROTLI_DECODER_NEEDS_MORE_OUTPUT: 3,
BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE: -1,
BROTLI_DECODER_ERROR_FORMAT_RESERVED: -2,
BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE: -3,
BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET: -4,
BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME: -5,
BROTLI_DECODER_ERROR_FORMAT_CL_SPACE: -6,
BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE: -7,
BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT: -8,
BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1: -9,
BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2: -10,
BROTLI_DECODER_ERROR_FORMAT_TRANSFORM: -11,
BROTLI_DECODER_ERROR_FORMAT_DICTIONARY: -12,
BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS: -13,
BROTLI_DECODER_ERROR_FORMAT_PADDING_1: -14,
BROTLI_DECODER_ERROR_FORMAT_PADDING_2: -15,
BROTLI_DECODER_ERROR_FORMAT_DISTANCE: -16,
BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET: -19,
BROTLI_DECODER_ERROR_INVALID_ARGUMENTS: -20,
BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES: -21,
BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS: -22,
BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP: -25,
BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1: -26,
BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2: -27,
BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES: -30,
BROTLI_DECODER_ERROR_UNREACHABLE: -31
}, realZlibConstants));
// ../../node_modules/.pnpm/minizlib@3.1.0/node_modules/minizlib/dist/esm/index.js
var OriginalBufferConcat = Buffer2.concat;
var desc = Object.getOwnPropertyDescriptor(Buffer2, "concat");
var noop = (args) => args;
var passthroughBufferConcat = desc?.writable === true || desc?.set !== void 0 ? (makeNoOp) => {
Buffer2.concat = makeNoOp ? noop : OriginalBufferConcat;
} : (_) => {
};
var _superWrite = Symbol("_superWrite");
var ZlibError = class extends Error {
code;
errno;
constructor(err, origin) {
super("zlib: " + err.message, { cause: err });
this.code = err.code;
this.errno = err.errno;
if (!this.code)
this.code = "ZLIB_ERROR";
this.message = "zlib: " + err.message;
Error.captureStackTrace(this, origin ?? this.constructor);
}
get name() {
return "ZlibError";
}
};
var _flushFlag = Symbol("flushFlag");
var ZlibBase = class extends Minipass {
#sawError = false;
#ended = false;
#flushFlag;
#finishFlushFlag;
#fullFlushFlag;
#handle;
#onError;
get sawError() {
return this.#sawError;
}
get handle() {
return this.#handle;
}
/* c8 ignore start */
get flushFlag() {
return this.#flushFlag;
}
/* c8 ignore stop */
constructor(opts, mode) {
if (!opts || typeof opts !== "object")
throw new TypeError("invalid options for ZlibBase constructor");
super(opts);
this.#flushFlag = opts.flush ?? 0;
this.#finishFlushFlag = opts.finishFlush ?? 0;
this.#fullFlushFlag = opts.fullFlushFlag ?? 0;
if (typeof realZlib2[mode] !== "function") {
throw new TypeError("Compression method not supported: " + mode);
}
try {
this.#handle = new realZlib2[mode](opts);
} catch (er) {
throw new ZlibError(er, this.constructor);
}
this.#onError = (err) => {
if (this.#sawError)
return;
this.#sawError = true;
this.close();
this.emit("error", err);
};
this.#handle?.on("error", (er) => this.#onError(new ZlibError(er)));
this.once("end", () => this.close);
}
close() {
if (this.#handle) {
this.#handle.close();
this.#handle = void 0;
this.emit("close");
}
}
reset() {
if (!this.#sawError) {
assert(this.#handle, "zlib binding closed");
return this.#handle.reset?.();
}
}
flush(flushFlag) {
if (this.ended)
return;
if (typeof flushFlag !== "number")
flushFlag = this.#fullFlushFlag;
this.write(Object.assign(Buffer2.alloc(0), { [_flushFlag]: flushFlag }));
}
end(chunk, encoding, cb) {
if (typeof chunk === "function") {
cb = chunk;
encoding = void 0;
chunk = void 0;
}
if (typeof encoding === "function") {
cb = encoding;
encoding = void 0;
}
if (chunk) {
if (encoding)
this.write(chunk, encoding);
else
this.write(chunk);
}
this.flush(this.#finishFlushFlag);
this.#ended = true;
return super.end(cb);
}
get ended() {
return this.#ended;
}
// overridden in the gzip classes to do portable writes
[_superWrite](data) {
return super.write(data);
}
write(chunk, encoding, cb) {
if (typeof encoding === "function")
cb = encoding, encoding = "utf8";
if (typeof chunk === "string")
chunk = Buffer2.from(chunk, encoding);
if (this.#sawError)
return;
assert(this.#handle, "zlib binding closed");
const nativeHandle = this.#handle._handle;
const originalNativeClose = nativeHandle.close;
nativeHandle.close = () => {
};
const originalClose = this.#handle.close;
this.#handle.close = () => {
};
passthroughBufferConcat(true);
let result = void 0;
try {
const flushFlag = typeof chunk[_flushFlag] === "number" ? chunk[_flushFlag] : this.#flushFlag;
result = this.#handle._processChunk(chunk, flushFlag);
passthroughBufferConcat(false);
} catch (err) {
passthroughBufferConcat(false);
this.#onError(new ZlibError(err, this.write));
} finally {
if (this.#handle) {
;
this.#handle._handle = nativeHandle;
nativeHandle.close = originalNativeClose;
this.#handle.close = originalClose;
this.#handle.removeAllListeners("error");
}
}
if (this.#handle)
this.#handle.on("error", (er) => this.#onError(new ZlibError(er, this.write)));
let writeReturn;
if (result) {
if (Array.isArray(result) && result.length > 0) {
const r = result[0];
writeReturn = this[_superWrite](Buffer2.from(r));
for (let i = 1; i < result.length; i++) {
writeReturn = this[_superWrite](result[i]);
}
} else {
writeReturn = this[_superWrite](Buffer2.from(result));
}
}
if (cb)
cb();
return writeReturn;
}
};
var Zlib = class extends ZlibBase {
#level;
#strategy;
constructor(opts, mode) {
opts = opts || {};
opts.flush = opts.flush || constants.Z_NO_FLUSH;
opts.finishFlush = opts.finishFlush || constants.Z_FINISH;
opts.fullFlushFlag = constants.Z_FULL_FLUSH;
super(opts, mode);
this.#level = opts.level;
this.#strategy = opts.strategy;
}
params(level, strategy) {
if (this.sawError)
return;
if (!this.handle)
throw new Error("cannot switch params when binding is closed");
if (!this.handle.params)
throw new Error("not supported in this implementation");
if (this.#level !== level || this.#strategy !== strategy) {
this.flush(constants.Z_SYNC_FLUSH);
assert(this.handle, "zlib binding closed");
const origFlush = this.handle.flush;
this.handle.flush = (flushFlag, cb) => {
if (typeof flushFlag === "function") {
cb = flushFlag;
flushFlag = this.flushFlag;
}
this.flush(flushFlag);
cb?.();
};
try {
;
this.handle.params(level, strategy);
} finally {
this.handle.flush = origFlush;
}
if (this.handle) {
this.#level = level;
this.#strategy = strategy;
}
}
}
};
var Gzip = class extends Zlib {
#portable;
constructor(opts) {
super(opts, "Gzip");
this.#portable = opts && !!opts.portable;
}
[_superWrite](data) {
if (!this.#portable)
return super[_superWrite](data);
this.#portable = false;
data[9] = 255;
return super[_superWrite](data);
}
};
var Unzip = class extends Zlib {
constructor(opts) {
super(opts, "Unzip");
}
};
var Brotli = class extends ZlibBase {
constructor(opts, mode) {
opts = opts || {};
opts.flush = opts.flush || constants.BROTLI_OPERATION_PROCESS;
opts.finishFlush = opts.finishFlush || constants.BROTLI_OPERATION_FINISH;
opts.fullFlushFlag = constants.BROTLI_OPERATION_FLUSH;
super(opts, mode);
}
};
var BrotliCompress = class extends Brotli {
constructor(opts) {
super(opts, "BrotliCompress");
}
};
var BrotliDecompress = class extends Brotli {
constructor(opts) {
super(opts, "BrotliDecompress");
}
};
var Zstd = class extends ZlibBase {
constructor(opts, mode) {
opts = opts || {};
opts.flush = opts.flush || constants.ZSTD_e_continue;
opts.finishFlush = opts.finishFlush || constants.ZSTD_e_end;
opts.fullFlushFlag = constants.ZSTD_e_flush;
super(opts, mode);
}
};
var ZstdCompress = class extends Zstd {
constructor(opts) {
super(opts, "ZstdCompress");
}
};
var ZstdDecompress = class extends Zstd {
constructor(opts) {
super(opts, "ZstdDecompress");
}
};
// ../../node_modules/.pnpm/tar@7.5.1/node_modules/tar/dist/esm/normalize-windows-path.js
var platform = process.env.TESTING_TAR_FAKE_PLATFORM || process.platform;
var normalizeWindowsPath = platform !== "win32" ? (p) => p : (p) => p && p.replace(/\\/g, "/");
// ../../node_modules/.pnpm/tar@7.5.1/node_modules/tar/dist/esm/read-entry.js
var ReadEntry = class extends Minipass {
extended;
globalExtended;
header;
startBlockSize;
blockRemain;
remain;
type;
meta = false;
ignore = false;
path;
mode;
uid;
gid;
uname;
gname;
size = 0;
mtime;
atime;
ctime;
linkpath;
dev;
ino;
nlink;
invalid = false;
absolute;
unsupported = false;
constructor(header, ex, gex) {
super({});
this.pause();
this.extended = ex;
this.globalExtended = gex;
this.header = header;
this.remain = header.size ?? 0;
this.startBlockSize = 512 * Math.ceil(this.remain / 512);
this.blockRemain = this.startBlockSize;
this.type = header.type;
switch (this.type) {
case "File":
case "OldFile":
case "Link":
case "SymbolicLink":
case "CharacterDevice":
case "BlockDevice":
case "Directory":
case "FIFO":
case "ContiguousFile":
case "GNUDumpDir":
break;
case "NextFileHasLongLinkpath":
case "NextFileHasLongPath":
case "OldGnuLongPath":
case "GlobalExtendedHeader":
case "ExtendedHeader":
case "OldExtendedHeader":
this.meta = true;
break;
// NOTE: gnutar and bsdtar treat unrecognized types as 'File'
// it may be worth doing the same, but with a warning.
default:
this.ignore = true;
}
if (!header.path) {
throw new Error("no path provided for tar.ReadEntry");
}
this.path = normalizeWindowsPath(header.path);
this.mode = header.mode;
if (this.mode) {
this.mode = this.mode & 4095;
}
this.uid = header.uid;
this.gid = header.gid;
this.uname = header.uname;
this.gname = header.gname;
this.size = this.remain;
this.mtime = header.mtime;
this.atime = header.atime;
this.ctime = header.ctime;
this.linkpath = header.linkpath ? normalizeWindowsPath(header.linkpath) : void 0;
this.uname = header.uname;
this.gname = header.gname;
if (ex) {
this.#slurp(ex);
}
if (gex) {
this.#slurp(gex, true);
}
}
write(data) {
const writeLen = data.length;
if (writeLen > this.blockRemain) {
throw new Error("writing more to entry than is appropriate");
}
const r = this.remain;
const br = this.blockRemain;
this.remain = Math.max(0, r - writeLen);
this.blockRemain = Math.max