tar 8.0.1 → 8.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"normalize-unicode.d.ts","sourceRoot":"","sources":["../../src/normalize-unicode.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,gBAAgB,GAAI,GAAG,MAAM,KAAG,MAyB5C,CAAA"}
1
+ {"version":3,"file":"normalize-unicode.d.ts","sourceRoot":"","sources":["../../src/normalize-unicode.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,gBAAgB,GAAI,GAAG,MAAM,KAAG,MA+B5C,CAAA"}
@@ -6,7 +6,16 @@ const normalizeCache = Object.create(null);
6
6
  // Limit the size of this. Very low-sophistication LRU cache
7
7
  const MAX = 10000;
8
8
  const cache = new Set();
9
+ // A longer string is not cached. Long paths do not repeat, and the
10
+ // cache would keep them for the life of the process.
11
+ const MAX_LENGTH = 256;
9
12
  export const normalizeUnicode = (s) => {
13
+ if (s.length > MAX_LENGTH) {
14
+ return s
15
+ .normalize('NFD')
16
+ .toLocaleLowerCase('en')
17
+ .toLocaleUpperCase('en');
18
+ }
10
19
  if (!cache.has(s)) {
11
20
  // shake out identical accents and ligatures
12
21
  normalizeCache[s] = s
@@ -1 +1 @@
1
- {"version":3,"file":"normalize-unicode.js","sourceRoot":"","sources":["../../src/normalize-unicode.ts"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,+CAA+C;AAC/C,6CAA6C;AAC7C,4CAA4C;AAC5C,MAAM,cAAc,GAA2B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;AAElE,4DAA4D;AAC5D,MAAM,GAAG,GAAG,KAAK,CAAA;AACjB,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAA;AAC/B,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAS,EAAU,EAAE;IACpD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QAClB,4CAA4C;QAC5C,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC;aAClB,SAAS,CAAC,KAAK,CAAC;aAChB,iBAAiB,CAAC,IAAI,CAAC;aACvB,iBAAiB,CAAC,IAAI,CAAC,CAAA;IAC5B,CAAC;SAAM,CAAC;QACN,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC;IACD,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IAEZ,MAAM,GAAG,GAAG,cAAc,CAAC,CAAC,CAAW,CAAA;IAEvC,IAAI,CAAC,GAAG,KAAK,CAAC,IAAI,GAAG,GAAG,CAAA;IACxB,yCAAyC;IACzC,IAAI,CAAC,GAAG,GAAG,GAAG,EAAE,EAAE,CAAC;QACjB,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;YACtB,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;YACf,OAAO,cAAc,CAAC,CAAC,CAAC,CAAA;YACxB,IAAI,EAAE,CAAC,IAAI,CAAC;gBAAE,MAAK;QACrB,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA","sourcesContent":["// warning: extremely hot code path.\n// This has been meticulously optimized for use\n// within npm install on large package trees.\n// Do not edit without careful benchmarking.\nconst normalizeCache: Record<string, string> = Object.create(null)\n\n// Limit the size of this. Very low-sophistication LRU cache\nconst MAX = 10000\nconst cache = new Set<string>()\nexport const normalizeUnicode = (s: string): string => {\n if (!cache.has(s)) {\n // shake out identical accents and ligatures\n normalizeCache[s] = s\n .normalize('NFD')\n .toLocaleLowerCase('en')\n .toLocaleUpperCase('en')\n } else {\n cache.delete(s)\n }\n cache.add(s)\n\n const ret = normalizeCache[s] as string\n\n let i = cache.size - MAX\n // only prune when we're 10% over the max\n if (i > MAX / 10) {\n for (const s of cache) {\n cache.delete(s)\n delete normalizeCache[s]\n if (--i <= 0) break\n }\n }\n\n return ret\n}\n"]}
1
+ {"version":3,"file":"normalize-unicode.js","sourceRoot":"","sources":["../../src/normalize-unicode.ts"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,+CAA+C;AAC/C,6CAA6C;AAC7C,4CAA4C;AAC5C,MAAM,cAAc,GAA2B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;AAElE,4DAA4D;AAC5D,MAAM,GAAG,GAAG,KAAK,CAAA;AACjB,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAA;AAC/B,mEAAmE;AACnE,qDAAqD;AACrD,MAAM,UAAU,GAAG,GAAG,CAAA;AACtB,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAS,EAAU,EAAE;IACpD,IAAI,CAAC,CAAC,MAAM,GAAG,UAAU,EAAE,CAAC;QAC1B,OAAO,CAAC;aACL,SAAS,CAAC,KAAK,CAAC;aAChB,iBAAiB,CAAC,IAAI,CAAC;aACvB,iBAAiB,CAAC,IAAI,CAAC,CAAA;IAC5B,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QAClB,4CAA4C;QAC5C,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC;aAClB,SAAS,CAAC,KAAK,CAAC;aAChB,iBAAiB,CAAC,IAAI,CAAC;aACvB,iBAAiB,CAAC,IAAI,CAAC,CAAA;IAC5B,CAAC;SAAM,CAAC;QACN,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC;IACD,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IAEZ,MAAM,GAAG,GAAG,cAAc,CAAC,CAAC,CAAW,CAAA;IAEvC,IAAI,CAAC,GAAG,KAAK,CAAC,IAAI,GAAG,GAAG,CAAA;IACxB,yCAAyC;IACzC,IAAI,CAAC,GAAG,GAAG,GAAG,EAAE,EAAE,CAAC;QACjB,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;YACtB,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;YACf,OAAO,cAAc,CAAC,CAAC,CAAC,CAAA;YACxB,IAAI,EAAE,CAAC,IAAI,CAAC;gBAAE,MAAK;QACrB,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA","sourcesContent":["// warning: extremely hot code path.\n// This has been meticulously optimized for use\n// within npm install on large package trees.\n// Do not edit without careful benchmarking.\nconst normalizeCache: Record<string, string> = Object.create(null)\n\n// Limit the size of this. Very low-sophistication LRU cache\nconst MAX = 10000\nconst cache = new Set<string>()\n// A longer string is not cached. Long paths do not repeat, and the\n// cache would keep them for the life of the process.\nconst MAX_LENGTH = 256\nexport const normalizeUnicode = (s: string): string => {\n if (s.length > MAX_LENGTH) {\n return s\n .normalize('NFD')\n .toLocaleLowerCase('en')\n .toLocaleUpperCase('en')\n }\n if (!cache.has(s)) {\n // shake out identical accents and ligatures\n normalizeCache[s] = s\n .normalize('NFD')\n .toLocaleLowerCase('en')\n .toLocaleUpperCase('en')\n } else {\n cache.delete(s)\n }\n cache.add(s)\n\n const ret = normalizeCache[s] as string\n\n let i = cache.size - MAX\n // only prune when we're 10% over the max\n if (i > MAX / 10) {\n for (const s of cache) {\n cache.delete(s)\n delete normalizeCache[s]\n if (--i <= 0) break\n }\n }\n\n return ret\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"path-reservations.d.ts","sourceRoot":"","sources":["../../src/path-reservations.ts"],"names":[],"mappings":"AAsBA;;;;;;;;GAQG;AACH,qBAAa,gBAAgB;;IAS3B,0CAA0C;gBAC9B,KAAK,GAAE,OAAe;IAIlC;;;;OAIG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAgGjE"}
1
+ {"version":3,"file":"path-reservations.d.ts","sourceRoot":"","sources":["../../src/path-reservations.ts"],"names":[],"mappings":"AAsBA;;;;;;;;GAQG;AACH,qBAAa,gBAAgB;;IAM3B,0CAA0C;gBAC9B,KAAK,GAAE,OAAe;IAIlC;;;;OAIG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAqGjE"}
@@ -4,15 +4,6 @@
4
4
  import { normalizeUnicode } from './normalize-unicode.js';
5
5
  import { stripTrailingSlashes } from './strip-trailing-slashes.js';
6
6
  import { join } from './path.js';
7
- // The parent directories of a normalized path.
8
- // '/a/b/c' gives ['/', '/a', '/a/b'].
9
- const getDirs = (path) => {
10
- const dirs = [];
11
- for (let i = path.indexOf('/'); i !== -1; i = path.indexOf('/', i + 1)) {
12
- dirs.push(path.slice(0, i) || '/');
13
- }
14
- return dirs;
15
- };
16
7
  /**
17
8
  * Gives each task the exclusive use of its paths, and the shared use
18
9
  * of their parent directories. A task starts when each task before
@@ -23,10 +14,7 @@ const getDirs = (path) => {
23
14
  * path, because they can be the same file on disk.
24
15
  */
25
16
  export class PathReservations {
26
- // For each path: the tasks that wait for it, in order. A function
27
- // has the path for itself. A Set of functions shares the path as a
28
- // parent directory.
29
- #queues = new Map();
17
+ #root = { queue: [], name: '' };
30
18
  #reservations = new Map();
31
19
  #running = new Set();
32
20
  #win32;
@@ -53,35 +41,39 @@ export class PathReservations {
53
41
  this.#add(paths, handler);
54
42
  });
55
43
  }
56
- #add(paths, fn) {
57
- paths =
58
- this.#win32 ?
59
- ['win32 parallelization disabled']
60
- : [
61
- ...new Set(paths.map(p => stripTrailingSlashes(join(normalizeUnicode(p))))),
62
- ];
63
- const dirs = new Set(paths.flatMap(getDirs));
44
+ #add(names, fn) {
45
+ const root = this.#root;
46
+ const paths = new Set();
47
+ const dirs = new Set();
48
+ for (const name of this.#win32 ?
49
+ ['win32 parallelization disabled']
50
+ : names) {
51
+ const path = this.#win32 ? name : (stripTrailingSlashes(join(normalizeUnicode(name))));
52
+ let node = root;
53
+ for (const part of path.split('/')) {
54
+ if (node !== root)
55
+ dirs.add(node);
56
+ const kids = (node.kids ??= new Map());
57
+ let kid = kids.get(part);
58
+ if (!kid)
59
+ kids.set(part, (kid = { queue: [], name: part, up: node }));
60
+ node = kid;
61
+ }
62
+ paths.add(node);
63
+ }
64
64
  // A path of the task is exclusive, so it also covers the use of
65
65
  // that path as a parent directory of another path.
66
66
  for (const p of paths)
67
67
  dirs.delete(p);
68
68
  this.#reservations.set(fn, { dirs, paths });
69
- for (const p of paths) {
70
- const q = this.#queues.get(p);
71
- if (!q)
72
- this.#queues.set(p, [fn]);
73
- else
74
- q.push(fn);
75
- }
76
- for (const dir of dirs) {
77
- const q = this.#queues.get(dir);
78
- const last = q?.[q.length - 1];
79
- if (!q)
80
- this.#queues.set(dir, [new Set([fn])]);
81
- else if (last instanceof Set)
69
+ for (const p of paths)
70
+ p.queue.push(fn);
71
+ for (const { queue } of dirs) {
72
+ const last = queue[queue.length - 1];
73
+ if (last instanceof Set)
82
74
  last.add(fn);
83
75
  else
84
- q.push(new Set([fn]));
76
+ queue.push(new Set([fn]));
85
77
  }
86
78
  this.#run(fn);
87
79
  }
@@ -91,11 +83,11 @@ export class PathReservations {
91
83
  #run(fn) {
92
84
  const { paths, dirs } = this.#reservations.get(fn);
93
85
  for (const p of paths) {
94
- if (this.#queues.get(p)?.[0] !== fn)
86
+ if (p.queue[0] !== fn)
95
87
  return;
96
88
  }
97
- for (const dir of dirs) {
98
- const first = this.#queues.get(dir)?.[0];
89
+ for (const { queue } of dirs) {
90
+ const first = queue[0];
99
91
  if (!(first instanceof Set) || !first.has(fn))
100
92
  return;
101
93
  }
@@ -105,33 +97,34 @@ export class PathReservations {
105
97
  #clear(fn) {
106
98
  const { paths, dirs } = this.#reservations.get(fn);
107
99
  const next = new Set();
108
- for (const path of paths) {
100
+ for (const { queue } of paths) {
109
101
  // A running task is first in the queue of each of its paths.
110
- const q = this.#queues.get(path);
111
- const after = q[1];
112
- if (!after) {
113
- this.#queues.delete(path);
114
- continue;
115
- }
116
- q.shift();
102
+ queue.shift();
103
+ const after = queue[0];
117
104
  if (typeof after === 'function')
118
105
  next.add(after);
119
- else
106
+ else if (after)
120
107
  for (const f of after)
121
108
  next.add(f);
122
109
  }
123
- for (const dir of dirs) {
110
+ for (const { queue } of dirs) {
124
111
  // A running task is in the first set of each of its directories.
125
- const q = this.#queues.get(dir);
126
- const first = q[0];
112
+ const first = queue[0];
127
113
  if (first.size > 1)
128
114
  first.delete(fn);
129
- else if (q.length === 1)
130
- this.#queues.delete(dir);
131
115
  else {
132
- q.shift();
116
+ queue.shift();
133
117
  // Two sets in a row would be one set, so this is a function.
134
- next.add(q[0]);
118
+ if (queue.length)
119
+ next.add(queue[0]);
120
+ }
121
+ }
122
+ // Remove each node that no task uses. Each directory of the task
123
+ // is above one of its paths.
124
+ for (let node of paths) {
125
+ while (node.up && !node.queue.length && !node.kids?.size) {
126
+ node.up.kids?.delete(node.name);
127
+ node = node.up;
135
128
  }
136
129
  }
137
130
  this.#running.delete(fn);
@@ -1 +1 @@
1
- {"version":3,"file":"path-reservations.js","sourceRoot":"","sources":["../../src/path-reservations.ts"],"names":[],"mappings":"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","sourcesContent":["// The async extraction does several entries at one time. Two entries\n// must not work on the same path at one time: a link needs its\n// target, and an entry can replace an object of a different type.\n\nimport { normalizeUnicode } from './normalize-unicode.js'\nimport { stripTrailingSlashes } from './strip-trailing-slashes.js'\nimport { join } from './path.js'\n\ntype Handler = () => void\ntype Queue = (Handler | Set<Handler>)[]\ntype Reservation = { paths: string[]; dirs: Set<string> }\n\n// The parent directories of a normalized path.\n// '/a/b/c' gives ['/', '/a', '/a/b'].\nconst getDirs = (path: string) => {\n const dirs: string[] = []\n for (let i = path.indexOf('/'); i !== -1; i = path.indexOf('/', i + 1)) {\n dirs.push(path.slice(0, i) || '/')\n }\n return dirs\n}\n\n/**\n * Gives each task the exclusive use of its paths, and the shared use\n * of their parent directories. A task starts when each task before\n * it that uses one of its paths, or a directory above or below one,\n * is done.\n *\n * Paths that differ only in case or in Unicode form are the same\n * path, because they can be the same file on disk.\n */\nexport class PathReservations {\n // For each path: the tasks that wait for it, in order. A function\n // has the path for itself. A Set of functions shares the path as a\n // parent directory.\n #queues = new Map<string, Queue>()\n #reservations = new Map<Handler, Reservation>()\n #running = new Set<Handler>()\n #win32: boolean\n\n /** @param win32 run one task at a time */\n constructor(win32: boolean = false) {\n this.#win32 = win32\n }\n\n /**\n * Call `fn` when it is first in line for each of its paths. The\n * paths are free again when the promise of `fn` settles. Returns a\n * promise with the result of `fn`.\n */\n reserve(paths: string[], fn: () => Promise<void>): Promise<void> {\n return new Promise<void>((res, rej) => {\n const handler: Handler = () => {\n fn().then(\n () => {\n this.#clear(handler)\n res()\n },\n er => {\n this.#clear(handler)\n rej(er)\n },\n )\n }\n this.#add(paths, handler)\n })\n }\n\n #add(paths: string[], fn: Handler) {\n paths =\n this.#win32 ?\n ['win32 parallelization disabled']\n : [\n ...new Set(\n paths.map(p =>\n stripTrailingSlashes(join(normalizeUnicode(p))),\n ),\n ),\n ]\n const dirs = new Set<string>(paths.flatMap(getDirs))\n // A path of the task is exclusive, so it also covers the use of\n // that path as a parent directory of another path.\n for (const p of paths) dirs.delete(p)\n this.#reservations.set(fn, { dirs, paths })\n for (const p of paths) {\n const q = this.#queues.get(p)\n if (!q) this.#queues.set(p, [fn])\n else q.push(fn)\n }\n for (const dir of dirs) {\n const q = this.#queues.get(dir)\n const last = q?.[q.length - 1]\n if (!q) this.#queues.set(dir, [new Set([fn])])\n else if (last instanceof Set) last.add(fn)\n else q.push(new Set([fn]))\n }\n this.#run(fn)\n }\n\n // Start the task if it is first in line for each path, and in the\n // first set for each directory. A task that waits is never first in\n // line for each of them, so a task starts one time only.\n #run(fn: Handler) {\n const { paths, dirs } = this.#reservations.get(fn) as Reservation\n for (const p of paths) {\n if (this.#queues.get(p)?.[0] !== fn) return\n }\n for (const dir of dirs) {\n const first = this.#queues.get(dir)?.[0]\n if (!(first instanceof Set) || !first.has(fn)) return\n }\n this.#running.add(fn)\n fn()\n }\n\n #clear(fn: Handler) {\n const { paths, dirs } = this.#reservations.get(fn) as Reservation\n const next = new Set<Handler>()\n for (const path of paths) {\n // A running task is first in the queue of each of its paths.\n const q = this.#queues.get(path) as Queue\n const after = q[1]\n if (!after) {\n this.#queues.delete(path)\n continue\n }\n q.shift()\n if (typeof after === 'function') next.add(after)\n else for (const f of after) next.add(f)\n }\n for (const dir of dirs) {\n // A running task is in the first set of each of its directories.\n const q = this.#queues.get(dir) as Queue\n const first = q[0] as Set<Handler>\n if (first.size > 1) first.delete(fn)\n else if (q.length === 1) this.#queues.delete(dir)\n else {\n q.shift()\n // Two sets in a row would be one set, so this is a function.\n next.add(q[0] as Handler)\n }\n }\n this.#running.delete(fn)\n this.#reservations.delete(fn)\n for (const f of next) this.#run(f)\n }\n}\n"]}
1
+ {"version":3,"file":"path-reservations.js","sourceRoot":"","sources":["../../src/path-reservations.ts"],"names":[],"mappings":"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","sourcesContent":["// The async extraction does several entries at one time. Two entries\n// must not work on the same path at one time: a link needs its\n// target, and an entry can replace an object of a different type.\n\nimport { normalizeUnicode } from './normalize-unicode.js'\nimport { stripTrailingSlashes } from './strip-trailing-slashes.js'\nimport { join } from './path.js'\n\ntype Handler = () => void\ntype Queue = (Handler | Set<Handler>)[]\n// One part of a path. `queue` has the tasks that wait for the path,\n// in order. A function has the path for itself. A Set of functions\n// shares the path as a parent directory. So a path uses memory for\n// its own parts only, and not for each of its parent paths.\ntype Node = {\n queue: Queue\n name: string\n up?: Node\n kids?: Map<string, Node>\n}\ntype Reservation = { paths: Set<Node>; dirs: Set<Node> }\n\n/**\n * Gives each task the exclusive use of its paths, and the shared use\n * of their parent directories. A task starts when each task before\n * it that uses one of its paths, or a directory above or below one,\n * is done.\n *\n * Paths that differ only in case or in Unicode form are the same\n * path, because they can be the same file on disk.\n */\nexport class PathReservations {\n #root: Node = { queue: [], name: '' }\n #reservations = new Map<Handler, Reservation>()\n #running = new Set<Handler>()\n #win32: boolean\n\n /** @param win32 run one task at a time */\n constructor(win32: boolean = false) {\n this.#win32 = win32\n }\n\n /**\n * Call `fn` when it is first in line for each of its paths. The\n * paths are free again when the promise of `fn` settles. Returns a\n * promise with the result of `fn`.\n */\n reserve(paths: string[], fn: () => Promise<void>): Promise<void> {\n return new Promise<void>((res, rej) => {\n const handler: Handler = () => {\n fn().then(\n () => {\n this.#clear(handler)\n res()\n },\n er => {\n this.#clear(handler)\n rej(er)\n },\n )\n }\n this.#add(paths, handler)\n })\n }\n\n #add(names: string[], fn: Handler) {\n const root = this.#root\n const paths = new Set<Node>()\n const dirs = new Set<Node>()\n for (const name of this.#win32 ?\n ['win32 parallelization disabled']\n : names) {\n const path =\n this.#win32 ? name : (\n stripTrailingSlashes(join(normalizeUnicode(name)))\n )\n let node = root\n for (const part of path.split('/')) {\n if (node !== root) dirs.add(node)\n const kids = (node.kids ??= new Map<string, Node>())\n let kid = kids.get(part)\n if (!kid)\n kids.set(part, (kid = { queue: [], name: part, up: node }))\n node = kid\n }\n paths.add(node)\n }\n // A path of the task is exclusive, so it also covers the use of\n // that path as a parent directory of another path.\n for (const p of paths) dirs.delete(p)\n this.#reservations.set(fn, { dirs, paths })\n for (const p of paths) p.queue.push(fn)\n for (const { queue } of dirs) {\n const last = queue[queue.length - 1]\n if (last instanceof Set) last.add(fn)\n else queue.push(new Set([fn]))\n }\n this.#run(fn)\n }\n\n // Start the task if it is first in line for each path, and in the\n // first set for each directory. A task that waits is never first in\n // line for each of them, so a task starts one time only.\n #run(fn: Handler) {\n const { paths, dirs } = this.#reservations.get(fn) as Reservation\n for (const p of paths) {\n if (p.queue[0] !== fn) return\n }\n for (const { queue } of dirs) {\n const first = queue[0]\n if (!(first instanceof Set) || !first.has(fn)) return\n }\n this.#running.add(fn)\n fn()\n }\n\n #clear(fn: Handler) {\n const { paths, dirs } = this.#reservations.get(fn) as Reservation\n const next = new Set<Handler>()\n for (const { queue } of paths) {\n // A running task is first in the queue of each of its paths.\n queue.shift()\n const after = queue[0]\n if (typeof after === 'function') next.add(after)\n else if (after) for (const f of after) next.add(f)\n }\n for (const { queue } of dirs) {\n // A running task is in the first set of each of its directories.\n const first = queue[0] as Set<Handler>\n if (first.size > 1) first.delete(fn)\n else {\n queue.shift()\n // Two sets in a row would be one set, so this is a function.\n if (queue.length) next.add(queue[0] as Handler)\n }\n }\n // Remove each node that no task uses. Each directory of the task\n // is above one of its paths.\n for (let node of paths) {\n while (node.up && !node.queue.length && !node.kids?.size) {\n node.up.kids?.delete(node.name)\n node = node.up\n }\n }\n this.#running.delete(fn)\n this.#reservations.delete(fn)\n for (const f of next) this.#run(f)\n }\n}\n"]}
@@ -1,3 +1,3 @@
1
- var Ti=Object.defineProperty;var Oi=(i,e)=>{for(var t in e)Ti(i,t,{get:e[t],enumerable:!0})};import*as Ps from"node:fs";import*as zs from"node:fs/promises";import{resolve as Fs}from"node:path";var v=i=>ArrayBuffer.isView(i)&&i[Symbol.toStringTag]==="Uint8Array",tt=i=>Object.prototype.toString.call(i)==="[object ArrayBuffer]",N=i=>typeof i?.size=="number"&&typeof i.stream=="function",Pe=i=>typeof i?.getReader=="function",Pi=new TextDecoder("utf-8",{ignoreBOM:!0}),zi=new TextEncoder,A=i=>{let e=i.length;for(let t=0;t<i.length;t++){let s=i.charCodeAt(t);s<128||(s<2048?e+=1:s>=55296&&s<=56319&&(i.charCodeAt(t+1)&64512)===56320?(e+=2,t++):e+=2)}return e},U=(i,e=0,t=i.length)=>{let s="";for(let n=e;n<t;n++){let r=i[n];if(r>=128)return Pi.decode(i.subarray(e,t));s+=String.fromCharCode(r)}return s},ze=(i,e,t,s)=>{let{written:n}=zi.encodeInto(i,e.subarray(t,t+s));e.fill(0,t+n,t+s)},it=(i,e,t)=>{for(let s=0;s<i.length;s++)e[t+s]=i.charCodeAt(s)};var vt=(i,e)=>{if(Number.isSafeInteger(i))i<0?Ni(i,e):Fi(i,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},Fi=(i,e)=>{e[0]=128;for(var t=e.length;t>1;t--)e[t-1]=i&255,i=Math.floor(i/256)},Ni=(i,e)=>{e[0]=255;var t=!1;i=i*-1;for(var s=e.length;s>1;s--){var n=i&255;i=Math.floor(i/256),t?e[s-1]=At(n):n===0?e[s-1]=0:(t=!0,e[s-1]=Tt(n))}},Rt=i=>{let e=i[0],t=e===128?Ci(i.subarray(1,i.length)):e===255?Ui(i):null;if(t===null)throw Error("invalid base256 encoding");if(!Number.isSafeInteger(t))throw Error("parsed number outside of javascript safe integer range");return t},Ui=i=>{for(var e=i.length,t=0,s=!1,n=e-1;n>-1;n--){var r=Number(i[n]),o;s?o=At(r):r===0?o=r:(s=!0,o=Tt(r)),o!==0&&(t-=o*Math.pow(256,e-n-1))}return t},Ci=i=>{for(var e=i.length,t=0,s=e-1;s>-1;s--){var n=Number(i[s]);n!==0&&(t+=n*Math.pow(256,e-s-1))}return t},At=i=>(255^i)&255,Tt=i=>(255^i)+1&255;var he=i=>{let e=i.charCodeAt(0)===47,t=[];for(let r of i.split("/"))r===""||r==="."||(r!==".."?t.push(r):t.length&&t[t.length-1]!==".."?t.pop():e||t.push(r));let s=t.length&&i.charCodeAt(i.length-1)===47,n=t.join("/")+(s?"/":"");return e?"/"+n:n||(i.endsWith("/")?"./":".")},W=(...i)=>he(i.filter(e=>e).join("/")),P=i=>{let e=i.length;for(;e>1&&i.charCodeAt(e-1)===47;)e--;let t=i.lastIndexOf("/",e-1);return t===-1?".":t===0?"/":t===1&&i.charCodeAt(0)===47?"//":i.slice(0,t)},le=i=>{let e=i.length;for(;e>0&&i.charCodeAt(e-1)===47;)e--;return i.slice(i.lastIndexOf("/",e-1)+1,e)},te=i=>i.charCodeAt(0)===47,C=(...i)=>{let e="";for(let s=i.length-1;s>=0&&!te(e);s--){let n=i[s];n&&(e=e?n+"/"+e:n)}let t=he(e);return t.length>1&&t.endsWith("/")?t.slice(0,-1):t},L=(i,e)=>{let t=C(i).split("/"),s=C(e).split("/");t[t.length-1]||t.pop(),s[s.length-1]||s.pop();let n=0;for(;n<t.length&&n<s.length&&t[n]===s[n];)n++;return[...Array.from({length:t.length-n},()=>".."),...s.slice(n)].join("/")};var nt={};Oi(nt,{code:()=>Fe,isCode:()=>de,isName:()=>Di,name:()=>pe,normalFsTypes:()=>st});var de=i=>pe.has(i),Di=i=>Fe.has(i),st=new Set(["0","","1","2","3","4","5","6","7","D"]),pe=new Map([["0","File"],["","OldFile"],["1","Link"],["2","SymbolicLink"],["3","CharacterDevice"],["4","BlockDevice"],["5","Directory"],["6","FIFO"],["7","ContiguousFile"],["g","GlobalExtendedHeader"],["x","ExtendedHeader"],["A","SolarisACL"],["D","GNUDumpDir"],["I","Inode"],["K","NextFileHasLongLinkpath"],["L","NextFileHasLongPath"],["M","ContinuationFile"],["N","OldGnuLongPath"],["S","SparseFile"],["V","TapeVolumeHeader"],["X","OldExtendedHeader"]]),Fe=new Map(Array.from(pe).map(i=>[i[1],i[0]]));var _i=i=>i===void 0||i<0?void 0:i,R=class{cksumValid=!1;needPax=!1;nullBlock=!1;block;path;mode;uid;gid;size;cksum;#e="Unsupported";linkpath;uname;gname;devmaj=0;devmin=0;atime;ctime;mtime;charset;comment;constructor(e,t=0,s,n){v(e)?this.decode(e,t||0,s,n):e&&this.#t(e)}decode(e,t,s,n){if(t||(t=0),!e||!(e.length>=t+512))throw new Error("need 512 bytes for header");let r=D(e,t+156,1),o=st.has(r),a=o?s:void 0,c=o?n:void 0;if(this.path=a?.path??D(e,t,100),this.mode=a?.mode??c?.mode??_(e,t+100,8),this.uid=a?.uid??c?.uid??_(e,t+108,8),this.gid=a?.gid??c?.gid??_(e,t+116,8),this.size=_i(a?.size??c?.size??_(e,t+124,12)),this.mtime=a?.mtime??c?.mtime??rt(e,t+136,12),this.cksum=_(e,t+148,12),c&&this.#t(c,!0),a&&this.#t(a),de(r)&&(this.#e=r||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=D(e,t+157,100),U(e,t+257,t+265)==="ustar\x0000")if(this.uname=a?.uname??c?.uname??D(e,t+265,32),this.gname=a?.gname??c?.gname??D(e,t+297,32),this.devmaj=a?.devmaj??c?.devmaj??_(e,t+329,8)??0,this.devmin=a?.devmin??c?.devmin??_(e,t+337,8)??0,e[t+475]!==0){let l=D(e,t+345,155);this.path=l+"/"+this.path}else{let l=D(e,t+345,130);l&&(this.path=l+"/"+this.path),this.atime=s?.atime??n?.atime??rt(e,t+476,12),this.ctime=s?.ctime??n?.ctime??rt(e,t+488,12)}let h=256;for(let l=t;l<t+148;l++)h+=e[l];for(let l=t+156;l<t+512;l++)h+=e[l];this.cksumValid=h===this.cksum,this.cksum===void 0&&h===256&&(this.nullBlock=!0)}#t(e,t=!1){Object.assign(this,Object.fromEntries(Object.entries(e).filter(([s,n])=>!(n==null||s==="size"&&Number(n)<0||s==="path"&&t||s==="linkpath"&&t||s==="global"))))}encode(e,t=0){if(e||(e=this.block=new Uint8Array(512)),this.#e==="Unsupported"&&(this.#e="0"),!(e.length>=t+512))throw new Error("need 512 bytes for header");let s=this.ctime||this.atime?130:155,n=Mi(this.path||"",s),r=n[0],o=n[1];this.needPax=!!n[2],this.needPax=Y(e,t,100,r)||this.needPax,this.needPax=M(e,t+100,8,this.mode)||this.needPax,this.needPax=M(e,t+108,8,this.uid)||this.needPax,this.needPax=M(e,t+116,8,this.gid)||this.needPax,this.needPax=M(e,t+124,12,this.size)||this.needPax,this.needPax=ot(e,t+136,12,this.mtime)||this.needPax,e[t+156]=Number(this.#e.codePointAt(0)),this.needPax=Y(e,t+157,100,this.linkpath)||this.needPax,it("ustar\x0000",e,t+257),this.needPax=Y(e,t+265,32,this.uname)||this.needPax,this.needPax=Y(e,t+297,32,this.gname)||this.needPax,this.needPax=M(e,t+329,8,this.devmaj)||this.needPax,this.needPax=M(e,t+337,8,this.devmin)||this.needPax,this.needPax=Y(e,t+345,s,o)||this.needPax,e[t+475]!==0?this.needPax=Y(e,t+345,155,o)||this.needPax:(this.needPax=Y(e,t+345,130,o)||this.needPax,this.needPax=ot(e,t+476,12,this.atime)||this.needPax,this.needPax=ot(e,t+488,12,this.ctime)||this.needPax);let a=256;for(let c=t;c<t+148;c++)a+=e[c];for(let c=t+156;c<t+512;c++)a+=e[c];return this.cksum=a,M(e,t+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:pe.get(this.#e)}get typeKey(){return this.#e}set type(e){let t=String(Fe.get(e));if(de(t)||t==="Unsupported")this.#e=t;else if(de(e))this.#e=e;else throw new TypeError("invalid entry type: "+e)}},Mi=(i,e)=>{let s=i,n="",r,o=i.charAt(0)==="/"?"/":".";if(A(s)<100)r=[s,n,!1];else{n=P(s),s=le(s);do A(s)<=100&&A(n)<=e?r=[s,n,!1]:A(s)>100&&A(n)<=e?r=[s.slice(0,99),n,!0]:(s=W(le(n),s),n=P(n));while(n!==o&&r===void 0);r||(r=[i.slice(0,99),"",!0])}return r},D=(i,e,t)=>{let s=e,n=Math.min(e+t,i.length);for(;s<n&&i[s]!==0;)s++;return U(i,e,s)},rt=(i,e,t)=>Ii(_(i,e,t)),Ii=i=>i===void 0?void 0:new Date(i*1e3),_=(i,e,t)=>Number(i[e])&128?Rt(i.subarray(e,e+t)):Hi(i,e,t),Bi=i=>isNaN(i)?void 0:i,Hi=(i,e,t)=>Bi(parseInt(D(i,e,t).trim(),8)),$i={12:8589934591,8:2097151},M=(i,e,t,s)=>s===void 0?!1:s>$i[t]||s<0?(vt(s,i.subarray(e,e+t)),!0):(ji(i,e,t,s),!1),ji=(i,e,t,s)=>it(Gi(s,t),i,e),Gi=(i,e)=>Wi(Math.floor(i).toString(8),e),Wi=(i,e)=>(i.length===e-1?i:"0".repeat(e-i.length-2)+i+" ")+"\0",ot=(i,e,t,s)=>s===void 0?!1:M(i,e,t,s.getTime()/1e3),Y=(i,e,t,s)=>s===void 0?!1:(ze(s,i,e,t),s.length!==A(s)||s.length>t);var Yi=/^\d+$/,I=class i{atime;mtime;ctime;charset;comment;gid;uid;gname;uname;linkpath;dev;ino;nlink;path;size;mode;global;constructor(e,t=!1){this.atime=e.atime,this.charset=e.charset,this.comment=e.comment,this.ctime=e.ctime,this.dev=e.dev,this.gid=e.gid,this.global=t,this.gname=e.gname,this.ino=e.ino,this.linkpath=e.linkpath,this.mtime=e.mtime,this.nlink=e.nlink,this.path=e.path,this.size=e.size,this.uid=e.uid,this.uname=e.uname}encode(){let e=this.encodeBody();if(e==="")return new Uint8Array(0);let t=A(e),s=512*Math.ceil(1+t/512),n=new Uint8Array(s);return new R({path:("PaxHeader/"+le(this.path??"")).slice(0,99),mode:this.mode||420,uid:this.uid,gid:this.gid,size:t,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(n),ze(e,n,512,t),n}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(e){if(this[e]===void 0)return"";let t=this[e],s=typeof t=="object"?t.getTime()/1e3:t,n=" "+(e==="dev"||e==="ino"||e==="nlink"?"SCHILY.":"")+e+"="+s+`
2
- `,r=A(n),o=Math.floor(Math.log(r)/Math.log(10))+1;return r+o>=Math.pow(10,o)&&(o+=1),o+r+n}static parse(e,t,s=!1){return i.parseBytes(new TextEncoder().encode(e),t,s)}static parseBytes(e,t,s=!1){return new i(Vi(qi(e),t),s)}},Vi=(i,e)=>e?Object.assign({},e,i):i,qi=i=>{let e=Object.create(null),t=0;for(;t<i.length;){let s=t;for(;s<i.length&&i[s]>=48&&i[s]<=57;)s++;if(s===t||i[s]!==32)break;let n=Number(U(i,t,s)),r=t+n;if(r<=s+1||r>i.length||i[r-1]!==10)break;Ki(e,U(i,s+1,r-1)),t=r}return e},Ki=(i,e)=>{let t=e.split("="),s=t.shift();if(!s)return i;let n=s.replace(/^SCHILY\.(dev|ino|nlink)/,"$1"),r=t.join("="),o=r.indexOf("\0"),a=o===-1?r:r.slice(0,o);switch(n){case"path":case"linkpath":case"type":case"charset":case"comment":case"gname":case"uname":i[n]=a;break;case"ctime":case"atime":case"mtime":let c=new Date(Number(a)*1e3);isNaN(c.getTime())||(i[n]=c);break;case"size":case"gid":case"uid":case"dev":case"ino":case"nlink":case"mode":if(!Yi.test(a.trim()))break;let h=+a;if(!Number.isSafeInteger(h))break;i[n]=h;break}return i};var T={name:"gzip",headLength:2,detect:i=>i[0]===31&&i[1]===139,decompress:()=>new DecompressionStream("gzip"),compress:i=>{let e=new CompressionStream("gzip");if(!i?.portable)return e;let t=0;return{writable:e.writable,readable:e.readable.pipeThrough(new TransformStream({transform:(s,n)=>{t<=9&&t+s.length>9&&(s[9-t]=255),t+=s.length,n.enqueue(s)}}))}}};var Ot={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:"onEntry",onReadEntry:"onEntry"},y=i=>{let e=Object.assign(Object.create(null),i);for(let[t,s]of Object.entries(Ot))e[t]!==void 0&&(e[s]??=e[t]),delete e[t];return e.noChmod===!1&&(e.chmod??=!0),delete e.noChmod,e};var z=i=>{if(i.length===1)return i[0].slice();let e=0;for(let n of i)e+=n.length;let t=new Uint8Array(e),s=0;for(let n of i)t.set(n,s),s+=n.length;return t};var k=(i,e)=>Object.assign(Object.create(null),i,e),V=(i,e,t)=>{if(e==null||e===0)return t;if(e===1/0||Number.isInteger(e)&&Number(e)>0)return e;throw new TypeError(`${i} must be a positive integer`)};var Xi=new Set(["File","OldFile","Link","SymbolicLink","CharacterDevice","BlockDevice","Directory","FIFO","ContiguousFile","GNUDumpDir"]),Ne=i=>i.replaceAll("\\","/"),q=class{header;extended;globalExtended;type;path;mode;uid;gid;uname;gname;size;mtime;atime;ctime;linkpath;devmaj;devmin;dev;ino;nlink;absolute;ignore;invalid=!1;unsupported=!1;constructor(e,t,s,n=!1){if(!e.path)throw new Error("no path provided for tar.ReadEntry");this.header=e,this.extended=t,this.globalExtended=s,this.type=e.type,this.ignore=!Xi.has(this.type),this.path=n?Ne(e.path):e.path,this.mode=e.mode&&e.mode&4095,this.uid=e.uid,this.gid=e.gid,this.uname=e.uname,this.gname=e.gname,this.size=e.size??0,this.mtime=e.mtime,this.atime=e.atime,this.ctime=e.ctime,this.linkpath=e.linkpath?n?Ne(e.linkpath):e.linkpath:void 0,this.devmaj=e.devmaj,this.devmin=e.devmin,s&&this.#e(s),t&&(this.#e(t),t.path!=null&&(this.path=n?Ne(t.path):t.path),t.linkpath!=null&&(this.linkpath=n?Ne(t.linkpath):t.linkpath))}#e(e){e.uid!=null&&(this.uid=e.uid),e.gid!=null&&(this.gid=e.gid),e.uname!=null&&(this.uname=e.uname),e.gname!=null&&(this.gname=e.gname),e.mtime!=null&&(this.mtime=e.mtime),e.atime!=null&&(this.atime=e.atime),e.ctime!=null&&(this.ctime=e.ctime),e.dev!=null&&(this.dev=e.dev),e.ino!=null&&(this.ino=e.ino),e.nlink!=null&&(this.nlink=e.nlink)}},Pt=new TextDecoder,zt=i=>{let e="";for(let t of i)e+=Pt.decode(t,{stream:!0});return e+Pt.decode()},Ft=()=>new TypeError("Body has already been consumed"),fe=class extends q{#e;#t=!1;#i;constructor(e,t,s,n,r){super(e,t,s,n),this.#e=r}get bodyUsed(){return this.#t}get body(){if(this.#i)return this.#i;let e=!1;return this.#i=new ReadableStream({pull:async t=>{e||(this.#n(),e=!0);let[s]=await this.#s(1);s?t.enqueue(s):t.close()}},{highWaterMark:0})}#n(){if(this.#t)throw Ft();this.#t=!0}#r(e,t=1/0){let s=this.#e;for(;s&&e.length<t;){let n=s.readBody(this);if(n===null)break;if(n===void 0)return!1;e.push(n)}return!0}async#s(e){let t=[];for(;!this.#r(t,e);)await this.#e?.fill();return t}async bytes(){this.#n();let e=[];for(;!this.#r(e);)await this.#e?.fill();return z(e)}async arrayBuffer(){return(await this.bytes()).buffer}async text(){return this.#n(),zt(await this.#s())}async blob(){return this.#n(),new Blob(await this.#s())}},me=class extends q{#e;#t=!1;#i;constructor(e,t,s,n,r){super(e,t,s,n),this.#e=r}get bodyUsed(){return this.#t}get body(){return this.#i??=this.#n()}*#n(){this.#r();for(let e;e=this.#e?.readBody(this);)yield e}#r(){if(this.#t)throw Ft();this.#t=!0}#s(){this.#r();let e=[];for(let t;t=this.#e?.readBody(this);)e.push(t);return e}bytes(){return z(this.#s())}arrayBuffer(){return this.bytes().buffer}text(){return zt(this.#s())}};var Nt=(i,e,t,s)=>(i.file&&(s.file=i.file),s.code=typeof t=="object"&&t.code||e,s.tarCode=e,s),at=(i,e,t,s={})=>Object.assign(typeof t=="object"?t:new Error(`${e}: ${t}`),Nt(i,e,t,s)),S=(i,e,t,s={})=>{let n=Object.hasOwn(s,"recoverable")&&s.recoverable===!1;if(i.strict||n)throw at(i,e,t,s);Nt(i,e,t,s),typeof t=="object"&&(s=Object.assign(t,s),t=t.message),i.onwarn?.(e,t,s)};var Ut=0,ie=1,Ue=2,Ce=3,Ct=4,ct={type:"entryEnd"},Zi={type:"end"},Ji=new Set(["ExtendedHeader","OldExtendedHeader","GlobalExtendedHeader","NextFileHasLongPath","OldGnuLongPath","NextFileHasLongLinkpath"]),Lt=i=>{let e=i.indexOf(0);return U(i,0,e===-1?i.length:e)},B=class{maxMetaEntrySize;position=0;offset=0;#e;#t;#i;#n=[];#r;#s=0;#o;#a=0;#c=Ut;#h;#d;#w;#y=0;#p=0;#l=0;#m;#g;#b;#x;#k=!1;#u;#f=!1;#S=0;constructor(e={},t){e=this.#e=k(e),this.maxMetaEntrySize=e.maxMetaEntrySize||1024*1024,this.#t=e.filter;let s=e.platform==="win32";this.#i=t??((n,r,o)=>new q(n,r,o,s))}warn(e,t,s){S(this.#e,e,t,s)}push(e){this.#k||this.#n.push(e)}end(){this.#k=!0}get bodyRemain(){let e=this.#r,t=this.#c;return t!==Ue&&t!==Ce||this.#n.length||e&&this.#s<e.length?0:this.#l}skipBody(){this.#f=this.#c===Ue,this.offset+=this.#l,this.#p=this.#l=0,this.#E()}next(){if(this.#f)return this.#f=!1,ct;for(;;){let e=this.#r,t=this.#s;if(!e||t===e.length){if(e=this.#r=this.#n.shift(),t=this.#s=0,!e){if(!this.#k||this.#S===2)return;let l=this.#R();if(l)return l}continue}let s=e.length-t,n=this.#c;if(n<=ie){let l;if(this.#a===0&&s>=512)this.#s=t+512,l=this.#v(e,t);else{let d=this.#o??=new Uint8Array(512),p=Math.min(512-this.#a,s);if(d.set(e.subarray(t,t+p),this.#a),this.#s=t+p,this.#a+=p,this.#a<512)continue;this.#a=0,l=this.#v(d,0)}if(l)return l;continue}let r=this.#l,o=s<r?s:r,a=this.#p,c=o<a?o:a;this.#s=t+o,this.offset+=o,this.#l=r-o,this.#p=a-c;let h=o===r;if(n===Ct){let l=this.#w;l.set(e.subarray(t,t+c),this.#y),this.#y+=c,h&&(this.#E(),this.#A(l));continue}if(h&&this.#E(),n!==Ce){if(c===0){if(h)return ct;continue}return this.#f=h,{type:"body",data:c===e.length?e:e.subarray(t,t+c)}}}}#E(){let e=this.#h;e&&(this.position=this.offset,this.#h=void 0),e?.invalid||(this.#u=!0),this.#c=ie}#R(){let e=this.#c;if(e>ie){let t=this.#h,s=(512-this.#l%512)%512,n=this.#l+s;this.#h=void 0,this.#w=void 0,this.#c=ie,t?.invalid||(this.#u=!0),this.#f=e===Ue,this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${n} more bytes, only ${s} available)`,{entry:t,header:this.#d});return}return this.#f?(this.#f=!1,ct):(this.#S===0&&(this.#S=1,(e===Ut||this.#u===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")),this.#S=2,Zi)}#v(e,t){this.offset+=512,this.#u===void 0&&(this.#u=!1);let s=this.#m,n=this.#g,r=this.#b;(n!==void 0||r!==void 0)&&(s=Object.assign(Object.create(null),s),s.path??=n,s.linkpath??=r);let o;try{o=new R(e,t,s,this.#x)}catch(d){this.warn("TAR_ENTRY_INVALID",d);return}if(o.nullBlock){this.#k=!0,this.#r=void 0,this.#n.length=0,this.#a=0,this.#c=ie;return}if(!o.cksumValid){this.warn("TAR_ENTRY_INVALID","checksum failure",{header:o});return}if(!o.path){this.warn("TAR_ENTRY_INVALID","path is required",{header:o});return}let a=o.type,c=a==="Link"||a==="SymbolicLink";if(c&&!o.linkpath){this.warn("TAR_ENTRY_INVALID","linkpath required",{header:o});return}if(!c&&o.linkpath&&a!=="ExtendedHeader"&&a!=="GlobalExtendedHeader"){this.warn("TAR_ENTRY_INVALID","linkpath forbidden",{header:o});return}let h=o.size??0;if(this.#d=o,this.#p=h,this.#l=512*Math.ceil(h/512),h||(this.#u=!0),Ji.has(a)){h>this.maxMetaEntrySize?this.#c=Ce:h>0&&(this.#w=new Uint8Array(h),this.#y=0,this.#c=Ct);return}this.#m=this.#g=this.#b=void 0;let l=this.#i(o,s,this.#x);return!l.ignore&&this.#t&&!this.#t(l.path,l)&&(l.ignore=!0),h?(this.#h=l,this.#c=l.ignore?Ce:Ue):(this.#c=ie,this.position=this.offset,this.#f=!l.ignore),{type:"entry",entry:l}}#A(e){switch(this.#d.type){case"ExtendedHeader":case"OldExtendedHeader":this.#m=I.parseBytes(e,this.#m,!1);break;case"GlobalExtendedHeader":this.#x=I.parseBytes(e,this.#x,!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":this.#g=Lt(e);break;default:this.#b=Lt(e)}}};var Qi=16*1024*1024,Dt=64*1024,es=1024*1024,De=Symbol.for("tar.readFile.skip"),Le=class{pos=0;size=0;#e;#t=Dt;constructor(e){this.#e=V("maxReadSize",e,Qi)}next(){let e=Math.min(this.#t,this.#e,this.size-this.pos);return this.#t*=2,e}skip(e){return e<es||this.pos+e>this.size?!1:(this.pos+=e,this.#t=Dt,!0)}};async function*ts(i,e,t){let s=await i.open(e,"r");try{t.size=(await s.stat()).size;for(let n;n=t.next();){let r=new Uint8Array(n),{bytesRead:o}=await s.read(r,0,n,t.pos);if(!o)break;t.pos+=o,yield o<n?r.subarray(0,o):r}}finally{await s.close().catch(()=>{})}}function*is(i,e,t){let s=i.openSync(e,"r");try{t.size=i.fstatSync(s).size;for(let n;n=t.next();){let r=new Uint8Array(n),o=i.readSync(s,r,0,n,t.pos);if(!o)break;t.pos+=o,yield o<n?r.subarray(0,o):r}}finally{try{i.closeSync(s)}catch{}}}var H=(i,e,t)=>{let s=new Le(t);return Object.assign(ts(i,e,s),{[De]:n=>s.skip(n)})},$=(i,e,t)=>{let s=new Le(t);return Object.assign(is(i,e,s),{[De]:n=>s.skip(n)})};var ht=()=>{},we=i=>Math.max(512,...i.map(e=>e.headLength)),ss=i=>{try{let e=new R(i);return e.cksumValid||e.nullBlock}catch{return!1}},ye=(i,e,t="")=>i.find(s=>s.detect(e))??(ss(e)?void 0:i.find(s=>s.extensions?.some(n=>t.endsWith(n)))),_t=i=>typeof i.maxDecompressionRatio=="number"?i.maxDecompressionRatio:1e3,_e=(i,e)=>at(i,"TAR_ABORT",e,{recoverable:!1}),Mt=(i,e,t)=>_e(i,new Error(`max decompression ratio exceeded: ${e.toFixed(2)} > ${t}`)),ns=()=>new TypeError("The body of an entry cannot be read after a later entry"),ue=class{parser;current;ended=!1;constructor(e){this.parser=e}entry(){if(this.current=void 0,this.ended)return null;for(let e;e=this.parser.next();){if(e.type==="end")return this.ended=!0,null;if(e.type==="entry"&&!e.entry.ignore)return this.current=e.entry}}body(e){if(e!==this.current)throw ns();let t=this.parser.next();if(t)return t.type==="body"?t.data:(this.current=void 0,null)}},It=(i,e)=>{if(i.current)return;let t=i.parser.bodyRemain;t&&e[De]?.(t)&&i.parser.skipBody()},rs=i=>{if(v(i))return[i].values();if(tt(i))return[new Uint8Array(i)].values();if(N(i)&&(i=i.stream()),Pe(i)){let e=i.getReader();return{next:()=>e.read(),return:()=>e.cancel()}}return Symbol.asyncIterator in i?i[Symbol.asyncIterator]():i[Symbol.iterator]()},b=class{parser;#e;#t;#i;#n;#r;#s;#o=!1;constructor(e,t={}){t=k(t);let s=t.platform==="win32";this.parser=new B(t,(n,r,o)=>new fe(n,r,o,s,this)),this.#e=new ue(this.parser),this.#t=t,this.#i=rs(e)}poll(){return this.#o?null:this.#e.entry()}readBody(e){return this.#e.body(e)}fill(){return this.#s??=this.#a()}async#a(){try{let e=this.#n??=await this.#c(this.#i),t=this.#r;this.#r=void 0,e===this.#i&&It(this.#e,e);let s=t?{value:t,done:!1}:await e.next();s.done?this.parser.end():this.parser.push(s.value)}finally{this.#s=void 0}}async#c(e){let t=this.#t,s=[...t.codecs??[],T],n=we(s),r;for(;!r||r.length<n;){let u=await e.next();if(u.done)break;r=r?z([r,u.value]):u.value}let o=r&&ye(s,r,t.file);if(!o)return this.#r=r,e;let a=0,c=0,{readable:h,writable:l}=o.decompress(),d=l.getWriter(),p=h.getReader(),f=!1;(async()=>{try{for(;;){if(await d.ready,f)return;let u=r?{value:r,done:!1}:await e.next();if(r=void 0,f)return;if(u.done)return await d.close();a+=u.value.length,await d.write(u.value)}}catch(u){f||await d.abort(u).catch(ht)}})();let m=_t(t);return{next:async()=>{let u=await p.read().catch(g=>{throw _e(t,g)});if(!u.done){c+=u.value.length;let g=c/a;if(g>m)throw Mt(t,g,m)}return u},return:async()=>(f=!0,await p.cancel().catch(ht),await d.abort().catch(ht),await e.return?.(),{value:void 0,done:!0})}}async next(){try{for(;;){let e=this.poll();if(e)return{value:e,done:!1};if(e===null)break;await this.fill()}}catch(e){throw await this.return(),e}return this.return()}async return(){return this.#o||(this.#o=!0,this.#e.current=void 0,await(this.#n??this.#i).return?.()),{value:void 0,done:!0}}[Symbol.asyncIterator](){return this}},E=class{parser;#e;#t;#i;#n;#r;#s=!1;constructor(e,t={}){t=k(t);let s=t.platform==="win32";this.parser=new B(t,(n,r,o)=>new me(n,r,o,s,this)),this.#e=new ue(this.parser),this.#t=t,this.#i=v(e)?[e].values():tt(e)?[new Uint8Array(e)].values():e[Symbol.iterator]()}readBody(e){for(;;){let t=this.#e.body(e);if(t!==void 0)return t;this.#o()}}#o(){let e=this.#n??=this.#a(this.#i),t=this.#r;this.#r=void 0,e===this.#i&&It(this.#e,e);let s=t?{value:t,done:!1}:e.next();s.done?this.parser.end():this.parser.push(s.value)}#a(e){let t=this.#t,s=[...t.codecs??[],T],n=we(s),r,o;for(;(!r||r.length<n)&&!(o=e.next()).done;)r=r?z([r,o.value]):o.value;let a=r&&ye(s,r,t.file);if(!r||!a)return this.#r=r,e;let{decompressSync:c}=a;if(!c)throw _e(t,new Error(`the ${a.name} codec has no decompressSync function`));let h=[r];for(;!(o=e.next()).done;)h.push(o.value);let l=z(h),d=_t(t),p;try{p=c(l,{maxOutputLength:l.length*d})}catch(w){throw _e(t,w)}let f=p.length/l.length;if(f>d)throw Mt(t,f,d);return[p].values()}next(){try{for(;;){let e=this.#s?null:this.#e.entry();if(e)return{value:e,done:!1};if(e===null)break;this.#o()}}catch(e){throw this.return(),e}return this.return()}return(){return this.#s||(this.#s=!0,this.#e.current=void 0,(this.#n??this.#i).return?.()),{value:void 0,done:!0}}[Symbol.iterator](){return this}},lt=(i,e)=>new b(i,e),Bt=(i,e)=>new E(i,e);var Ht=(i,e,t)=>(i&=4095,t&&(i=(i|384)&-19),e&&(i&256&&(i|=64),i&32&&(i|=8),i&4&&(i|=1)),i);var Me=["|","<",">","?",":"],dt=Me.map(i=>String.fromCodePoint(61440+Number(i.codePointAt(0)))),os=new Map(Me.map((i,e)=>[i,dt[e]])),as=new Map(dt.map((i,e)=>[i,Me[e]])),pt=i=>Me.reduce((e,t)=>e.split(t).join(os.get(t)),i),$t=i=>dt.reduce((e,t)=>e.split(t).join(as.get(t)),i);var K=i=>i===47||i===92,cs=i=>i>=65&&i<=90||i>=97&&i<=122,j=i=>{let e=i.length,t=0;if(K(i.charCodeAt(0))){if(t=1,K(i.charCodeAt(1))){let s=2,n=s;for(;s<e&&!K(i.charCodeAt(s));)s++;if(s<e&&s!==n){for(n=s;s<e&&K(i.charCodeAt(s));)s++;if(s<e&&s!==n){for(n=s;s<e&&!K(i.charCodeAt(s));)s++;s===e?t=s:s!==n&&(t=s+1)}}}}else cs(i.charCodeAt(0))&&i.charCodeAt(1)===58&&(t=K(i.charCodeAt(2))?3:2);return i.slice(0,t)},ge=i=>K(i.charCodeAt(0))||j(i).length===3,Ie=(i,e)=>{let t=ge(e)?e:i+"/"+e,s=j(t);return s+C("/",t.slice(s.length)).slice(1)},Gt=i=>{let e=j(i),t=P(i.slice(e.length));return t==="."?e:e+t};var Be=i=>{let e="";for(let t;t=j(i);)i.charAt(0)==="/"&&i.slice(0,4)!=="//?/"&&(t="/"),i=i.slice(t.length),e+=t;return[e,i]};var He=i=>new ReadableStream({pull:async e=>{let t=await i.next();t.done?e.close():e.enqueue(t.value)},cancel:async()=>{await i.return?.()}},{highWaterMark:0});var X=i=>{let e=i.length-1,t=-1;for(;e>-1&&i.charAt(e)==="/";)t=e,e--;return t===-1?i:i.slice(0,t)};var hs=new TextEncoder,Wt=(i,e)=>e?X(e)+"/"+i.replace(/^\.(\/|$)/,""):i,se=class{path;type;mode;uid;gid;uname;gname;size;mtime;atime;ctime;linkpath;dev;ino;nlink;body;absolute;header;constructor(e,t){if(e.type==="Unsupported")throw new Error("writing entry that should be ignored");if(typeof t=="string"&&(t=hs.encode(t)),this.path=e.path,this.type=e.type??"File",this.mode=e.mode,this.uid=e.uid,this.gid=e.gid,this.uname=e.uname,this.gname=e.gname,e.size===void 0&&t!==void 0&&!v(t)&&!N(t))throw new TypeError("a stream body needs the size option");this.size=e.size??(v(t)?t.length:N(t)?t.size:0),this.mtime=e.mtime,this.atime=e.atime,this.ctime=e.ctime,this.linkpath=e.linkpath,this.dev=e.dev,this.ino=e.ino,this.nlink=e.nlink,this.body=t}encode(e={},t=new Uint8Array(512)){e=k(e);let s=Wt(this.path,e.prefix),n=this.type==="Link"&&this.linkpath!==void 0?Wt(this.linkpath,e.prefix):this.linkpath,{uid:r,gid:o,uname:a,gname:c,size:h,mtime:l,atime:d,ctime:p}=this;if(this.header=new R({path:s,linkpath:n,mode:this.mode,uid:r,gid:o,size:h,mtime:l,type:this.type,uname:a,gname:c,atime:d,ctime:p}),!this.header.encode(t)||e.noPax)return[t];let{dev:f,ino:w,nlink:m}=this;return[new I({atime:d,ctime:p,gid:o,gname:c,mtime:l,path:s,linkpath:n,size:h,uid:r,uname:a,dev:f,ino:w,nlink:m}).encode(),t]}};var ls=16*1024*1024,O=()=>{},xe=i=>512*Math.ceil(i/512),Z=i=>i.replaceAll("\\","/"),ft=i=>`${i.dev}:${i.ino}`,$e={bigint:!0},ds=({dev:i,ino:e})=>!Number.isSafeInteger(i)||!Number.isSafeInteger(e),je=(i,e)=>i.dev===e.dev&&i.ino===e.ino,mt=(i,e)=>Object.assign(new Error(i),{path:e,syscall:"read",code:"EOF"}),Xt=(i,e)=>mt(`encountered unexpected EOF: ${i} has fewer than the ${e} bytes of its stat`,i),Zt=(i,e)=>mt(`did not encounter expected EOF: ${i} has more than the ${e} bytes of its stat`,i),Jt=i=>i.absolute??i.path,ps=i=>Object.assign(new Error("writing more data than expected"),{path:Jt(i)}),Qt=i=>Symbol.asyncIterator in i||Symbol.iterator in i,fs=i=>typeof i.encode=="function",F=class{path;absolute;up;linkpath;ready;constructor(e,t){this.path=e,this.absolute=t}},ke=class{opt;fs;cwd;win32;maxReadSize;header;codec;codecOptions;ended=!1;head;tail;wake;#e=new Map;constructor(e,t){e=this.opt=k(e),this.fs=e.fs,this.win32=e.platform==="win32",this.maxReadSize=V("maxReadSize",e.maxReadSize,ls);let{prefix:s,noPax:n}=e;this.header={prefix:s&&this.win32?Z(s):s,noPax:n};let r=e.cwd&&(this.win32?Z(e.cwd):e.cwd);if(r&&!(this.win32?ge:te)(r))throw new TypeError("cwd must be an absolute path");this.cwd=r&&this.#t(r,"");let o=e,a=["gzip","brotli","zstd","compress"].filter(h=>o[h]);if(a.length>1)throw new TypeError(`${a.join(", ")} are mutually exclusive`);let[c]=a;if(c){let h=e.compress,[l,d]=h?Array.isArray(h)?h:[h]:[[...e.codecs??[],T].find(p=>p.name===c),o[c]];if(!l?.[t])throw new TypeError(`no codec named ${l?.name??c} has a ${t} function`);this.codec=l,this.codecOptions={...typeof d=="object"?d:void 0,...l.name==="gzip"&&e.portable?{portable:!0}:void 0}}}#t(e,t){return this.win32?Ie(e,t):C(e,t)}resolve(e){if(!this.cwd||!this.fs)throw new TypeError("a path needs the cwd and fs options");return this.#t(this.cwd,this.win32?Z(e):e)}add(e){if(this.ended)throw new Error("write after end");if(typeof e!="string")this.push(e);else{let t=this.win32?Z(e):e;this.push(new F(t||"./",this.resolve(t)))}return this}end(){return this.ended=!0,this.wake?.(),this}push(e){let t={item:e};this.tail?this.tail.next=t:this.head=t,this.tail=t,this.wake?.()}shift(){this.head=this.head?.next,this.head||(this.tail=void 0)}needsExact(e){return ds(e)&&(e.isDirectory()?!!this.opt.follow:e.isFile()&&e.nlink>1)}plan(e,t,s){let{filter:n}=this.opt;if(!(n&&!n(e.path,t))){if(t.isDirectory()){for(let r=e.up;r;r=r.up)if(r.key===ft(s)){S(this.opt,"TAR_ENTRY_ERROR","directory is its own ancestor",{path:e.path,absolute:e.absolute});return}return"Directory"}if(t.isSymbolicLink())return"SymbolicLink";if(!t.isFile()){S(this.opt,"TAR_ENTRY_UNSUPPORTED","unsupported file type",{path:e.path,absolute:e.absolute});return}if(t.nlink>1){let r=ft(s),o=this.#e.get(r),a=this.cwd;if(o!==e.absolute&&o?.startsWith(a.endsWith("/")?a:a+"/"))return e.linkpath=L(a,o),"Link";this.#e.set(r,e.absolute)}return"File"}}children(e,t,s){let n=e.path==="./"?"":e.path.replace(/\/*$/,"/"),r=e.absolute.endsWith("/")?e.absolute:e.absolute+"/",o=this.opt.follow?{key:ft(s),up:e.up}:void 0;return[...t].sort().map(a=>{let c=new F(n+a,r+a);return c.up=o,c})}missing(e,t){if(t?.code!=="ENOENT")throw t;S(this.opt,"TAR_ENTRY_ERROR",t,{path:e.path,absolute:e.absolute})}changed(e,t){S(this.opt,"TAR_ENTRY_ERROR",t==="Directory"?"directory changed between lstat and readdir":"file changed between lstat and open",{path:e.path,absolute:e.absolute})}pathEntry(e,t,s,n,r){let{processUid:o,processUname:a=""}=this.opt,c=new se({path:e.path,type:s,mode:t.mode,uid:t.uid,gid:t.gid,uname:t.uid===o?a:"",size:s==="File"?t.size:0,mtime:t.mtime,atime:t.atime,ctime:t.ctime,linkpath:n&&this.win32?Z(n):n,dev:t.dev,ino:t.ino,nlink:t.nlink},r);return c.absolute=e.absolute,this.#i(c,!0)}addedEntry(e){if(fs(e))return this.#i(e,!1);let{filter:t}=this.opt;if(!(t&&!t(e.path,e)))return this.#i(new se(e,e.body),!1)}#i(e,t){let{opt:s,win32:n}=this,r=e.type==="Directory";n&&!t&&(e.path=Z(e.path),e.linkpath&&(e.linkpath=Z(e.linkpath)));let[o,a]=s.preservePaths?["",e.path]:Be(e.path);return e.path=a,t&&(n&&(e.path=$t(e.path)),e.path===""&&(e.path="./")),o&&S(s,"TAR_ENTRY_INFO",`stripping ${o} from absolute path`,{entry:e,path:o+e.path}),t&&r&&!e.path.endsWith("/")&&(e.path+="/"),s.portable&&(e.uid=e.gid=e.dev=e.ino=e.nlink=void 0,e.uname=e.gname=void 0,e.atime=e.ctime=void 0),e.mode!==void 0&&(e.mode=Ht(e.mode,r,!!s.portable)),e.mtime=s.noMtime||s.portable&&r?void 0:s.mtime||e.mtime,e}},Yt=async(i,e,t,s,n,r)=>{for(;t<e.length&&s<n;){let{bytesRead:o}=await i.read(e,t,e.length-t,s);if(o<=0)throw Xt(r,n);if(o>n-s)throw Zt(r,n);t+=o,s+=o}return s},Vt=(i,e,t,s,n,r,o)=>{for(;s<t.length&&n<r;){let a=i.readSync(e,t,s,t.length-s,n);if(a<=0)throw Xt(o,r);if(a>r-n)throw Zt(o,r);s+=a,n+=a}return n};async function*ms(i){if(v(i))yield i;else if(N(i)||Pe(i)){let e=(N(i)?i.stream():i).getReader();try{for(;;){let t=await e.read();if(t.done)break;yield t.value}}finally{await e.cancel().catch(O)}}else i&&(yield*i)}function*us(i){if(v(i))yield i;else if(i&&Symbol.iterator in i)yield*i;else if(i)throw new TypeError("PackSync needs a body that is a string, a Uint8Array, or an iterable")}var ei=(i,e,t)=>{if(t.length>e)throw ps(i);return e-t.length},ti=(i,e)=>{if(e)throw mt("encountered unexpected EOF",Jt(i));return new Uint8Array(xe(i.size)-i.size)};async function*qt(i){if(!i.size)return;let e=i.size;for await(let s of ms(i.body))e=ei(i,e,s),yield s;let t=ti(i,e);t.length&&(yield t)}function*Kt(i){if(!i.size)return;let e=i.size;for(let s of us(i.body))e=ei(i,e,s),yield s;let t=ti(i,e);t.length&&(yield t)}var Se=class extends ke{jobs;#e;#t=Promise.resolve();constructor(e={}){super(e,"compress"),this.jobs=V("jobs",this.opt.jobs,4)}async next(){let e=await(this.#e??=this.#i()).next();return e.done?{value:void 0,done:!0}:e}async return(){return this.end(),await this.#e?.return(),{value:void 0,done:!0}}[Symbol.asyncIterator](){return this}#i(){let{codec:e}=this;return e?.compress?this.#n(e.compress(this.codecOptions)):this.#r()}async*#n(e){let t=this.#r(),s,n=He({next:()=>t.next().catch(r=>{throw s={er:r},n.cancel().catch(O),r})}).pipeThrough(e).getReader();try{for(;;){let r=await n.read();if(s)throw s.er;if(r.done)break;yield r.value}}finally{await n.cancel().catch(O),await t.return()}}async*#r(){try{for(;;){let e=this.head;if(!e){if(this.ended)break;await new Promise(s=>this.wake=s);continue}this.#s();let{item:t}=e;if(t instanceof F)yield*this.#c(t);else if(!Qt(t))yield*this.#d(t);else for await(let s of t)yield*this.#d(s);this.shift()}yield new Uint8Array(1024)}finally{for(let e=this.head;e;e=e.next){let{item:t}=e;if(!(t instanceof F)||!t.ready)break;await(await t.ready.catch(O))?.handle?.close().catch(O)}}}#s(){let e=this.fs,t=this.head;for(let s=0;t&&s<this.jobs;s++,t=t.next){let n=t.item;if(!(n instanceof F))break;if(n.ready)continue;let r=this.#o(e,n.absolute);r.catch(O);let o=this.#t.then(()=>r).then(([a,c])=>{let h=this.plan(n,a,c);return h&&{load:this.#a(e,n,a,c,h)}},a=>this.missing(n,a));this.#t=o.catch(O),n.ready=o.then(a=>a?.load),n.ready.catch(O)}}async#o(e,t){let{follow:s}=this.opt,n=await(s?e.stat(t):e.lstat(t)),r=this.needsExact(n)?await(s?e.stat(t,$e):e.lstat(t,$e)):n;return[n,r]}async#a(e,t,s,n,r){let{absolute:o}=t,{follow:a,noDirRecurse:c}=this.opt,h={stat:s,id:n,type:r};if(r==="SymbolicLink")h.linkpath=await e.readlink(o);else if(r==="Directory"&&!c)h.names=await e.readdir(o),h.changed=!a&&!je(s,await e.lstat(o));else if(r==="File"&&s.size){let l=await e.open(o,"r");try{let{size:d}=s,p=xe(d);!a&&!je(s,await l.stat())?h.changed=!0:p>this.maxReadSize?h.handle=l:(h.buf=new Uint8Array(512+p),await Yt(l,h.buf,512,0,d,o))}catch(d){throw await l.close().catch(O),d}h.handle||await l.close()}return h}async*#c(e){let t=await e.ready;if(!t)return;let{stat:s,id:n,type:r,names:o,buf:a,handle:c}=t;if(t.changed)return this.changed(e,r);let h=!1;try{let l=a?a.subarray(512,512+s.size):c&&this.#h(c,s.size,e.absolute),d=this.pathEntry(e,s,r,t.linkpath??e.linkpath,l);if(o)for(let f of this.children(e,o,n))this.push(f);await this.opt.onWriteEntry?.(d);let p=a&&d.body===l&&d.size===s.size;yield*d.encode(this.header,p?a:void 0),p||(yield*qt(d)),h=!0}finally{if(c){t.handle=void 0;let l=c.close();await(h?l:l.catch(O))}}}async*#h(e,t,s){let n=xe(t);for(let r=0;r<t;){let o=new Uint8Array(Math.min(n-r,this.maxReadSize)),a=await Yt(e,o,0,r,t,s);yield o.subarray(0,a-r),r=a}}async*#d(e){let t=this.addedEntry(e);t&&(await this.opt.onWriteEntry?.(t),yield*t.encode(this.header),yield*qt(t))}},be=class extends ke{#e;constructor(e={}){super(e,"compressSync")}next(){let e=(this.#e??=this.#t()).next();return e.done?{value:void 0,done:!0}:e}return(){return this.ended=!0,this.#e?.return(),{value:void 0,done:!0}}[Symbol.iterator](){return this}*#t(){let{codec:e}=this;if(!e?.compressSync)return yield*this.#i();yield e.compressSync(z([...this.#i()]),this.codecOptions)}*#i(){for(let e;e=this.head;this.shift()){let{item:t}=e;if(t instanceof F){let s=[t];for(let n of s)yield*this.#n(n,s)}else if(!Qt(t))yield*this.#s(t);else for(let s of t)yield*this.#s(s)}this.ended=!0,yield new Uint8Array(1024)}*#n(e,t){let s=this.fs,{absolute:n}=e,{follow:r,noDirRecurse:o}=this.opt,a;try{a=r?s.statSync(n):s.lstatSync(n)}catch(m){return this.missing(e,m)}let c=this.needsExact(a)?r?s.statSync(n,$e):s.lstatSync(n,$e):a,h=this.plan(e,a,c);if(!h)return;let{linkpath:l}=e,d,p,f,w=!1;try{if(h==="SymbolicLink")l=s.readlinkSync(n);else if(h==="Directory"&&!o){let g=s.readdirSync(n);if(!r&&!je(a,s.lstatSync(n)))return this.changed(e,h);t.push(...this.children(e,g,c))}else if(h==="File"&&a.size){let{size:g}=a,Et=xe(g);if(f=s.openSync(n,"r"),!r&&!je(a,s.fstatSync(f)))return this.changed(e,h);Et>this.maxReadSize?p=this.#r(s,f,g,n):(d=new Uint8Array(512+Et),Vt(s,f,d,512,0,g,n),p=d.subarray(512,512+g))}let m=this.pathEntry(e,a,h,l,p);this.opt.onWriteEntry?.(m);let u=d&&m.body===p&&m.size===a.size;yield*m.encode(this.header,u?d:void 0),u||(yield*Kt(m)),w=!0}finally{if(f!==void 0&&!w)try{s.closeSync(f)}catch{}}f!==void 0&&s.closeSync(f)}*#r(e,t,s,n){let r=xe(s);for(let o=0;o<s;){let a=new Uint8Array(Math.min(r-o,this.maxReadSize)),c=Vt(e,t,a,0,o,s,n);yield a.subarray(0,c-o),o=c}}*#s(e){let t=this.addedEntry(e);t&&(this.opt.onWriteEntry?.(t),yield*t.encode(this.header),yield*Kt(t))}};var Ee=64*1024,Ge=4*Ee,ws=()=>{},ut=(i,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive");if(i.file&&!i.fs)throw new TypeError("the file option needs the fs option")},ii=async(i,e,t,s)=>{for(let n=0;n<t;)n+=(await i.write(e,n,t-n,s+n)).bytesWritten},wt=async(i,e,t)=>{let s=new Uint8Array(Ge),n=0,r=async()=>{await ii(i,s,n,t),t+=n,n=0};for await(let o of e)(n+o.length>Ge||o.length>=Ee)&&await r(),o.length>=Ee?(await ii(i,o,o.length,t),t+=o.length):(s.set(o,n),n+=o.length);await r()},yt=(i,e,t,s)=>{let n=new Uint8Array(Ge),r=0,o=(a,c)=>{for(let h=0;h<c;)h+=i.writeSync(e,a,h,c-h,s+h);s+=c};for(let a of t)(r+a.length>Ge||a.length>=Ee)&&(o(n,r),r=0),a.length>=Ee?o(a,a.length):(n.set(a,r),r+=a.length);o(n,r)},ys=async(i,e,t,s)=>{let n=await e.open(t,"w",s),r=!1;try{await wt(n,i,0),r=!0}finally{let o=n.close();await(r?o:o.catch(ws))}},We=(i,e)=>{let{fs:t,strict:s,onwarn:n,codecs:r,platform:o}=i,a=new Se(i);for(let c of e)if(typeof c!="string"||c.charAt(0)!=="@")a.add(c);else{let h=a.resolve(c.slice(1));a.add(new b(H(t,h,i.maxReadSize),{strict:s,onwarn:n,codecs:r,platform:o,file:h}))}return a.end()},gt=(i,e)=>{let{strict:t,onwarn:s,codecs:n,platform:r}=i,o=new be(i);for(let a of e)if(typeof a!="string"||a.charAt(0)!=="@")o.add(a);else{let c=o.resolve(a.slice(1));o.add(new E($(i.fs,c,i.maxReadSize),{strict:t,onwarn:s,codecs:n,platform:r,file:c}))}return o};function ne(i,e){let t=y(i);if(!t.file)return ut(t,e),He(We(t,e));try{return ut(t,e),ys(We(t,e),t.fs,t.file,t.mode||438)}catch(s){return Promise.reject(s)}}function Ye(i,e){let t=y(i);ut(t,e);let{file:s}=t,n=t.fs,r=gt(t,e);if(!s)return r;let o=n.openSync(s,"w",t.mode||438);try{yt(n,o,r,0)}catch(a){try{n.closeSync(o)}catch{}throw a}n.closeSync(o)}var J=(i,e)=>{let t=new Set(i.map(o=>X(o))),s=new Set(t),n=0;for(let o of t)n=Math.max(n,o.length);let r=o=>{let a=X(o),c=a.charAt(0)==="/"?"/":".",h=!1;for(let l=a.length;l>0;l=a.lastIndexOf("/",l-1)){if(l>n)continue;let d=a.slice(0,l);if(!(d===c||!t.has(d))&&(h=!0,s.delete(d),!s.size))break}return h};return[(o,a)=>{let c=!e||e(o,a);return r(o)&&c},o=>{for(let a of s)S(o,"TAR_ENTRY_ERROR",`${a}: not found in archive`,{path:a})}]},si=()=>new TypeError("list needs input, or file and fs"),Ve=async(i,e)=>{let t=y(i),{input:s,file:n,fs:r,onEntry:o}=t,a=s??(n&&r?H(r,n,t.maxReadSize):void 0);if(!a)throw si();let[c,h]=e?.length?J(e,t.filter):[];c&&(t.filter=c);let l=new b(a,t);try{for(;;){let d=l.poll();if(d===null)break;d===void 0?await l.fill():o&&await o(d)}}finally{await l.return()}h?.(t)},ni=(i,e)=>{let t=y(i),{input:s,file:n,fs:r,onEntry:o}=t,a=s??(n&&r?$(r,n,t.maxReadSize):void 0);if(!a)throw si();let[c,h]=e?.length?J(e,t.filter):[];c&&(t.filter=c);let l=new E(a,t);for(let d of l)o?.(d);h?.(t)};var gs=()=>{},ri=(i,e)=>{if(!i.file)throw new TypeError("file is required");if(!i.fs)throw new TypeError("the file option needs the fs option");let t=[...i.codecs??[],T];if(e?.length)return[t,...J(e,i.filter)];if(i.filter)return[t,i.filter];throw new TypeError("no paths specified to delete")},oi=i=>`${i}.${Math.random().toString(36).slice(2)}.tmp`,xt=async(i,e)=>{let t=y(i),[s,n,r]=ri(t,e),{fs:o,file:a,filter:c,maxReadSize:h,...l}=t,d=new Uint8Array(we(s)),p=0,f=await o.open(a,"r");try{for(let u=1;u>0&&p<d.length;p+=u)u=(await f.read(d,p,d.length-p,p)).bytesRead}finally{await f.close()}let{mode:w}=await o.stat(a),m=oi(a);try{await ne({...l,fs:o,file:m,mode:w&511,compress:ye(s,d.subarray(0,p),a),preservePaths:!0,filter:(u,g)=>!n(u,g)},[new b(H(o,a,h),{...l,file:a})]),r?.(t),await o.rename(m,a)}catch(u){throw await o.unlink(m).catch(gs),u}},ai=(i,e)=>{let t=y(i),[s,n,r]=ri(t,e),{fs:o,file:a,filter:c,maxReadSize:h,...l}=t,d=new Uint8Array(we(s)),p=0,f=o.openSync(a,"r");try{for(let u=1;u>0&&p<d.length;p+=u)u=o.readSync(f,d,p,d.length-p,p)}finally{o.closeSync(f)}let{mode:w}=o.statSync(a),m=oi(a);try{Ye({...l,fs:o,file:m,mode:w&511,compress:ye(s,d.subarray(0,p),a),preservePaths:!0,filter:(u,g)=>!n(u,g)},[new E($(o,a,h),{...l,file:a})]),r?.(t),o.renameSync(m,a)}catch(u){try{o.unlinkSync(m)}catch{}throw u}};var re=class extends Error{path;code;syscall="chdir";constructor(e,t){super(`${t}: Cannot cd into '${e}'`),this.path=e,this.code=t}get name(){return"CwdError"}};var G=class extends Error{path;symlink;syscall="symlink";code="TAR_SYMLINK_ERROR";constructor(e,t){super("TAR_SYMLINK_ERROR: Cannot extract through symbolic link"),this.symlink=e,this.path=t}get name(){return"SymlinkError"}};var ci=i=>{let e=i.mode|448,{uid:t,gid:s}=i;return{mode:e,needChmod:(e&i.umask)!==0,owner:typeof t=="number"&&typeof s=="number"&&(t!==i.processUid||s!==i.processGid)?{uid:t,gid:s}:void 0}},hi=(i,e)=>i.endsWith("/")?i+e:i+"/"+e,li=(i,e)=>{let t=i.replaceAll("\\","/"),s=[e];for(let n=e.length;!t.endsWith(e.slice(0,n));){if(n=e.lastIndexOf("/",n-1),n<=0)return[e];s.push(e.slice(0,n))}return s},di=async(i,e,t)=>{let{mode:s,needChmod:n,owner:r}=ci(t),{cwd:o}=t,a=[];if(e===o){let c="ENOTDIR";if(!await i.stat(e).then(l=>l.isDirectory(),l=>(c=l?.code||c,!1)))throw new re(e,c)}else if(t.preserve){let c=await i.mkdir(e,{mode:s,recursive:!0});c&&(a=li(c,e))}else{let c=L(o,e).split("/"),h=o;for(let l=0;l<c.length;l++){h=hi(h,c[l]);try{await i.mkdir(h,{mode:s})}catch(d){let p=await i.lstat(h);if(p.isDirectory())continue;if(!t.unlink)throw p.isSymbolicLink()?new G(h,h+"/"+c.slice(l+1).join("/")):d;await i.unlink(h),await i.mkdir(h,{mode:s})}a.push(h)}}if(r)for(let c of a)await i.lchown(c,r.uid,r.gid);n&&await i.chmod(e,s)},pi=(i,e,t)=>{let{mode:s,needChmod:n,owner:r}=ci(t),{cwd:o}=t,a=[];if(e===o){let c="ENOTDIR",h=!1;try{h=i.statSync(e).isDirectory()}catch(l){c=l?.code||c}if(!h)throw new re(e,c)}else if(t.preserve){let c=i.mkdirSync(e,{mode:s,recursive:!0});c&&(a=li(c,e))}else{let c=L(o,e).split("/"),h=o;for(let l=0;l<c.length;l++){h=hi(h,c[l]);try{i.mkdirSync(h,{mode:s})}catch(d){let p=i.lstatSync(h);if(p.isDirectory())continue;if(!t.unlink)throw p.isSymbolicLink()?new G(h,h+"/"+c.slice(l+1).join("/")):d;i.unlinkSync(h),i.mkdirSync(h,{mode:s})}a.push(h)}}if(r)for(let c of a)i.lchownSync(c,r.uid,r.gid);n&&i.chmodSync(e,s)};var kt=Object.create(null),fi=1e4,oe=new Set,mi=i=>{oe.has(i)?oe.delete(i):kt[i]=i.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),oe.add(i);let e=kt[i],t=oe.size-fi;if(t>fi/10){for(let s of oe)if(oe.delete(s),delete kt[s],--t<=0)break}return e};var xs=i=>{let e=[];for(let t=i.indexOf("/");t!==-1;t=i.indexOf("/",t+1))e.push(i.slice(0,t)||"/");return e},ve=class{#e=new Map;#t=new Map;#i=new Set;#n;constructor(e=!1){this.#n=e}reserve(e,t){return new Promise((s,n)=>{let r=()=>{t().then(()=>{this.#o(r),s()},o=>{this.#o(r),n(o)})};this.#r(e,r)})}#r(e,t){e=this.#n?["win32 parallelization disabled"]:[...new Set(e.map(n=>X(W(mi(n)))))];let s=new Set(e.flatMap(xs));for(let n of e)s.delete(n);this.#t.set(t,{dirs:s,paths:e});for(let n of e){let r=this.#e.get(n);r?r.push(t):this.#e.set(n,[t])}for(let n of s){let r=this.#e.get(n),o=r?.[r.length-1];r?o instanceof Set?o.add(t):r.push(new Set([t])):this.#e.set(n,[new Set([t])])}this.#s(t)}#s(e){let{paths:t,dirs:s}=this.#t.get(e);for(let n of t)if(this.#e.get(n)?.[0]!==e)return;for(let n of s){let r=this.#e.get(n)?.[0];if(!(r instanceof Set)||!r.has(e))return}this.#i.add(e),e()}#o(e){let{paths:t,dirs:s}=this.#t.get(e),n=new Set;for(let r of t){let o=this.#e.get(r),a=o[1];if(!a){this.#e.delete(r);continue}if(o.shift(),typeof a=="function")n.add(a);else for(let c of a)n.add(c)}for(let r of s){let o=this.#e.get(r),a=o[0];a.size>1?a.delete(e):o.length===1?this.#e.delete(r):(o.shift(),n.add(o[0]))}this.#i.delete(e),this.#t.delete(e);for(let r of n)this.#s(r)}};var ui=(i,e)=>{if(!i)return()=>"w";let{O_CREAT:t,O_TRUNC:s,O_WRONLY:n,O_NOFOLLOW:r,UV_FS_O_FILEMAP:o}=i,a=s|t|n;if(!e){let h=typeof r=="number"?r|a:"w";return()=>h}if(!o)return()=>"w";let c=o|a;return h=>h<524288?c:"w"};var ks=1024,wi=32768,Ss=16,qe=new Set(["File","OldFile","ContiguousFile"]),ae=new Set(["Directory","GNUDumpDir"]),bs=new Set(["Link","SymbolicLink"]),yi=(i,e,t)=>i!==void 0?i:e!==void 0&&e===e>>>0?e:t,Re=class{opt;cwd;win32;strip;maxDepth;preservePaths;unlink;keep;newer;noMtime;chmod;uid;gid;preserveOwner;forceChown;processUid;processGid;processUmask;umask;dmode;fmode;writeFlag;resolve;dirname;fatal;constructor(e){let t=this.opt=k(e),s=this.win32=t.platform==="win32";if(this.resolve=s?Ie:C,this.dirname=s?Gt:P,typeof t.cwd!="string")throw new TypeError("cwd is required");let n=s?t.cwd.replaceAll("\\","/"):t.cwd;if(!(s?ge:te)(n))throw new TypeError("cwd must be an absolute path");if(this.cwd=this.resolve(n,""),typeof t.uid=="number"||typeof t.gid=="number"){if(typeof t.uid!="number"||typeof t.gid!="number")throw new TypeError("cannot set owner without number uid and gid");if(t.uid!==t.uid>>>0||t.gid!==t.gid>>>0)throw new TypeError("uid and gid must be unsigned 32-bit integers");if(t.preserveOwner)throw new TypeError("cannot preserve owner in archive and also set owner explicitly");this.uid=t.uid,this.gid=t.gid}this.processUid=t.processUid,this.processGid=t.processGid,this.preserveOwner=t.preserveOwner===void 0&&typeof t.uid!="number"?t.processUid===0:!!t.preserveOwner,this.forceChown=t.forceChown===!0,this.maxDepth=typeof t.maxDepth=="number"?t.maxDepth:ks,this.strip=Number(t.strip)||0,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.keep=!!t.keep,this.newer=!!t.newer,this.noMtime=!!t.noMtime,this.chmod=!!t.chmod,this.processUmask=this.chmod?typeof t.processUmask=="number"?t.processUmask:18:0,this.umask=typeof t.umask=="number"?t.umask:this.processUmask,this.dmode=t.dmode||511&~this.umask,this.fmode=t.fmode||438&~this.umask,this.writeFlag=ui(t.fs.constants,s)}warn(e,t,s={}){(e==="TAR_BAD_ARCHIVE"||e==="TAR_ABORT")&&(s.recoverable=!1),s.cwd=this.cwd,S(this.opt,e,t,s)}readerOptions(){return k(this.opt,{strict:!1,onwarn:(e,t,s)=>s instanceof Error?this.warn(e,s):this.warn(e,t,s)})}entryError(e,t){if(this.fatal?.error===e||e?.name==="CwdError")throw e;this.warn("TAR_ENTRY_ERROR",e,{entry:t})}fail(e){return this.fatal??={error:e},e}#e(e,t){let s=e[t];if(!s||this.preservePaths)return!0;let[n,r]=Be(s),o=r.replaceAll("\\","/").split("/");if(o.includes("..")){if(t==="path"||e.type==="Link")return this.warn("TAR_ENTRY_ERROR",`${t} contains '..'`,{entry:e,[t]:s}),!1;let a=o.findIndex(l=>l!==".."&&l!=="."&&l!=="");if(a!==-1&&o.includes("..",a))return this.warn("TAR_ENTRY_ERROR",`${t} contains '..' after a path portion`,{entry:e,[t]:s}),!1;let c=P(he(e.path)),h=he(W(c,o.join("/")));if(h.startsWith("../")||h==="..")return this.warn("TAR_ENTRY_ERROR",`${t} escapes extraction directory`,{entry:e,[t]:s}),!1}return n&&(e[t]=r,this.warn("TAR_ENTRY_INFO",`stripping ${n} from absolute ${t}`,{entry:e,[t]:s})),!0}check(e){let t=e.path,s=t.split("/");if(this.strip){if(s.length<this.strip)return!1;if(e.type==="Link"){let c=String(e.linkpath).split("/");if(c.length<this.strip)return!1;e.linkpath=c.slice(this.strip).join("/")}if(s.splice(0,this.strip),s.every(c=>c===""))return!1;e.path=s.join("/")}let{maxDepth:n}=this;if(isFinite(n)&&s.length>n)return this.warn("TAR_ENTRY_ERROR","path excessively deep",{entry:e,path:t,depth:s.length,maxDepth:n}),!1;let{linkpath:r}=e;if(r&&isFinite(n)&&r.split("/").length>n)return this.warn("TAR_ENTRY_ERROR","linkpath excessively deep",{entry:e,path:t,linkpath:r,maxDepth:n}),!1;for(let c of["path","linkpath"]){let{length:h}=e[c]??"";if(h>wi)return this.warn("TAR_ENTRY_ERROR",`${c} excessively long`,{entry:e,path:t,length:h,maxLength:wi}),!1}if(!this.#e(e,"path")||!this.#e(e,"linkpath"))return!1;let{cwd:o}=this,a=this.resolve(o,e.path);if(!this.preservePaths&&a!==o&&!a.startsWith(o.endsWith("/")?o:o+"/"))return this.warn("TAR_ENTRY_ERROR","path escaped extraction target",{entry:e,path:e.path,resolvedPath:a,cwd:o}),!1;if(a===o&&!ae.has(e.type))return!1;if(this.win32){let c=j(a);a=c+pt(a.slice(c.length));let h=j(e.path);e.path=h+pt(e.path.slice(h.length))}if(e.absolute=a,typeof e.mode=="number"&&(e.mode&=511),ae.has(e.type))e.mode&&(e.mode|=448);else if(!qe.has(e.type)&&!bs.has(e.type))return e.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${e.type}`,{entry:e}),!1;return!0}reservedPaths(e){let{path:t,linkpath:s}=e;return s?[t,e.type==="SymbolicLink"&&!te(s)?W(P(t),s):s]:[t]}mkdirOptions(e){return{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e}}owner(e){let t=this.forceChown||this.preserveOwner&&(typeof e.uid=="number"&&e.uid!==this.processUid||typeof e.gid=="number"&&e.gid!==this.processGid)||typeof this.uid=="number"&&this.uid!==this.processUid||typeof this.gid=="number"&&this.gid!==this.processGid,s=yi(this.uid,e.uid,this.processUid),n=yi(this.gid,e.gid,this.processGid);return t&&typeof s=="number"&&typeof n=="number"?{uid:s,gid:n}:void 0}times(e){return e.mtime&&!this.noMtime?{atime:e.atime||new Date,mtime:e.mtime}:void 0}skip(e,t){return this.keep||this.newer&&t.mtime>(e.mtime??t.mtime)}isReusable(e,t){return e.type==="File"&&!this.unlink&&t.isFile()&&t.nlink<=1&&!this.win32}linkParts(e,t){let s=String(e.linkpath);return e.type==="Link"?s.split("/"):L(this.cwd,this.resolve(this.dirname(t),s)).split("/")}parentParts(e){let{cwd:t}=this,s=e===t?t:this.dirname(e);return s===t?[]:L(t,s).split("/")}symlinkError(e,t){return new G(e,this.resolve(this.cwd,t.join("/")))}},gi=i=>i+".DELETE."+Array.from(crypto.getRandomValues(new Uint8Array(16)),e=>e.toString(16).padStart(2,"0")).join(""),Ae=class extends Re{#e;#t;#i;#n=0;#r;#s=!1;#o;constructor(e){super(e),this.#e=this.opt.fs,this.#t=new ve(this.win32),this.#i=V("jobs",this.opt.jobs,Ss)}async extract(e){let t=new b(e,this.readerOptions()),{onEntry:s}=this.opt,n=!!this.opt.transform;try{for(;!this.fatal;){let r=t.poll();if(r===null)break;if(r===void 0){await t.fill();continue}if(s&&await s(r),r.bodyUsed||!this.check(r))continue;let o=[],a=!n;if(a&&qe.has(r.type))for(;;){let h=t.readBody(r);if(h===null)break;if(h===void 0){a=!1;break}o.push(h)}let c=this.#c(r,o,a?void 0:t);for(a||await c;this.#n>=this.#i;)await this.#a()}}catch(r){this.fail(r)}for(await t.return().catch(r=>this.fail(r));this.#n>0;)await this.#a();if(this.fatal){let{error:r}=this.fatal;throw r&&typeof r=="object"&&"tarCode"in r&&Object.assign(r,{cwd:this.cwd}),r}}#a(){return new Promise(e=>{this.#r=e})}#c(e,t,s){return this.#n++,this.#t.reserve(this.reservedPaths(e),async()=>{try{this.fatal||await this.#w(e,t,s)}catch(n){try{this.entryError(n,e)}catch(r){this.fail(r)}}this.#n--,this.#r?.()})}#h(e,t){return di(this.#e,e,this.mkdirOptions(t))}#d(){return this.#o??=this.#h(this.cwd,this.dmode).then(()=>{this.#s=!0},e=>{throw this.#o=void 0,e})}async#w(e,t,s){let n=this.#e,r=e.absolute,{cwd:o}=this;if(this.#s||await this.#d(),r!==o){let c=this.dirname(r);c!==o&&await this.#h(c,this.dmode)}let a=await n.lstat(r).catch(()=>{});if(!(a&&this.skip(e,a))){if(a&&!this.isReusable(e,a)&&(a.isDirectory()&&ae.has(e.type)?this.chmod&&e.mode&&(a.mode&4095)!==e.mode&&await n.chmod(r,e.mode):r!==o&&(a.isDirectory()?await n.rmdir(r):await this.#y(r))),qe.has(e.type))return this.#m(e,r,t,s);if(ae.has(e.type))await this.#l(e,r);else{await this.#p(this.linkParts(e,r));let c=String(e.linkpath);e.type==="Link"?await n.link(this.resolve(o,c),r):await n.symlink(c,r)}await this.#p(this.parentParts(r))}}async#y(e){let t=this.#e;if(!this.win32)return t.unlink(e);let s=gi(e);await t.rename(e,s),await t.unlink(s)}async#p(e){if(this.preservePaths)return;let t=this.cwd;for(let s of e){t=this.resolve(t,s);let n=await this.#e.lstat(t).catch(()=>{});if(!n)return;if(n.isSymbolicLink())throw this.symlinkError(t,e)}}async#l(e,t){let s=this.#e;await this.#h(t,e.mode??this.dmode);let n=this.times(e);n&&await s.lutimes(t,n.atime,n.mtime).catch(()=>{});let r=this.owner(e);r&&await s.lchown(t,r.uid,r.gid).catch(()=>{})}async#m(e,t,s,n){let r=this.#e,o=await r.open(t,this.writeFlag(e.size),e.mode??this.fmode);try{if(await this.#p(this.parentParts(t)),n)await this.#g(e,s,n,o);else for(let h of s)await o.write(h);let a=this.times(e);if(a){let{atime:h,mtime:l}=a;await o.utimes(h,l).catch(async d=>{await r.utimes(t,h,l).catch(()=>{throw d})})}let c=this.owner(e);if(c){let{uid:h,gid:l}=c;await o.chown(h,l).catch(async d=>{await r.chown(t,h,l).catch(()=>{throw d})})}}catch(a){throw await o.close().catch(()=>{}),a}await o.close()}async#g(e,t,s,n){let r=0,o=async()=>{if(r<t.length)return t[r++];try{for(;;){let f=s.readBody(e);if(f!==void 0)return f;await s.fill()}}catch(f){throw this.fail(f)}},a=this.opt.transform?.(e);if(!a){let f,w;try{for(let m;(m=await o())&&(await f,!w);)f=n.write(m).then(()=>{},u=>{w={error:u}})}finally{await f}if(w)throw w.error;return}let c=a.writable.getWriter(),h=a.readable.getReader(),l,d=async f=>{l??={error:f},await h.cancel(f).catch(()=>{}),await c.abort(f).catch(()=>{})},p=(async()=>{try{for(let f;f=await o();)await c.write(f);await c.close()}catch(f){await d(f)}})();try{for(;;){let{done:f,value:w}=await h.read();if(f)break;await n.write(w)}}catch(f){await d(f)}if(await p,l)throw l.error}},Te=class extends Re{#e;#t=!1;constructor(e){super(e),this.#e=this.opt.fs}extract(e){let t=new E(e,this.readerOptions()),{onEntry:s}=this.opt;try{for(let n of t)if(s?.(n),!n.bodyUsed&&this.check(n))try{this.#n(n,t)}catch(r){this.entryError(r,n)}}catch(n){throw n&&typeof n=="object"&&"tarCode"in n&&Object.assign(n,{cwd:this.cwd}),n}}#i(e,t){pi(this.#e,e,this.mkdirOptions(t))}#n(e,t){let s=this.#e,n=e.absolute,{cwd:r}=this;if(this.#t||(this.#i(r,this.dmode),this.#t=!0),n!==r){let a=this.dirname(n);a!==r&&this.#i(a,this.dmode)}let o;try{o=s.lstatSync(n)}catch{}if(!(o&&this.skip(e,o))){if(o&&!this.isReusable(e,o)&&(o.isDirectory()&&ae.has(e.type)?this.chmod&&e.mode&&(o.mode&4095)!==e.mode&&s.chmodSync(n,e.mode):n!==r&&(o.isDirectory()?s.rmdirSync(n):this.#r(n))),qe.has(e.type))return this.#a(e,n,t);if(ae.has(e.type))this.#o(e,n);else{this.#s(this.linkParts(e,n));let a=String(e.linkpath);e.type==="Link"?s.linkSync(this.resolve(r,a),n):s.symlinkSync(a,n)}this.#s(this.parentParts(n))}}#r(e){let t=this.#e;if(!this.win32)return t.unlinkSync(e);let s=gi(e);t.renameSync(e,s),t.unlinkSync(s)}#s(e){if(this.preservePaths)return;let t=this.cwd;for(let s of e){t=this.resolve(t,s);let n;try{n=this.#e.lstatSync(t)}catch{return}if(n.isSymbolicLink())throw this.symlinkError(t,e)}}#o(e,t){let s=this.#e;this.#i(t,e.mode??this.dmode);let n=this.times(e);if(n)try{s.lutimesSync(t,n.atime,n.mtime)}catch{}let r=this.owner(e);if(r)try{s.lchownSync(t,r.uid,r.gid)}catch{}}#a(e,t,s){let n=this.#e,r=n.openSync(t,this.writeFlag(e.size),e.mode??this.fmode);try{this.#s(this.parentParts(t));let o=this.opt.transform?.(e);for(;;){let h;try{h=s.readBody(e)}catch(l){throw this.fail(l)}if(!h)break;n.writeSync(r,o?o(h):h)}let a=this.times(e);if(a){let{atime:h,mtime:l}=a;try{n.futimesSync(r,h,l)}catch(d){try{n.utimesSync(t,h,l)}catch{throw d}}}let c=this.owner(e);if(c){let{uid:h,gid:l}=c;try{n.fchownSync(r,h,l)}catch(d){try{n.chownSync(t,h,l)}catch{throw d}}}}catch(o){try{n.closeSync(r)}catch{}throw o}n.closeSync(r)}};var xi=()=>new TypeError("extract needs input or file"),Ke=async(i,e)=>{let t=y(i),s=t.input??(t.file?H(t.fs,t.file,t.maxReadSize):void 0);if(!s)throw xi();let[n,r]=e?.length?J(e,t.filter):[];n&&(t.filter=n),await new Ae(t).extract(s),r?.(t)},ki=(i,e)=>{let t=y(i),s=t.input??(t.file?$(t.fs,t.file,t.maxReadSize):void 0);if(!s)throw xi();let[n,r]=e?.length?J(e,t.filter):[];n&&(t.filter=n),new Te(t).extract(s),r?.(t)};var Si=64*1024,bi={},Es=()=>{},Xe=()=>new Error("cannot append to compressed archives"),Ei=(i,e)=>{let{file:t}=i;if(!t)throw new TypeError("file is required");if(i.gzip||i.brotli||i.zstd||t.endsWith(".br")||t.endsWith(".tbr"))throw new TypeError(Xe().message);if(!e?.length)throw new TypeError("no paths specified to add/replace")},Oe=class{buf=new Uint8Array(Si);pos=0;#e;#t;#i;#n;constructor(e,t=[],s){this.#e=e,this.#i=[...t,T],this.#n=s,this.#t=new B({filter:()=>!1,onwarn:(n,r,o)=>{throw o instanceof Error?o:bi}})}get position(){return this.#t.position}get want(){return Math.min(Si,this.#e-this.pos)}push(e){let t=this.buf.subarray(0,e);if(this.pos===0&&this.#i.some(r=>r.detect(t)))throw Xe();let s=this.#t;this.pos+=e;let n=0;s.push(t);try{for(let r;r=s.next();){if(r.type!=="entry")return!1;let{entry:o}=r;if(n=s.offset+512*Math.ceil(o.size/512),n>this.#e)return!1;o.mtime&&this.#n?.set(o.path,o.mtime)}this.pos<n&&(s.skipBody(),this.pos=n)}catch(r){if(r!==bi)throw r;return!1}return e>0&&this.pos<this.#e}},ce=async(i,e)=>{let t=y(i);Ei(t,e);let{fs:s,file:n}=t,r=We(t,e);if(r.codec)throw new TypeError(Xe().message);let o=await s.open(n,"r+").catch(c=>{if(c?.code!=="ENOENT")throw c;return s.open(n,"w+",t.mode||438)}),a=!1;try{let{size:c}=await o.stat(),h=new Oe(c,t.codecs,t.mtimeCache);for(;h.push((await o.read(h.buf,0,h.want,h.pos)).bytesRead););await wt(o,r,h.position),a=!0}finally{let c=o.close();await(a?c:c.catch(Es))}},Ze=(i,e)=>{let t=y(i);Ei(t,e);let{fs:s,file:n}=t,r=gt(t,e);if(r.codec)throw new TypeError(Xe().message);let o;try{o=s.openSync(n,"r+")}catch(a){if(a?.code!=="ENOENT")throw a;o=s.openSync(n,"w+",t.mode||438)}try{let{size:a}=s.fstatSync(o),c=new Oe(a,t.codecs,t.mtimeCache);for(;c.push(s.readSync(o,c.buf,0,c.want,c.pos)););yt(s,o,r,c.position)}catch(a){try{s.closeSync(o)}catch{}throw a}s.closeSync(o)};var vs=(i,e)=>{let t=e.getTime(),s=i.getTime();return(t%1e3===0?s-s%1e3:s)>t},vi=i=>{let{filter:e}=i,t=i.mtimeCache??new Map;return{...i,mtimeCache:t,filter:(s,n)=>{if(e&&!e(s,n))return!1;if("isDirectory"in n&&n.isDirectory())return!0;let r=t.get(s);return!r||!n.mtime||vs(n.mtime,r)}}},Je=(i,e)=>ce(vi(i),e),Ri=(i,e)=>Ze(vi(i),e);import{constants as As}from"node:buffer";import*as Ts from"node:zlib";var Qe=64*1024,et=(i,e=!1,t)=>{let s,n,r=!1,o=!1,a,c,h=e?new Uint8Array(Qe):void 0,l=0,d=m=>new Promise(u=>{a=u,i.write(m,()=>u())}),p=async m=>{l&&await d(m.subarray(0,l)),l=0},f=()=>{o=!0,a?.(),c?.()},w=()=>{f(),i.destroy()};return i.pause(),i.on("data",m=>{t?.(m),t=void 0,r=!1,i.pause(),s.enqueue(m)}),i.on("end",()=>{o||s.close()}),i.on("error",m=>{s.error(m),n.error(m),f()}),i.on("close",f),{readable:new ReadableStream({start:m=>{s=m},pull:()=>{r=!0,c?.(),i.resume()},cancel:m=>{n.error(m),w()}},{highWaterMark:0}),writable:new WritableStream({start:m=>{n=m;let{signal:u}=m;u.addEventListener("abort",()=>{s.error(u.reason),w()})},write:async m=>{h?(l+m.length>Qe&&await p(h),m.length>Qe?await d(m):(h.set(m,l),l+=m.length)):await d(m),!r&&!o&&await new Promise(u=>c=u)},close:async()=>{h&&await p(h),await new Promise(m=>{a=m,i.end()})}})}},Os=i=>i>=As.MAX_LENGTH?{}:{maxOutputLength:Math.max(1,Math.floor(i))},St=(i,e,t,s,n)=>({...i,decompress:()=>et(t({chunkSize:Qe})),compress:r=>et(e(r),!0),decompressSync:(r,{maxOutputLength:o})=>{try{return n(r,Os(o))}catch(a){throw a?.code!=="ERR_BUFFER_TOO_LARGE"?a:new Error(`max decompression ratio exceeded: the output is larger than ${o} bytes`)}},compressSync:s}),Ai=i=>{i[9]=255},bt=(i=Ts)=>{let{createBrotliCompress:e,createBrotliDecompress:t,brotliCompressSync:s,brotliDecompressSync:n,createZstdCompress:r,createZstdDecompress:o,zstdCompressSync:a,zstdDecompressSync:c}=i,l=[{...St({name:"gzip",headLength:2,detect:d=>d[0]===31&&d[1]===139},i.createGzip,i.createGunzip,i.gzipSync,i.gunzipSync),compress:({portable:d,...p}={})=>et(i.createGzip(p),!0,d?Ai:void 0),compressSync:(d,{portable:p,...f}={})=>{let w=i.gzipSync(d,f);return p&&Ai(w),w}}];return e&&t&&s&&n&&l.push(St({name:"brotli",headLength:0,detect:()=>!1,extensions:[".tar.br",".tbr"]},e,t,s,n)),r&&o&&a&&c&&l.push(St({name:"zstd",headLength:4,detect:d=>d[0]===40&&d[1]===181&&d[2]===47&&d[3]===253},r,o,a,c)),l};var Q=zs,ee=Ps,Ns=process.platform==="win32"?"win32":"posix",Us=bt(),x=(i,e,t)=>{let s=y(i);return s.fs??=e,s.platform??=Ns,s.codecs=[...s.codecs??[],...Us],t&&(s.cwd=Fs(s.cwd??""),s.processUid??=process.getuid?.(),s.processGid??=process.getgid?.(),s.processUname??=process.env.USER,s.chmod&&(s.processUmask??=process.umask())),s},ko=(i,e={})=>lt(i,x(e,Q,!1)),So=(i,e={})=>Bt(i,x(e,ee,!1)),bo=(i,e)=>Ve(x(i,Q,!1),e),Eo=(i,e)=>ni(x(i,ee,!1),e),vo=(i,e)=>Ke(x(i,Q,!0),e),Ro=(i,e)=>ki(x(i,ee,!0),e);function Ao(i,e){return ne(x(i,Q,!0),e)}function To(i,e){return Ye(x(i,ee,!0),e)}var Oo=(i,e)=>ce(x(i,Q,!0),e),Po=(i,e)=>Ze(x(i,ee,!0),e),zo=(i,e)=>Je(x(i,Q,!0),e),Fo=(i,e)=>Ri(x(i,ee,!0),e),No=(i,e)=>xt(x(i,Q,!1),e),Uo=(i,e)=>ai(x(i,ee,!1),e);export{Oe as AppendScan,re as CwdError,ue as EntryCursor,q as EntryData,R as Header,Se as Pack,ke as PackBase,F as PackJob,be as PackSync,B as Parser,ve as PathReservations,I as Pax,fe as ReadEntry,me as ReadEntrySync,G as SymlinkError,b as TarReader,E as TarReaderSync,Ae as Unpack,Re as UnpackBase,Te as UnpackSync,se as WriteEntry,Ot as aliases,Ao as c,et as codecStream,Ao as create,To as createSync,No as delete,Uo as deleteSync,ko as entries,So as entriesSync,vo as extract,Ro as extractSync,T as gzip,bo as list,Eo as listSync,Oo as r,Oo as replace,Po as replaceSync,bo as t,nt as types,zo as u,zo as update,Fo as updateSync,vo as x,bt as zlibCodecs};
1
+ var Ti=Object.defineProperty;var Oi=(i,e)=>{for(var t in e)Ti(i,t,{get:e[t],enumerable:!0})};import*as Ps from"node:fs";import*as zs from"node:fs/promises";import{resolve as Fs}from"node:path";var v=i=>ArrayBuffer.isView(i)&&i[Symbol.toStringTag]==="Uint8Array",tt=i=>Object.prototype.toString.call(i)==="[object ArrayBuffer]",N=i=>typeof i?.size=="number"&&typeof i.stream=="function",Pe=i=>typeof i?.getReader=="function",Pi=new TextDecoder("utf-8",{ignoreBOM:!0}),zi=new TextEncoder,A=i=>{let e=i.length;for(let t=0;t<i.length;t++){let s=i.charCodeAt(t);s<128||(s<2048?e+=1:s>=55296&&s<=56319&&(i.charCodeAt(t+1)&64512)===56320?(e+=2,t++):e+=2)}return e},U=(i,e=0,t=i.length)=>{let s="";for(let n=e;n<t;n++){let r=i[n];if(r>=128)return Pi.decode(i.subarray(e,t));s+=String.fromCharCode(r)}return s},ze=(i,e,t,s)=>{let{written:n}=zi.encodeInto(i,e.subarray(t,t+s));e.fill(0,t+n,t+s)},it=(i,e,t)=>{for(let s=0;s<i.length;s++)e[t+s]=i.charCodeAt(s)};var vt=(i,e)=>{if(Number.isSafeInteger(i))i<0?Ni(i,e):Fi(i,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},Fi=(i,e)=>{e[0]=128;for(var t=e.length;t>1;t--)e[t-1]=i&255,i=Math.floor(i/256)},Ni=(i,e)=>{e[0]=255;var t=!1;i=i*-1;for(var s=e.length;s>1;s--){var n=i&255;i=Math.floor(i/256),t?e[s-1]=At(n):n===0?e[s-1]=0:(t=!0,e[s-1]=Tt(n))}},Rt=i=>{let e=i[0],t=e===128?Ci(i.subarray(1,i.length)):e===255?Ui(i):null;if(t===null)throw Error("invalid base256 encoding");if(!Number.isSafeInteger(t))throw Error("parsed number outside of javascript safe integer range");return t},Ui=i=>{for(var e=i.length,t=0,s=!1,n=e-1;n>-1;n--){var r=Number(i[n]),o;s?o=At(r):r===0?o=r:(s=!0,o=Tt(r)),o!==0&&(t-=o*Math.pow(256,e-n-1))}return t},Ci=i=>{for(var e=i.length,t=0,s=e-1;s>-1;s--){var n=Number(i[s]);n!==0&&(t+=n*Math.pow(256,e-s-1))}return t},At=i=>(255^i)&255,Tt=i=>(255^i)+1&255;var he=i=>{let e=i.charCodeAt(0)===47,t=[];for(let r of i.split("/"))r===""||r==="."||(r!==".."?t.push(r):t.length&&t[t.length-1]!==".."?t.pop():e||t.push(r));let s=t.length&&i.charCodeAt(i.length-1)===47,n=t.join("/")+(s?"/":"");return e?"/"+n:n||(i.endsWith("/")?"./":".")},W=(...i)=>he(i.filter(e=>e).join("/")),P=i=>{let e=i.length;for(;e>1&&i.charCodeAt(e-1)===47;)e--;let t=i.lastIndexOf("/",e-1);return t===-1?".":t===0?"/":t===1&&i.charCodeAt(0)===47?"//":i.slice(0,t)},le=i=>{let e=i.length;for(;e>0&&i.charCodeAt(e-1)===47;)e--;return i.slice(i.lastIndexOf("/",e-1)+1,e)},te=i=>i.charCodeAt(0)===47,C=(...i)=>{let e="";for(let s=i.length-1;s>=0&&!te(e);s--){let n=i[s];n&&(e=e?n+"/"+e:n)}let t=he(e);return t.length>1&&t.endsWith("/")?t.slice(0,-1):t},L=(i,e)=>{let t=C(i).split("/"),s=C(e).split("/");t[t.length-1]||t.pop(),s[s.length-1]||s.pop();let n=0;for(;n<t.length&&n<s.length&&t[n]===s[n];)n++;return[...Array.from({length:t.length-n},()=>".."),...s.slice(n)].join("/")};var nt={};Oi(nt,{code:()=>Fe,isCode:()=>de,isName:()=>Di,name:()=>pe,normalFsTypes:()=>st});var de=i=>pe.has(i),Di=i=>Fe.has(i),st=new Set(["0","","1","2","3","4","5","6","7","D"]),pe=new Map([["0","File"],["","OldFile"],["1","Link"],["2","SymbolicLink"],["3","CharacterDevice"],["4","BlockDevice"],["5","Directory"],["6","FIFO"],["7","ContiguousFile"],["g","GlobalExtendedHeader"],["x","ExtendedHeader"],["A","SolarisACL"],["D","GNUDumpDir"],["I","Inode"],["K","NextFileHasLongLinkpath"],["L","NextFileHasLongPath"],["M","ContinuationFile"],["N","OldGnuLongPath"],["S","SparseFile"],["V","TapeVolumeHeader"],["X","OldExtendedHeader"]]),Fe=new Map(Array.from(pe).map(i=>[i[1],i[0]]));var _i=i=>i===void 0||i<0?void 0:i,R=class{cksumValid=!1;needPax=!1;nullBlock=!1;block;path;mode;uid;gid;size;cksum;#e="Unsupported";linkpath;uname;gname;devmaj=0;devmin=0;atime;ctime;mtime;charset;comment;constructor(e,t=0,s,n){v(e)?this.decode(e,t||0,s,n):e&&this.#t(e)}decode(e,t,s,n){if(t||(t=0),!e||!(e.length>=t+512))throw new Error("need 512 bytes for header");let r=D(e,t+156,1),o=st.has(r),a=o?s:void 0,c=o?n:void 0;if(this.path=a?.path??D(e,t,100),this.mode=a?.mode??c?.mode??_(e,t+100,8),this.uid=a?.uid??c?.uid??_(e,t+108,8),this.gid=a?.gid??c?.gid??_(e,t+116,8),this.size=_i(a?.size??_(e,t+124,12)),this.mtime=a?.mtime??c?.mtime??rt(e,t+136,12),this.cksum=_(e,t+148,12),c&&this.#t(c,!0),a&&this.#t(a),de(r)&&(this.#e=r||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=D(e,t+157,100),U(e,t+257,t+265)==="ustar\x0000")if(this.uname=a?.uname??c?.uname??D(e,t+265,32),this.gname=a?.gname??c?.gname??D(e,t+297,32),this.devmaj=a?.devmaj??c?.devmaj??_(e,t+329,8)??0,this.devmin=a?.devmin??c?.devmin??_(e,t+337,8)??0,e[t+475]!==0){let l=D(e,t+345,155);this.path=l+"/"+this.path}else{let l=D(e,t+345,130);l&&(this.path=l+"/"+this.path),this.atime=s?.atime??n?.atime??rt(e,t+476,12),this.ctime=s?.ctime??n?.ctime??rt(e,t+488,12)}let h=256;for(let l=t;l<t+148;l++)h+=e[l];for(let l=t+156;l<t+512;l++)h+=e[l];this.cksumValid=h===this.cksum,this.cksum===void 0&&h===256&&(this.nullBlock=!0)}#t(e,t=!1){Object.assign(this,Object.fromEntries(Object.entries(e).filter(([s,n])=>!(n==null||s==="size"&&(t||Number(n)<0)||s==="path"&&t||s==="linkpath"&&t||s==="global"))))}encode(e,t=0){if(e||(e=this.block=new Uint8Array(512)),this.#e==="Unsupported"&&(this.#e="0"),!(e.length>=t+512))throw new Error("need 512 bytes for header");let s=this.ctime||this.atime?130:155,n=Mi(this.path||"",s),r=n[0],o=n[1];this.needPax=!!n[2],this.needPax=Y(e,t,100,r)||this.needPax,this.needPax=M(e,t+100,8,this.mode)||this.needPax,this.needPax=M(e,t+108,8,this.uid)||this.needPax,this.needPax=M(e,t+116,8,this.gid)||this.needPax,this.needPax=M(e,t+124,12,this.size)||this.needPax,this.needPax=ot(e,t+136,12,this.mtime)||this.needPax,e[t+156]=Number(this.#e.codePointAt(0)),this.needPax=Y(e,t+157,100,this.linkpath)||this.needPax,it("ustar\x0000",e,t+257),this.needPax=Y(e,t+265,32,this.uname)||this.needPax,this.needPax=Y(e,t+297,32,this.gname)||this.needPax,this.needPax=M(e,t+329,8,this.devmaj)||this.needPax,this.needPax=M(e,t+337,8,this.devmin)||this.needPax,this.needPax=Y(e,t+345,s,o)||this.needPax,e[t+475]!==0?this.needPax=Y(e,t+345,155,o)||this.needPax:(this.needPax=Y(e,t+345,130,o)||this.needPax,this.needPax=ot(e,t+476,12,this.atime)||this.needPax,this.needPax=ot(e,t+488,12,this.ctime)||this.needPax);let a=256;for(let c=t;c<t+148;c++)a+=e[c];for(let c=t+156;c<t+512;c++)a+=e[c];return this.cksum=a,M(e,t+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:pe.get(this.#e)}get typeKey(){return this.#e}set type(e){let t=String(Fe.get(e));if(de(t)||t==="Unsupported")this.#e=t;else if(de(e))this.#e=e;else throw new TypeError("invalid entry type: "+e)}},Mi=(i,e)=>{let s=i,n="",r,o=i.charAt(0)==="/"?"/":".";if(A(s)<100)r=[s,n,!1];else{n=P(s),s=le(s);do A(s)<=100&&A(n)<=e?r=[s,n,!1]:A(s)>100&&A(n)<=e?r=[s.slice(0,99),n,!0]:(s=W(le(n),s),n=P(n));while(n!==o&&r===void 0);r||(r=[i.slice(0,99),"",!0])}return r},D=(i,e,t)=>{let s=e,n=Math.min(e+t,i.length);for(;s<n&&i[s]!==0;)s++;return U(i,e,s)},rt=(i,e,t)=>Ii(_(i,e,t)),Ii=i=>i===void 0?void 0:new Date(i*1e3),_=(i,e,t)=>Number(i[e])&128?Rt(i.subarray(e,e+t)):Hi(i,e,t),Bi=i=>isNaN(i)?void 0:i,Hi=(i,e,t)=>Bi(parseInt(D(i,e,t).trim(),8)),$i={12:8589934591,8:2097151},M=(i,e,t,s)=>s===void 0?!1:s>$i[t]||s<0?(vt(s,i.subarray(e,e+t)),!0):(ji(i,e,t,s),!1),ji=(i,e,t,s)=>it(Gi(s,t),i,e),Gi=(i,e)=>Wi(Math.floor(i).toString(8),e),Wi=(i,e)=>(i.length===e-1?i:"0".repeat(e-i.length-2)+i+" ")+"\0",ot=(i,e,t,s)=>s===void 0?!1:M(i,e,t,s.getTime()/1e3),Y=(i,e,t,s)=>s===void 0?!1:(ze(s,i,e,t),s.length!==A(s)||s.length>t);var Yi=/^\d+$/,I=class i{atime;mtime;ctime;charset;comment;gid;uid;gname;uname;linkpath;dev;ino;nlink;path;size;mode;global;constructor(e,t=!1){this.atime=e.atime,this.charset=e.charset,this.comment=e.comment,this.ctime=e.ctime,this.dev=e.dev,this.gid=e.gid,this.global=t,this.gname=e.gname,this.ino=e.ino,this.linkpath=e.linkpath,this.mtime=e.mtime,this.nlink=e.nlink,this.path=e.path,this.size=e.size,this.uid=e.uid,this.uname=e.uname}encode(){let e=this.encodeBody();if(e==="")return new Uint8Array(0);let t=A(e),s=512*Math.ceil(1+t/512),n=new Uint8Array(s);return new R({path:("PaxHeader/"+le(this.path??"")).slice(0,99),mode:this.mode||420,uid:this.uid,gid:this.gid,size:t,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(n),ze(e,n,512,t),n}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(e){if(this[e]===void 0)return"";let t=this[e],s=typeof t=="object"?t.getTime()/1e3:t,n=" "+(e==="dev"||e==="ino"||e==="nlink"?"SCHILY.":"")+e+"="+s+`
2
+ `,r=A(n),o=Math.floor(Math.log(r)/Math.log(10))+1;return r+o>=Math.pow(10,o)&&(o+=1),o+r+n}static parse(e,t,s=!1){return i.parseBytes(new TextEncoder().encode(e),t,s)}static parseBytes(e,t,s=!1){return new i(Vi(qi(e),t),s)}},Vi=(i,e)=>e?Object.assign({},e,i):i,qi=i=>{let e=Object.create(null),t=0;for(;t<i.length;){let s=t;for(;s<i.length&&i[s]>=48&&i[s]<=57;)s++;if(s===t||i[s]!==32)break;let n=Number(U(i,t,s)),r=t+n;if(r<=s+1||r>i.length||i[r-1]!==10)break;Ki(e,U(i,s+1,r-1)),t=r}return e},Ki=(i,e)=>{let t=e.split("="),s=t.shift();if(!s)return i;let n=s.replace(/^SCHILY\.(dev|ino|nlink)/,"$1"),r=t.join("="),o=r.indexOf("\0"),a=o===-1?r:r.slice(0,o);switch(n){case"path":case"linkpath":case"type":case"charset":case"comment":case"gname":case"uname":i[n]=a;break;case"ctime":case"atime":case"mtime":let c=new Date(Number(a)*1e3);isNaN(c.getTime())||(i[n]=c);break;case"size":case"gid":case"uid":case"dev":case"ino":case"nlink":case"mode":if(!Yi.test(a.trim()))break;let h=+a;if(!Number.isSafeInteger(h))break;i[n]=h;break}return i};var T={name:"gzip",headLength:2,detect:i=>i[0]===31&&i[1]===139,decompress:()=>new DecompressionStream("gzip"),compress:i=>{let e=new CompressionStream("gzip");if(!i?.portable)return e;let t=0;return{writable:e.writable,readable:e.readable.pipeThrough(new TransformStream({transform:(s,n)=>{t<=9&&t+s.length>9&&(s[9-t]=255),t+=s.length,n.enqueue(s)}}))}}};var Ot={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:"onEntry",onReadEntry:"onEntry"},y=i=>{let e=Object.assign(Object.create(null),i);for(let[t,s]of Object.entries(Ot))e[t]!==void 0&&(e[s]??=e[t]),delete e[t];return e.noChmod===!1&&(e.chmod??=!0),delete e.noChmod,e};var z=i=>{if(i.length===1)return i[0].slice();let e=0;for(let n of i)e+=n.length;let t=new Uint8Array(e),s=0;for(let n of i)t.set(n,s),s+=n.length;return t};var k=(i,e)=>Object.assign(Object.create(null),i,e),V=(i,e,t)=>{if(e==null||e===0)return t;if(e===1/0||Number.isInteger(e)&&Number(e)>0)return e;throw new TypeError(`${i} must be a positive integer`)};var Xi=new Set(["File","OldFile","Link","SymbolicLink","CharacterDevice","BlockDevice","Directory","FIFO","ContiguousFile","GNUDumpDir"]),Ne=i=>i.replaceAll("\\","/"),q=class{header;extended;globalExtended;type;path;mode;uid;gid;uname;gname;size;mtime;atime;ctime;linkpath;devmaj;devmin;dev;ino;nlink;absolute;ignore;invalid=!1;unsupported=!1;constructor(e,t,s,n=!1){if(!e.path)throw new Error("no path provided for tar.ReadEntry");this.header=e,this.extended=t,this.globalExtended=s,this.type=e.type,this.ignore=!Xi.has(this.type),this.path=n?Ne(e.path):e.path,this.mode=e.mode&&e.mode&4095,this.uid=e.uid,this.gid=e.gid,this.uname=e.uname,this.gname=e.gname,this.size=e.size??0,this.mtime=e.mtime,this.atime=e.atime,this.ctime=e.ctime,this.linkpath=e.linkpath?n?Ne(e.linkpath):e.linkpath:void 0,this.devmaj=e.devmaj,this.devmin=e.devmin,s&&this.#e(s),t&&(this.#e(t),t.path!=null&&(this.path=n?Ne(t.path):t.path),t.linkpath!=null&&(this.linkpath=n?Ne(t.linkpath):t.linkpath))}#e(e){e.uid!=null&&(this.uid=e.uid),e.gid!=null&&(this.gid=e.gid),e.uname!=null&&(this.uname=e.uname),e.gname!=null&&(this.gname=e.gname),e.mtime!=null&&(this.mtime=e.mtime),e.atime!=null&&(this.atime=e.atime),e.ctime!=null&&(this.ctime=e.ctime),e.dev!=null&&(this.dev=e.dev),e.ino!=null&&(this.ino=e.ino),e.nlink!=null&&(this.nlink=e.nlink)}},Pt=new TextDecoder,zt=i=>{let e="";for(let t of i)e+=Pt.decode(t,{stream:!0});return e+Pt.decode()},Ft=()=>new TypeError("Body has already been consumed"),fe=class extends q{#e;#t=!1;#i;constructor(e,t,s,n,r){super(e,t,s,n),this.#e=r}get bodyUsed(){return this.#t}get body(){if(this.#i)return this.#i;let e=!1;return this.#i=new ReadableStream({pull:async t=>{e||(this.#s(),e=!0);let[s]=await this.#n(1);s?t.enqueue(s):t.close()}},{highWaterMark:0})}#s(){if(this.#t)throw Ft();this.#t=!0}#r(e,t=1/0){let s=this.#e;for(;s&&e.length<t;){let n=s.readBody(this);if(n===null)break;if(n===void 0)return!1;e.push(n)}return!0}async#n(e){let t=[];for(;!this.#r(t,e);)await this.#e?.fill();return t}async bytes(){this.#s();let e=[];for(;!this.#r(e);)await this.#e?.fill();return z(e)}async arrayBuffer(){return(await this.bytes()).buffer}async text(){return this.#s(),zt(await this.#n())}async blob(){return this.#s(),new Blob(await this.#n())}},ue=class extends q{#e;#t=!1;#i;constructor(e,t,s,n,r){super(e,t,s,n),this.#e=r}get bodyUsed(){return this.#t}get body(){return this.#i??=this.#s()}*#s(){this.#r();for(let e;e=this.#e?.readBody(this);)yield e}#r(){if(this.#t)throw Ft();this.#t=!0}#n(){this.#r();let e=[];for(let t;t=this.#e?.readBody(this);)e.push(t);return e}bytes(){return z(this.#n())}arrayBuffer(){return this.bytes().buffer}text(){return zt(this.#n())}};var Nt=(i,e,t,s)=>(i.file&&(s.file=i.file),s.code=typeof t=="object"&&t.code||e,s.tarCode=e,s),at=(i,e,t,s={})=>Object.assign(typeof t=="object"?t:new Error(`${e}: ${t}`),Nt(i,e,t,s)),S=(i,e,t,s={})=>{let n=Object.hasOwn(s,"recoverable")&&s.recoverable===!1;if(i.strict||n)throw at(i,e,t,s);Nt(i,e,t,s),typeof t=="object"&&(s=Object.assign(t,s),t=t.message),i.onwarn?.(e,t,s)};var Ut=0,ie=1,Ue=2,Ce=3,Ct=4,ct={type:"entryEnd"},Zi={type:"end"},Ji=new Set(["ExtendedHeader","OldExtendedHeader","GlobalExtendedHeader","NextFileHasLongPath","OldGnuLongPath","NextFileHasLongLinkpath"]),Lt=i=>{let e=i.indexOf(0);return U(i,0,e===-1?i.length:e)},B=class{maxMetaEntrySize;position=0;offset=0;#e;#t;#i;#s=[];#r;#n=0;#o;#a=0;#c=Ut;#h;#d;#w;#y=0;#p=0;#l=0;#u;#g;#b;#x;#k=!1;#m;#f=!1;#S=0;constructor(e={},t){e=this.#e=k(e),this.maxMetaEntrySize=e.maxMetaEntrySize||1024*1024,this.#t=e.filter;let s=e.platform==="win32";this.#i=t??((n,r,o)=>new q(n,r,o,s))}warn(e,t,s){S(this.#e,e,t,s)}push(e){this.#k||this.#s.push(e)}end(){this.#k=!0}get bodyRemain(){let e=this.#r,t=this.#c;return t!==Ue&&t!==Ce||this.#s.length||e&&this.#n<e.length?0:this.#l}skipBody(){this.#f=this.#c===Ue,this.offset+=this.#l,this.#p=this.#l=0,this.#E()}next(){if(this.#f)return this.#f=!1,ct;for(;;){let e=this.#r,t=this.#n;if(!e||t===e.length){if(e=this.#r=this.#s.shift(),t=this.#n=0,!e){if(!this.#k||this.#S===2)return;let l=this.#R();if(l)return l}continue}let s=e.length-t,n=this.#c;if(n<=ie){let l;if(this.#a===0&&s>=512)this.#n=t+512,l=this.#v(e,t);else{let d=this.#o??=new Uint8Array(512),p=Math.min(512-this.#a,s);if(d.set(e.subarray(t,t+p),this.#a),this.#n=t+p,this.#a+=p,this.#a<512)continue;this.#a=0,l=this.#v(d,0)}if(l)return l;continue}let r=this.#l,o=s<r?s:r,a=this.#p,c=o<a?o:a;this.#n=t+o,this.offset+=o,this.#l=r-o,this.#p=a-c;let h=o===r;if(n===Ct){let l=this.#w;l.set(e.subarray(t,t+c),this.#y),this.#y+=c,h&&(this.#E(),this.#A(l));continue}if(h&&this.#E(),n!==Ce){if(c===0){if(h)return ct;continue}return this.#f=h,{type:"body",data:c===e.length?e:e.subarray(t,t+c)}}}}#E(){let e=this.#h;e&&(this.position=this.offset,this.#h=void 0),e?.invalid||(this.#m=!0),this.#c=ie}#R(){let e=this.#c;if(e>ie){let t=this.#h,s=(512-this.#l%512)%512,n=this.#l+s;this.#h=void 0,this.#w=void 0,this.#c=ie,t?.invalid||(this.#m=!0),this.#f=e===Ue,this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${n} more bytes, only ${s} available)`,{entry:t,header:this.#d});return}return this.#f?(this.#f=!1,ct):(this.#S===0&&(this.#S=1,(e===Ut||this.#m===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")),this.#S=2,Zi)}#v(e,t){this.offset+=512,this.#m===void 0&&(this.#m=!1);let s=this.#u,n=this.#g,r=this.#b;(n!==void 0||r!==void 0)&&(s=Object.assign(Object.create(null),s),s.path??=n,s.linkpath??=r);let o;try{o=new R(e,t,s,this.#x)}catch(d){this.warn("TAR_ENTRY_INVALID",d);return}if(o.nullBlock){this.#k=!0,this.#r=void 0,this.#s.length=0,this.#a=0,this.#c=ie;return}if(!o.cksumValid){this.warn("TAR_ENTRY_INVALID","checksum failure",{header:o});return}if(!o.path){this.warn("TAR_ENTRY_INVALID","path is required",{header:o});return}let a=o.type,c=a==="Link"||a==="SymbolicLink";if(c&&!o.linkpath){this.warn("TAR_ENTRY_INVALID","linkpath required",{header:o});return}if(!c&&o.linkpath&&a!=="ExtendedHeader"&&a!=="GlobalExtendedHeader"){this.warn("TAR_ENTRY_INVALID","linkpath forbidden",{header:o});return}let h=o.size??0;if(this.#d=o,this.#p=h,this.#l=512*Math.ceil(h/512),h||(this.#m=!0),Ji.has(a)){h>this.maxMetaEntrySize?this.#c=Ce:h>0&&(this.#w=new Uint8Array(h),this.#y=0,this.#c=Ct);return}this.#u=this.#g=this.#b=void 0;let l=this.#i(o,s,this.#x);return!l.ignore&&this.#t&&!this.#t(l.path,l)&&(l.ignore=!0),h?(this.#h=l,this.#c=l.ignore?Ce:Ue):(this.#c=ie,this.position=this.offset,this.#f=!l.ignore),{type:"entry",entry:l}}#A(e){switch(this.#d.type){case"ExtendedHeader":case"OldExtendedHeader":this.#u=I.parseBytes(e,this.#u,!1);break;case"GlobalExtendedHeader":this.#x=I.parseBytes(e,this.#x,!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":this.#g=Lt(e);break;default:this.#b=Lt(e)}}};var Qi=16*1024*1024,Dt=64*1024,es=1024*1024,De=Symbol.for("tar.readFile.skip"),Le=class{pos=0;size=0;#e;#t=Dt;constructor(e){this.#e=V("maxReadSize",e,Qi)}next(){let e=Math.min(this.#t,this.#e,this.size-this.pos);return this.#t*=2,e}skip(e){return e<es||this.pos+e>this.size?!1:(this.pos+=e,this.#t=Dt,!0)}};async function*ts(i,e,t){let s=await i.open(e,"r");try{t.size=(await s.stat()).size;for(let n;n=t.next();){let r=new Uint8Array(n),{bytesRead:o}=await s.read(r,0,n,t.pos);if(!o)break;t.pos+=o,yield o<n?r.subarray(0,o):r}}finally{await s.close().catch(()=>{})}}function*is(i,e,t){let s=i.openSync(e,"r");try{t.size=i.fstatSync(s).size;for(let n;n=t.next();){let r=new Uint8Array(n),o=i.readSync(s,r,0,n,t.pos);if(!o)break;t.pos+=o,yield o<n?r.subarray(0,o):r}}finally{try{i.closeSync(s)}catch{}}}var H=(i,e,t)=>{let s=new Le(t);return Object.assign(ts(i,e,s),{[De]:n=>s.skip(n)})},$=(i,e,t)=>{let s=new Le(t);return Object.assign(is(i,e,s),{[De]:n=>s.skip(n)})};var ht=()=>{},we=i=>Math.max(512,...i.map(e=>e.headLength)),ss=i=>{try{let e=new R(i);return e.cksumValid||e.nullBlock}catch{return!1}},ye=(i,e,t="")=>i.find(s=>s.detect(e))??(ss(e)?void 0:i.find(s=>s.extensions?.some(n=>t.endsWith(n)))),_t=i=>typeof i.maxDecompressionRatio=="number"?i.maxDecompressionRatio:1e3,_e=(i,e)=>at(i,"TAR_ABORT",e,{recoverable:!1}),Mt=(i,e,t)=>_e(i,new Error(`max decompression ratio exceeded: ${e.toFixed(2)} > ${t}`)),ns=()=>new TypeError("The body of an entry cannot be read after a later entry"),me=class{parser;current;ended=!1;constructor(e){this.parser=e}entry(){if(this.current=void 0,this.ended)return null;for(let e;e=this.parser.next();){if(e.type==="end")return this.ended=!0,null;if(e.type==="entry"&&!e.entry.ignore)return this.current=e.entry}}body(e){if(e!==this.current)throw ns();let t=this.parser.next();if(t)return t.type==="body"?t.data:(this.current=void 0,null)}},It=(i,e)=>{if(i.current)return;let t=i.parser.bodyRemain;t&&e[De]?.(t)&&i.parser.skipBody()},rs=i=>{if(v(i))return[i].values();if(tt(i))return[new Uint8Array(i)].values();if(N(i)&&(i=i.stream()),Pe(i)){let e=i.getReader();return{next:()=>e.read(),return:()=>e.cancel()}}return Symbol.asyncIterator in i?i[Symbol.asyncIterator]():i[Symbol.iterator]()},b=class{parser;#e;#t;#i;#s;#r;#n;#o=!1;constructor(e,t={}){t=k(t);let s=t.platform==="win32";this.parser=new B(t,(n,r,o)=>new fe(n,r,o,s,this)),this.#e=new me(this.parser),this.#t=t,this.#i=rs(e)}poll(){return this.#o?null:this.#e.entry()}readBody(e){return this.#e.body(e)}fill(){return this.#n??=this.#a()}async#a(){try{let e=this.#s??=await this.#c(this.#i),t=this.#r;this.#r=void 0,e===this.#i&&It(this.#e,e);let s=t?{value:t,done:!1}:await e.next();s.done?this.parser.end():this.parser.push(s.value)}finally{this.#n=void 0}}async#c(e){let t=this.#t,s=[...t.codecs??[],T],n=we(s),r;for(;!r||r.length<n;){let m=await e.next();if(m.done)break;r=r?z([r,m.value]):m.value}let o=r&&ye(s,r,t.file);if(!o)return this.#r=r,e;let a=0,c=0,{readable:h,writable:l}=o.decompress(),d=l.getWriter(),p=h.getReader(),f=!1;(async()=>{try{for(;;){if(await d.ready,f)return;let m=r?{value:r,done:!1}:await e.next();if(r=void 0,f)return;if(m.done)return await d.close();a+=m.value.length,await d.write(m.value)}}catch(m){f||await d.abort(m).catch(ht)}})();let u=_t(t);return{next:async()=>{let m=await p.read().catch(g=>{throw _e(t,g)});if(!m.done){c+=m.value.length;let g=c/a;if(g>u)throw Mt(t,g,u)}return m},return:async()=>(f=!0,await p.cancel().catch(ht),await d.abort().catch(ht),await e.return?.(),{value:void 0,done:!0})}}async next(){try{for(;;){let e=this.poll();if(e)return{value:e,done:!1};if(e===null)break;await this.fill()}}catch(e){throw await this.return(),e}return this.return()}async return(){return this.#o||(this.#o=!0,this.#e.current=void 0,await(this.#s??this.#i).return?.()),{value:void 0,done:!0}}[Symbol.asyncIterator](){return this}},E=class{parser;#e;#t;#i;#s;#r;#n=!1;constructor(e,t={}){t=k(t);let s=t.platform==="win32";this.parser=new B(t,(n,r,o)=>new ue(n,r,o,s,this)),this.#e=new me(this.parser),this.#t=t,this.#i=v(e)?[e].values():tt(e)?[new Uint8Array(e)].values():e[Symbol.iterator]()}readBody(e){for(;;){let t=this.#e.body(e);if(t!==void 0)return t;this.#o()}}#o(){let e=this.#s??=this.#a(this.#i),t=this.#r;this.#r=void 0,e===this.#i&&It(this.#e,e);let s=t?{value:t,done:!1}:e.next();s.done?this.parser.end():this.parser.push(s.value)}#a(e){let t=this.#t,s=[...t.codecs??[],T],n=we(s),r,o;for(;(!r||r.length<n)&&!(o=e.next()).done;)r=r?z([r,o.value]):o.value;let a=r&&ye(s,r,t.file);if(!r||!a)return this.#r=r,e;let{decompressSync:c}=a;if(!c)throw _e(t,new Error(`the ${a.name} codec has no decompressSync function`));let h=[r];for(;!(o=e.next()).done;)h.push(o.value);let l=z(h),d=_t(t),p;try{p=c(l,{maxOutputLength:l.length*d})}catch(w){throw _e(t,w)}let f=p.length/l.length;if(f>d)throw Mt(t,f,d);return[p].values()}next(){try{for(;;){let e=this.#n?null:this.#e.entry();if(e)return{value:e,done:!1};if(e===null)break;this.#o()}}catch(e){throw this.return(),e}return this.return()}return(){return this.#n||(this.#n=!0,this.#e.current=void 0,(this.#s??this.#i).return?.()),{value:void 0,done:!0}}[Symbol.iterator](){return this}},lt=(i,e)=>new b(i,e),Bt=(i,e)=>new E(i,e);var Ht=(i,e,t)=>(i&=4095,t&&(i=(i|384)&-19),e&&(i&256&&(i|=64),i&32&&(i|=8),i&4&&(i|=1)),i);var Me=["|","<",">","?",":"],dt=Me.map(i=>String.fromCodePoint(61440+Number(i.codePointAt(0)))),os=new Map(Me.map((i,e)=>[i,dt[e]])),as=new Map(dt.map((i,e)=>[i,Me[e]])),pt=i=>Me.reduce((e,t)=>e.split(t).join(os.get(t)),i),$t=i=>dt.reduce((e,t)=>e.split(t).join(as.get(t)),i);var K=i=>i===47||i===92,cs=i=>i>=65&&i<=90||i>=97&&i<=122,j=i=>{let e=i.length,t=0;if(K(i.charCodeAt(0))){if(t=1,K(i.charCodeAt(1))){let s=2,n=s;for(;s<e&&!K(i.charCodeAt(s));)s++;if(s<e&&s!==n){for(n=s;s<e&&K(i.charCodeAt(s));)s++;if(s<e&&s!==n){for(n=s;s<e&&!K(i.charCodeAt(s));)s++;s===e?t=s:s!==n&&(t=s+1)}}}}else cs(i.charCodeAt(0))&&i.charCodeAt(1)===58&&(t=K(i.charCodeAt(2))?3:2);return i.slice(0,t)},ge=i=>K(i.charCodeAt(0))||j(i).length===3,Ie=(i,e)=>{let t=ge(e)?e:i+"/"+e,s=j(t);return s+C("/",t.slice(s.length)).slice(1)},Gt=i=>{let e=j(i),t=P(i.slice(e.length));return t==="."?e:e+t};var Be=i=>{let e="";for(let t;t=j(i);)i.charAt(0)==="/"&&i.slice(0,4)!=="//?/"&&(t="/"),i=i.slice(t.length),e+=t;return[e,i]};var He=i=>new ReadableStream({pull:async e=>{let t=await i.next();t.done?e.close():e.enqueue(t.value)},cancel:async()=>{await i.return?.()}},{highWaterMark:0});var X=i=>{let e=i.length-1,t=-1;for(;e>-1&&i.charAt(e)==="/";)t=e,e--;return t===-1?i:i.slice(0,t)};var hs=new TextEncoder,Wt=(i,e)=>e?X(e)+"/"+i.replace(/^\.(\/|$)/,""):i,se=class{path;type;mode;uid;gid;uname;gname;size;mtime;atime;ctime;linkpath;dev;ino;nlink;body;absolute;header;constructor(e,t){if(e.type==="Unsupported")throw new Error("writing entry that should be ignored");if(typeof t=="string"&&(t=hs.encode(t)),this.path=e.path,this.type=e.type??"File",this.mode=e.mode,this.uid=e.uid,this.gid=e.gid,this.uname=e.uname,this.gname=e.gname,e.size===void 0&&t!==void 0&&!v(t)&&!N(t))throw new TypeError("a stream body needs the size option");this.size=e.size??(v(t)?t.length:N(t)?t.size:0),this.mtime=e.mtime,this.atime=e.atime,this.ctime=e.ctime,this.linkpath=e.linkpath,this.dev=e.dev,this.ino=e.ino,this.nlink=e.nlink,this.body=t}encode(e={},t=new Uint8Array(512)){e=k(e);let s=Wt(this.path,e.prefix),n=this.type==="Link"&&this.linkpath!==void 0?Wt(this.linkpath,e.prefix):this.linkpath,{uid:r,gid:o,uname:a,gname:c,size:h,mtime:l,atime:d,ctime:p}=this;if(this.header=new R({path:s,linkpath:n,mode:this.mode,uid:r,gid:o,size:h,mtime:l,type:this.type,uname:a,gname:c,atime:d,ctime:p}),!this.header.encode(t)||e.noPax)return[t];let{dev:f,ino:w,nlink:u}=this;return[new I({atime:d,ctime:p,gid:o,gname:c,mtime:l,path:s,linkpath:n,size:h,uid:r,uname:a,dev:f,ino:w,nlink:u}).encode(),t]}};var ls=16*1024*1024,O=()=>{},xe=i=>512*Math.ceil(i/512),Z=i=>i.replaceAll("\\","/"),ft=i=>`${i.dev}:${i.ino}`,$e={bigint:!0},ds=({dev:i,ino:e})=>!Number.isSafeInteger(i)||!Number.isSafeInteger(e),je=(i,e)=>i.dev===e.dev&&i.ino===e.ino,ut=(i,e)=>Object.assign(new Error(i),{path:e,syscall:"read",code:"EOF"}),Xt=(i,e)=>ut(`encountered unexpected EOF: ${i} has fewer than the ${e} bytes of its stat`,i),Zt=(i,e)=>ut(`did not encounter expected EOF: ${i} has more than the ${e} bytes of its stat`,i),Jt=i=>i.absolute??i.path,ps=i=>Object.assign(new Error("writing more data than expected"),{path:Jt(i)}),Qt=i=>Symbol.asyncIterator in i||Symbol.iterator in i,fs=i=>typeof i.encode=="function",F=class{path;absolute;up;linkpath;ready;constructor(e,t){this.path=e,this.absolute=t}},ke=class{opt;fs;cwd;win32;maxReadSize;header;codec;codecOptions;ended=!1;head;tail;wake;#e=new Map;constructor(e,t){e=this.opt=k(e),this.fs=e.fs,this.win32=e.platform==="win32",this.maxReadSize=V("maxReadSize",e.maxReadSize,ls);let{prefix:s,noPax:n}=e;this.header={prefix:s&&this.win32?Z(s):s,noPax:n};let r=e.cwd&&(this.win32?Z(e.cwd):e.cwd);if(r&&!(this.win32?ge:te)(r))throw new TypeError("cwd must be an absolute path");this.cwd=r&&this.#t(r,"");let o=e,a=["gzip","brotli","zstd","compress"].filter(h=>o[h]);if(a.length>1)throw new TypeError(`${a.join(", ")} are mutually exclusive`);let[c]=a;if(c){let h=e.compress,[l,d]=h?Array.isArray(h)?h:[h]:[[...e.codecs??[],T].find(p=>p.name===c),o[c]];if(!l?.[t])throw new TypeError(`no codec named ${l?.name??c} has a ${t} function`);this.codec=l,this.codecOptions={...typeof d=="object"?d:void 0,...l.name==="gzip"&&e.portable?{portable:!0}:void 0}}}#t(e,t){return this.win32?Ie(e,t):C(e,t)}resolve(e){if(!this.cwd||!this.fs)throw new TypeError("a path needs the cwd and fs options");return this.#t(this.cwd,this.win32?Z(e):e)}add(e){if(this.ended)throw new Error("write after end");if(typeof e!="string")this.push(e);else{let t=this.win32?Z(e):e;this.push(new F(t||"./",this.resolve(t)))}return this}end(){return this.ended=!0,this.wake?.(),this}push(e){let t={item:e};this.tail?this.tail.next=t:this.head=t,this.tail=t,this.wake?.()}shift(){this.head=this.head?.next,this.head||(this.tail=void 0)}needsExact(e){return ds(e)&&(e.isDirectory()?!!this.opt.follow:e.isFile()&&e.nlink>1)}plan(e,t,s){let{filter:n}=this.opt;if(!(n&&!n(e.path,t))){if(t.isDirectory()){for(let r=e.up;r;r=r.up)if(r.key===ft(s)){S(this.opt,"TAR_ENTRY_ERROR","directory is its own ancestor",{path:e.path,absolute:e.absolute});return}return"Directory"}if(t.isSymbolicLink())return"SymbolicLink";if(!t.isFile()){S(this.opt,"TAR_ENTRY_UNSUPPORTED","unsupported file type",{path:e.path,absolute:e.absolute});return}if(t.nlink>1){let r=ft(s),o=this.#e.get(r),a=this.cwd;if(o!==e.absolute&&o?.startsWith(a.endsWith("/")?a:a+"/"))return e.linkpath=L(a,o),"Link";this.#e.set(r,e.absolute)}return"File"}}children(e,t,s){let n=e.path==="./"?"":e.path.replace(/\/*$/,"/"),r=e.absolute.endsWith("/")?e.absolute:e.absolute+"/",o=this.opt.follow?{key:ft(s),up:e.up}:void 0;return[...t].sort().map(a=>{let c=new F(n+a,r+a);return c.up=o,c})}missing(e,t){if(t?.code!=="ENOENT")throw t;S(this.opt,"TAR_ENTRY_ERROR",t,{path:e.path,absolute:e.absolute})}changed(e,t){S(this.opt,"TAR_ENTRY_ERROR",t==="Directory"?"directory changed between lstat and readdir":"file changed between lstat and open",{path:e.path,absolute:e.absolute})}pathEntry(e,t,s,n,r){let{processUid:o,processUname:a=""}=this.opt,c=new se({path:e.path,type:s,mode:t.mode,uid:t.uid,gid:t.gid,uname:t.uid===o?a:"",size:s==="File"?t.size:0,mtime:t.mtime,atime:t.atime,ctime:t.ctime,linkpath:n&&this.win32?Z(n):n,dev:t.dev,ino:t.ino,nlink:t.nlink},r);return c.absolute=e.absolute,this.#i(c,!0)}addedEntry(e){if(fs(e))return this.#i(e,!1);let{filter:t}=this.opt;if(!(t&&!t(e.path,e)))return this.#i(new se(e,e.body),!1)}#i(e,t){let{opt:s,win32:n}=this,r=e.type==="Directory";n&&!t&&(e.path=Z(e.path),e.linkpath&&(e.linkpath=Z(e.linkpath)));let[o,a]=s.preservePaths?["",e.path]:Be(e.path);return e.path=a,t&&(n&&(e.path=$t(e.path)),e.path===""&&(e.path="./")),o&&S(s,"TAR_ENTRY_INFO",`stripping ${o} from absolute path`,{entry:e,path:o+e.path}),t&&r&&!e.path.endsWith("/")&&(e.path+="/"),s.portable&&(e.uid=e.gid=e.dev=e.ino=e.nlink=void 0,e.uname=e.gname=void 0,e.atime=e.ctime=void 0),e.mode!==void 0&&(e.mode=Ht(e.mode,r,!!s.portable)),e.mtime=s.noMtime||s.portable&&r?void 0:s.mtime||e.mtime,e}},Yt=async(i,e,t,s,n,r)=>{for(;t<e.length&&s<n;){let{bytesRead:o}=await i.read(e,t,e.length-t,s);if(o<=0)throw Xt(r,n);if(o>n-s)throw Zt(r,n);t+=o,s+=o}return s},Vt=(i,e,t,s,n,r,o)=>{for(;s<t.length&&n<r;){let a=i.readSync(e,t,s,t.length-s,n);if(a<=0)throw Xt(o,r);if(a>r-n)throw Zt(o,r);s+=a,n+=a}return n};async function*us(i){if(v(i))yield i;else if(N(i)||Pe(i)){let e=(N(i)?i.stream():i).getReader();try{for(;;){let t=await e.read();if(t.done)break;yield t.value}}finally{await e.cancel().catch(O)}}else i&&(yield*i)}function*ms(i){if(v(i))yield i;else if(i&&Symbol.iterator in i)yield*i;else if(i)throw new TypeError("PackSync needs a body that is a string, a Uint8Array, or an iterable")}var ei=(i,e,t)=>{if(t.length>e)throw ps(i);return e-t.length},ti=(i,e)=>{if(e)throw ut("encountered unexpected EOF",Jt(i));return new Uint8Array(xe(i.size)-i.size)};async function*qt(i){if(!i.size)return;let e=i.size;for await(let s of us(i.body))e=ei(i,e,s),yield s;let t=ti(i,e);t.length&&(yield t)}function*Kt(i){if(!i.size)return;let e=i.size;for(let s of ms(i.body))e=ei(i,e,s),yield s;let t=ti(i,e);t.length&&(yield t)}var Se=class extends ke{jobs;#e;#t=Promise.resolve();constructor(e={}){super(e,"compress"),this.jobs=V("jobs",this.opt.jobs,4)}async next(){let e=await(this.#e??=this.#i()).next();return e.done?{value:void 0,done:!0}:e}async return(){return this.end(),await this.#e?.return(),{value:void 0,done:!0}}[Symbol.asyncIterator](){return this}#i(){let{codec:e}=this;return e?.compress?this.#s(e.compress(this.codecOptions)):this.#r()}async*#s(e){let t=this.#r(),s,n=He({next:()=>t.next().catch(r=>{throw s={er:r},n.cancel().catch(O),r})}).pipeThrough(e).getReader();try{for(;;){let r=await n.read();if(s)throw s.er;if(r.done)break;yield r.value}}finally{await n.cancel().catch(O),await t.return()}}async*#r(){try{for(;;){let e=this.head;if(!e){if(this.ended)break;await new Promise(s=>this.wake=s);continue}this.#n();let{item:t}=e;if(t instanceof F)yield*this.#c(t);else if(!Qt(t))yield*this.#d(t);else for await(let s of t)yield*this.#d(s);this.shift()}yield new Uint8Array(1024)}finally{for(let e=this.head;e;e=e.next){let{item:t}=e;if(!(t instanceof F)||!t.ready)break;await(await t.ready.catch(O))?.handle?.close().catch(O)}}}#n(){let e=this.fs,t=this.head;for(let s=0;t&&s<this.jobs;s++,t=t.next){let n=t.item;if(!(n instanceof F))break;if(n.ready)continue;let r=this.#o(e,n.absolute);r.catch(O);let o=this.#t.then(()=>r).then(([a,c])=>{let h=this.plan(n,a,c);return h&&{load:this.#a(e,n,a,c,h)}},a=>this.missing(n,a));this.#t=o.catch(O),n.ready=o.then(a=>a?.load),n.ready.catch(O)}}async#o(e,t){let{follow:s}=this.opt,n=await(s?e.stat(t):e.lstat(t)),r=this.needsExact(n)?await(s?e.stat(t,$e):e.lstat(t,$e)):n;return[n,r]}async#a(e,t,s,n,r){let{absolute:o}=t,{follow:a,noDirRecurse:c}=this.opt,h={stat:s,id:n,type:r};if(r==="SymbolicLink")h.linkpath=await e.readlink(o);else if(r==="Directory"&&!c)h.names=await e.readdir(o),h.changed=!a&&!je(s,await e.lstat(o));else if(r==="File"&&s.size){let l=await e.open(o,"r");try{let{size:d}=s,p=xe(d);!a&&!je(s,await l.stat())?h.changed=!0:p>this.maxReadSize?h.handle=l:(h.buf=new Uint8Array(512+p),await Yt(l,h.buf,512,0,d,o))}catch(d){throw await l.close().catch(O),d}h.handle||await l.close()}return h}async*#c(e){let t=await e.ready;if(!t)return;let{stat:s,id:n,type:r,names:o,buf:a,handle:c}=t;if(t.changed)return this.changed(e,r);let h=!1;try{let l=a?a.subarray(512,512+s.size):c&&this.#h(c,s.size,e.absolute),d=this.pathEntry(e,s,r,t.linkpath??e.linkpath,l);if(o)for(let f of this.children(e,o,n))this.push(f);await this.opt.onWriteEntry?.(d);let p=a&&d.body===l&&d.size===s.size;yield*d.encode(this.header,p?a:void 0),p||(yield*qt(d)),h=!0}finally{if(c){t.handle=void 0;let l=c.close();await(h?l:l.catch(O))}}}async*#h(e,t,s){let n=xe(t);for(let r=0;r<t;){let o=new Uint8Array(Math.min(n-r,this.maxReadSize)),a=await Yt(e,o,0,r,t,s);yield o.subarray(0,a-r),r=a}}async*#d(e){let t=this.addedEntry(e);t&&(await this.opt.onWriteEntry?.(t),yield*t.encode(this.header),yield*qt(t))}},be=class extends ke{#e;constructor(e={}){super(e,"compressSync")}next(){let e=(this.#e??=this.#t()).next();return e.done?{value:void 0,done:!0}:e}return(){return this.ended=!0,this.#e?.return(),{value:void 0,done:!0}}[Symbol.iterator](){return this}*#t(){let{codec:e}=this;if(!e?.compressSync)return yield*this.#i();yield e.compressSync(z([...this.#i()]),this.codecOptions)}*#i(){for(let e;e=this.head;this.shift()){let{item:t}=e;if(t instanceof F){let s=[t];for(let n of s)yield*this.#s(n,s)}else if(!Qt(t))yield*this.#n(t);else for(let s of t)yield*this.#n(s)}this.ended=!0,yield new Uint8Array(1024)}*#s(e,t){let s=this.fs,{absolute:n}=e,{follow:r,noDirRecurse:o}=this.opt,a;try{a=r?s.statSync(n):s.lstatSync(n)}catch(u){return this.missing(e,u)}let c=this.needsExact(a)?r?s.statSync(n,$e):s.lstatSync(n,$e):a,h=this.plan(e,a,c);if(!h)return;let{linkpath:l}=e,d,p,f,w=!1;try{if(h==="SymbolicLink")l=s.readlinkSync(n);else if(h==="Directory"&&!o){let g=s.readdirSync(n);if(!r&&!je(a,s.lstatSync(n)))return this.changed(e,h);t.push(...this.children(e,g,c))}else if(h==="File"&&a.size){let{size:g}=a,Et=xe(g);if(f=s.openSync(n,"r"),!r&&!je(a,s.fstatSync(f)))return this.changed(e,h);Et>this.maxReadSize?p=this.#r(s,f,g,n):(d=new Uint8Array(512+Et),Vt(s,f,d,512,0,g,n),p=d.subarray(512,512+g))}let u=this.pathEntry(e,a,h,l,p);this.opt.onWriteEntry?.(u);let m=d&&u.body===p&&u.size===a.size;yield*u.encode(this.header,m?d:void 0),m||(yield*Kt(u)),w=!0}finally{if(f!==void 0&&!w)try{s.closeSync(f)}catch{}}f!==void 0&&s.closeSync(f)}*#r(e,t,s,n){let r=xe(s);for(let o=0;o<s;){let a=new Uint8Array(Math.min(r-o,this.maxReadSize)),c=Vt(e,t,a,0,o,s,n);yield a.subarray(0,c-o),o=c}}*#n(e){let t=this.addedEntry(e);t&&(this.opt.onWriteEntry?.(t),yield*t.encode(this.header),yield*Kt(t))}};var Ee=64*1024,Ge=4*Ee,ws=()=>{},mt=(i,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive");if(i.file&&!i.fs)throw new TypeError("the file option needs the fs option")},ii=async(i,e,t,s)=>{for(let n=0;n<t;)n+=(await i.write(e,n,t-n,s+n)).bytesWritten},wt=async(i,e,t)=>{let s=new Uint8Array(Ge),n=0,r=async()=>{await ii(i,s,n,t),t+=n,n=0};for await(let o of e)(n+o.length>Ge||o.length>=Ee)&&await r(),o.length>=Ee?(await ii(i,o,o.length,t),t+=o.length):(s.set(o,n),n+=o.length);await r()},yt=(i,e,t,s)=>{let n=new Uint8Array(Ge),r=0,o=(a,c)=>{for(let h=0;h<c;)h+=i.writeSync(e,a,h,c-h,s+h);s+=c};for(let a of t)(r+a.length>Ge||a.length>=Ee)&&(o(n,r),r=0),a.length>=Ee?o(a,a.length):(n.set(a,r),r+=a.length);o(n,r)},ys=async(i,e,t,s)=>{let n=await e.open(t,"w",s),r=!1;try{await wt(n,i,0),r=!0}finally{let o=n.close();await(r?o:o.catch(ws))}},We=(i,e)=>{let{fs:t,strict:s,onwarn:n,codecs:r,platform:o}=i,a=new Se(i);for(let c of e)if(typeof c!="string"||c.charAt(0)!=="@")a.add(c);else{let h=a.resolve(c.slice(1));a.add(new b(H(t,h,i.maxReadSize),{strict:s,onwarn:n,codecs:r,platform:o,file:h}))}return a.end()},gt=(i,e)=>{let{strict:t,onwarn:s,codecs:n,platform:r}=i,o=new be(i);for(let a of e)if(typeof a!="string"||a.charAt(0)!=="@")o.add(a);else{let c=o.resolve(a.slice(1));o.add(new E($(i.fs,c,i.maxReadSize),{strict:t,onwarn:s,codecs:n,platform:r,file:c}))}return o};function ne(i,e){let t=y(i);if(!t.file)return mt(t,e),He(We(t,e));try{return mt(t,e),ys(We(t,e),t.fs,t.file,t.mode||438)}catch(s){return Promise.reject(s)}}function Ye(i,e){let t=y(i);mt(t,e);let{file:s}=t,n=t.fs,r=gt(t,e);if(!s)return r;let o=n.openSync(s,"w",t.mode||438);try{yt(n,o,r,0)}catch(a){try{n.closeSync(o)}catch{}throw a}n.closeSync(o)}var J=(i,e)=>{let t=new Set(i.map(o=>X(o))),s=new Set(t),n=0;for(let o of t)n=Math.max(n,o.length);let r=o=>{let a=X(o),c=a.charAt(0)==="/"?"/":".",h=!1;for(let l=a.length;l>0;l=a.lastIndexOf("/",l-1)){if(l>n)continue;let d=a.slice(0,l);if(!(d===c||!t.has(d))&&(h=!0,s.delete(d),!s.size))break}return h};return[(o,a)=>{let c=!e||e(o,a);return r(o)&&c},o=>{for(let a of s)S(o,"TAR_ENTRY_ERROR",`${a}: not found in archive`,{path:a})}]},si=()=>new TypeError("list needs input, or file and fs"),Ve=async(i,e)=>{let t=y(i),{input:s,file:n,fs:r,onEntry:o}=t,a=s??(n&&r?H(r,n,t.maxReadSize):void 0);if(!a)throw si();let[c,h]=e?.length?J(e,t.filter):[];c&&(t.filter=c);let l=new b(a,t);try{for(;;){let d=l.poll();if(d===null)break;d===void 0?await l.fill():o&&await o(d)}}finally{await l.return()}h?.(t)},ni=(i,e)=>{let t=y(i),{input:s,file:n,fs:r,onEntry:o}=t,a=s??(n&&r?$(r,n,t.maxReadSize):void 0);if(!a)throw si();let[c,h]=e?.length?J(e,t.filter):[];c&&(t.filter=c);let l=new E(a,t);for(let d of l)o?.(d);h?.(t)};var gs=()=>{},ri=(i,e)=>{if(!i.file)throw new TypeError("file is required");if(!i.fs)throw new TypeError("the file option needs the fs option");let t=[...i.codecs??[],T];if(e?.length)return[t,...J(e,i.filter)];if(i.filter)return[t,i.filter];throw new TypeError("no paths specified to delete")},oi=i=>`${i}.${Math.random().toString(36).slice(2)}.tmp`,xt=async(i,e)=>{let t=y(i),[s,n,r]=ri(t,e),{fs:o,file:a,filter:c,maxReadSize:h,...l}=t,d=new Uint8Array(we(s)),p=0,f=await o.open(a,"r");try{for(let m=1;m>0&&p<d.length;p+=m)m=(await f.read(d,p,d.length-p,p)).bytesRead}finally{await f.close()}let{mode:w}=await o.stat(a),u=oi(a);try{await ne({...l,fs:o,file:u,mode:w&511,compress:ye(s,d.subarray(0,p),a),preservePaths:!0,filter:(m,g)=>!n(m,g)},[new b(H(o,a,h),{...l,file:a})]),r?.(t),await o.rename(u,a)}catch(m){throw await o.unlink(u).catch(gs),m}},ai=(i,e)=>{let t=y(i),[s,n,r]=ri(t,e),{fs:o,file:a,filter:c,maxReadSize:h,...l}=t,d=new Uint8Array(we(s)),p=0,f=o.openSync(a,"r");try{for(let m=1;m>0&&p<d.length;p+=m)m=o.readSync(f,d,p,d.length-p,p)}finally{o.closeSync(f)}let{mode:w}=o.statSync(a),u=oi(a);try{Ye({...l,fs:o,file:u,mode:w&511,compress:ye(s,d.subarray(0,p),a),preservePaths:!0,filter:(m,g)=>!n(m,g)},[new E($(o,a,h),{...l,file:a})]),r?.(t),o.renameSync(u,a)}catch(m){try{o.unlinkSync(u)}catch{}throw m}};var re=class extends Error{path;code;syscall="chdir";constructor(e,t){super(`${t}: Cannot cd into '${e}'`),this.path=e,this.code=t}get name(){return"CwdError"}};var G=class extends Error{path;symlink;syscall="symlink";code="TAR_SYMLINK_ERROR";constructor(e,t){super("TAR_SYMLINK_ERROR: Cannot extract through symbolic link"),this.symlink=e,this.path=t}get name(){return"SymlinkError"}};var ci=i=>{let e=i.mode|448,{uid:t,gid:s}=i;return{mode:e,needChmod:(e&i.umask)!==0,owner:typeof t=="number"&&typeof s=="number"&&(t!==i.processUid||s!==i.processGid)?{uid:t,gid:s}:void 0}},hi=(i,e)=>i.endsWith("/")?i+e:i+"/"+e,li=(i,e)=>{let t=i.replaceAll("\\","/"),s=[e];for(let n=e.length;!t.endsWith(e.slice(0,n));){if(n=e.lastIndexOf("/",n-1),n<=0)return[e];s.push(e.slice(0,n))}return s},di=async(i,e,t)=>{let{mode:s,needChmod:n,owner:r}=ci(t),{cwd:o}=t,a=[];if(e===o){let c="ENOTDIR";if(!await i.stat(e).then(l=>l.isDirectory(),l=>(c=l?.code||c,!1)))throw new re(e,c)}else if(t.preserve){let c=await i.mkdir(e,{mode:s,recursive:!0});c&&(a=li(c,e))}else{let c=L(o,e).split("/"),h=o;for(let l=0;l<c.length;l++){h=hi(h,c[l]);try{await i.mkdir(h,{mode:s})}catch(d){let p=await i.lstat(h);if(p.isDirectory())continue;if(!t.unlink)throw p.isSymbolicLink()?new G(h,h+"/"+c.slice(l+1).join("/")):d;await i.unlink(h),await i.mkdir(h,{mode:s})}a.push(h)}}if(r)for(let c of a)await i.lchown(c,r.uid,r.gid);n&&await i.chmod(e,s)},pi=(i,e,t)=>{let{mode:s,needChmod:n,owner:r}=ci(t),{cwd:o}=t,a=[];if(e===o){let c="ENOTDIR",h=!1;try{h=i.statSync(e).isDirectory()}catch(l){c=l?.code||c}if(!h)throw new re(e,c)}else if(t.preserve){let c=i.mkdirSync(e,{mode:s,recursive:!0});c&&(a=li(c,e))}else{let c=L(o,e).split("/"),h=o;for(let l=0;l<c.length;l++){h=hi(h,c[l]);try{i.mkdirSync(h,{mode:s})}catch(d){let p=i.lstatSync(h);if(p.isDirectory())continue;if(!t.unlink)throw p.isSymbolicLink()?new G(h,h+"/"+c.slice(l+1).join("/")):d;i.unlinkSync(h),i.mkdirSync(h,{mode:s})}a.push(h)}}if(r)for(let c of a)i.lchownSync(c,r.uid,r.gid);n&&i.chmodSync(e,s)};var kt=Object.create(null),fi=1e4,oe=new Set,xs=256,ui=i=>{if(i.length>xs)return i.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en");oe.has(i)?oe.delete(i):kt[i]=i.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),oe.add(i);let e=kt[i],t=oe.size-fi;if(t>fi/10){for(let s of oe)if(oe.delete(s),delete kt[s],--t<=0)break}return e};var ve=class{#e={queue:[],name:""};#t=new Map;#i=new Set;#s;constructor(e=!1){this.#s=e}reserve(e,t){return new Promise((s,n)=>{let r=()=>{t().then(()=>{this.#o(r),s()},o=>{this.#o(r),n(o)})};this.#r(e,r)})}#r(e,t){let s=this.#e,n=new Set,r=new Set;for(let o of this.#s?["win32 parallelization disabled"]:e){let a=this.#s?o:X(W(ui(o))),c=s;for(let h of a.split("/")){c!==s&&r.add(c);let l=c.kids??=new Map,d=l.get(h);d||l.set(h,d={queue:[],name:h,up:c}),c=d}n.add(c)}for(let o of n)r.delete(o);this.#t.set(t,{dirs:r,paths:n});for(let o of n)o.queue.push(t);for(let{queue:o}of r){let a=o[o.length-1];a instanceof Set?a.add(t):o.push(new Set([t]))}this.#n(t)}#n(e){let{paths:t,dirs:s}=this.#t.get(e);for(let n of t)if(n.queue[0]!==e)return;for(let{queue:n}of s){let r=n[0];if(!(r instanceof Set)||!r.has(e))return}this.#i.add(e),e()}#o(e){let{paths:t,dirs:s}=this.#t.get(e),n=new Set;for(let{queue:r}of t){r.shift();let o=r[0];if(typeof o=="function")n.add(o);else if(o)for(let a of o)n.add(a)}for(let{queue:r}of s){let o=r[0];o.size>1?o.delete(e):(r.shift(),r.length&&n.add(r[0]))}for(let r of t)for(;r.up&&!r.queue.length&&!r.kids?.size;)r.up.kids?.delete(r.name),r=r.up;this.#i.delete(e),this.#t.delete(e);for(let r of n)this.#n(r)}};var mi=(i,e)=>{if(!i)return()=>"w";let{O_CREAT:t,O_TRUNC:s,O_WRONLY:n,O_NOFOLLOW:r,UV_FS_O_FILEMAP:o}=i,a=s|t|n;if(!e){let h=typeof r=="number"?r|a:"w";return()=>h}if(!o)return()=>"w";let c=o|a;return h=>h<524288?c:"w"};var ks=1024,wi=32768,Ss=16,qe=new Set(["File","OldFile","ContiguousFile"]),ae=new Set(["Directory","GNUDumpDir"]),bs=new Set(["Link","SymbolicLink"]),yi=(i,e,t)=>i!==void 0?i:e!==void 0&&e===e>>>0?e:t,Re=class{opt;cwd;win32;strip;maxDepth;preservePaths;unlink;keep;newer;noMtime;chmod;uid;gid;preserveOwner;forceChown;processUid;processGid;processUmask;umask;dmode;fmode;writeFlag;resolve;dirname;fatal;constructor(e){let t=this.opt=k(e),s=this.win32=t.platform==="win32";if(this.resolve=s?Ie:C,this.dirname=s?Gt:P,typeof t.cwd!="string")throw new TypeError("cwd is required");let n=s?t.cwd.replaceAll("\\","/"):t.cwd;if(!(s?ge:te)(n))throw new TypeError("cwd must be an absolute path");if(this.cwd=this.resolve(n,""),typeof t.uid=="number"||typeof t.gid=="number"){if(typeof t.uid!="number"||typeof t.gid!="number")throw new TypeError("cannot set owner without number uid and gid");if(t.uid!==t.uid>>>0||t.gid!==t.gid>>>0)throw new TypeError("uid and gid must be unsigned 32-bit integers");if(t.preserveOwner)throw new TypeError("cannot preserve owner in archive and also set owner explicitly");this.uid=t.uid,this.gid=t.gid}this.processUid=t.processUid,this.processGid=t.processGid,this.preserveOwner=t.preserveOwner===void 0&&typeof t.uid!="number"?t.processUid===0:!!t.preserveOwner,this.forceChown=t.forceChown===!0,this.maxDepth=typeof t.maxDepth=="number"?t.maxDepth:ks,this.strip=Number(t.strip)||0,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.keep=!!t.keep,this.newer=!!t.newer,this.noMtime=!!t.noMtime,this.chmod=!!t.chmod,this.processUmask=this.chmod?typeof t.processUmask=="number"?t.processUmask:18:0,this.umask=typeof t.umask=="number"?t.umask:this.processUmask,this.dmode=t.dmode||511&~this.umask,this.fmode=t.fmode||438&~this.umask,this.writeFlag=mi(t.fs.constants,s)}warn(e,t,s={}){(e==="TAR_BAD_ARCHIVE"||e==="TAR_ABORT")&&(s.recoverable=!1),s.cwd=this.cwd,S(this.opt,e,t,s)}readerOptions(){return k(this.opt,{strict:!1,onwarn:(e,t,s)=>s instanceof Error?this.warn(e,s):this.warn(e,t,s)})}entryError(e,t){if(this.fatal?.error===e||e?.name==="CwdError")throw e;this.warn("TAR_ENTRY_ERROR",e,{entry:t})}fail(e){return this.fatal??={error:e},e}#e(e,t){let s=e[t];if(!s||this.preservePaths)return!0;let[n,r]=Be(s),o=r.replaceAll("\\","/").split("/");if(o.includes("..")){if(t==="path"||e.type==="Link")return this.warn("TAR_ENTRY_ERROR",`${t} contains '..'`,{entry:e,[t]:s}),!1;let a=o.findIndex(l=>l!==".."&&l!=="."&&l!=="");if(a!==-1&&o.includes("..",a))return this.warn("TAR_ENTRY_ERROR",`${t} contains '..' after a path portion`,{entry:e,[t]:s}),!1;let c=P(he(e.path)),h=he(W(c,o.join("/")));if(h.startsWith("../")||h==="..")return this.warn("TAR_ENTRY_ERROR",`${t} escapes extraction directory`,{entry:e,[t]:s}),!1}return n&&(e[t]=r,this.warn("TAR_ENTRY_INFO",`stripping ${n} from absolute ${t}`,{entry:e,[t]:s})),!0}check(e){let t=e.path,s=t.split("/");if(this.strip){if(s.length<this.strip)return!1;if(e.type==="Link"){let c=String(e.linkpath).split("/");if(c.length<this.strip)return!1;e.linkpath=c.slice(this.strip).join("/")}if(s.splice(0,this.strip),s.every(c=>c===""))return!1;e.path=s.join("/")}let{maxDepth:n}=this;if(isFinite(n)&&s.length>n)return this.warn("TAR_ENTRY_ERROR","path excessively deep",{entry:e,path:t,depth:s.length,maxDepth:n}),!1;let{linkpath:r}=e;if(r&&isFinite(n)&&r.split("/").length>n)return this.warn("TAR_ENTRY_ERROR","linkpath excessively deep",{entry:e,path:t,linkpath:r,maxDepth:n}),!1;for(let c of["path","linkpath"]){let{length:h}=e[c]??"";if(h>wi)return this.warn("TAR_ENTRY_ERROR",`${c} excessively long`,{entry:e,path:t,length:h,maxLength:wi}),!1}if(!this.#e(e,"path")||!this.#e(e,"linkpath"))return!1;let{cwd:o}=this,a=this.resolve(o,e.path);if(!this.preservePaths&&a!==o&&!a.startsWith(o.endsWith("/")?o:o+"/"))return this.warn("TAR_ENTRY_ERROR","path escaped extraction target",{entry:e,path:e.path,resolvedPath:a,cwd:o}),!1;if(a===o&&!ae.has(e.type))return!1;if(this.win32){let c=j(a);a=c+pt(a.slice(c.length));let h=j(e.path);e.path=h+pt(e.path.slice(h.length))}if(e.absolute=a,typeof e.mode=="number"&&(e.mode&=511),ae.has(e.type))e.mode&&(e.mode|=448);else if(!qe.has(e.type)&&!bs.has(e.type))return e.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${e.type}`,{entry:e}),!1;return!0}reservedPaths(e){let{path:t,linkpath:s}=e;return s?[t,e.type==="SymbolicLink"&&!te(s)?W(P(t),s):s]:[t]}mkdirOptions(e){return{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e}}owner(e){let t=this.forceChown||this.preserveOwner&&(typeof e.uid=="number"&&e.uid!==this.processUid||typeof e.gid=="number"&&e.gid!==this.processGid)||typeof this.uid=="number"&&this.uid!==this.processUid||typeof this.gid=="number"&&this.gid!==this.processGid,s=yi(this.uid,e.uid,this.processUid),n=yi(this.gid,e.gid,this.processGid);return t&&typeof s=="number"&&typeof n=="number"?{uid:s,gid:n}:void 0}times(e){return e.mtime&&!this.noMtime?{atime:e.atime||new Date,mtime:e.mtime}:void 0}skip(e,t){return this.keep||this.newer&&t.mtime>(e.mtime??t.mtime)}isReusable(e,t){return e.type==="File"&&!this.unlink&&t.isFile()&&t.nlink<=1&&!this.win32}linkParts(e,t){let s=String(e.linkpath);return e.type==="Link"?s.split("/"):L(this.cwd,this.resolve(this.dirname(t),s)).split("/")}parentParts(e){let{cwd:t}=this,s=e===t?t:this.dirname(e);return s===t?[]:L(t,s).split("/")}symlinkError(e,t){return new G(e,this.resolve(this.cwd,t.join("/")))}},gi=i=>i+".DELETE."+Array.from(crypto.getRandomValues(new Uint8Array(16)),e=>e.toString(16).padStart(2,"0")).join(""),Ae=class extends Re{#e;#t;#i;#s=0;#r;#n=!1;#o;constructor(e){super(e),this.#e=this.opt.fs,this.#t=new ve(this.win32),this.#i=V("jobs",this.opt.jobs,Ss)}async extract(e){let t=new b(e,this.readerOptions()),{onEntry:s}=this.opt,n=!!this.opt.transform;try{for(;!this.fatal;){let r=t.poll();if(r===null)break;if(r===void 0){await t.fill();continue}if(s&&await s(r),r.bodyUsed||!this.check(r))continue;let o=[],a=!n;if(a&&qe.has(r.type))for(;;){let h=t.readBody(r);if(h===null)break;if(h===void 0){a=!1;break}o.push(h)}let c=this.#c(r,o,a?void 0:t);for(a||await c;this.#s>=this.#i;)await this.#a()}}catch(r){this.fail(r)}for(await t.return().catch(r=>this.fail(r));this.#s>0;)await this.#a();if(this.fatal){let{error:r}=this.fatal;throw r&&typeof r=="object"&&"tarCode"in r&&Object.assign(r,{cwd:this.cwd}),r}}#a(){return new Promise(e=>{this.#r=e})}#c(e,t,s){return this.#s++,this.#t.reserve(this.reservedPaths(e),async()=>{try{this.fatal||await this.#w(e,t,s)}catch(n){try{this.entryError(n,e)}catch(r){this.fail(r)}}this.#s--,this.#r?.()})}#h(e,t){return di(this.#e,e,this.mkdirOptions(t))}#d(){return this.#o??=this.#h(this.cwd,this.dmode).then(()=>{this.#n=!0},e=>{throw this.#o=void 0,e})}async#w(e,t,s){let n=this.#e,r=e.absolute,{cwd:o}=this;if(this.#n||await this.#d(),r!==o){let c=this.dirname(r);c!==o&&await this.#h(c,this.dmode)}let a=await n.lstat(r).catch(()=>{});if(!(a&&this.skip(e,a))){if(a&&!this.isReusable(e,a)&&(a.isDirectory()&&ae.has(e.type)?this.chmod&&e.mode&&(a.mode&4095)!==e.mode&&await n.chmod(r,e.mode):r!==o&&(a.isDirectory()?await n.rmdir(r):await this.#y(r))),qe.has(e.type))return this.#u(e,r,t,s);if(ae.has(e.type))await this.#l(e,r);else{await this.#p(this.linkParts(e,r));let c=String(e.linkpath);e.type==="Link"?await n.link(this.resolve(o,c),r):await n.symlink(c,r)}await this.#p(this.parentParts(r))}}async#y(e){let t=this.#e;if(!this.win32)return t.unlink(e);let s=gi(e);await t.rename(e,s),await t.unlink(s)}async#p(e){if(this.preservePaths)return;let t=this.cwd;for(let s of e){t=this.resolve(t,s);let n=await this.#e.lstat(t).catch(()=>{});if(!n)return;if(n.isSymbolicLink())throw this.symlinkError(t,e)}}async#l(e,t){let s=this.#e;await this.#h(t,e.mode??this.dmode);let n=this.times(e);n&&await s.lutimes(t,n.atime,n.mtime).catch(()=>{});let r=this.owner(e);r&&await s.lchown(t,r.uid,r.gid).catch(()=>{})}async#u(e,t,s,n){let r=this.#e,o=await r.open(t,this.writeFlag(e.size),e.mode??this.fmode);try{if(await this.#p(this.parentParts(t)),n)await this.#g(e,s,n,o);else for(let h of s)await o.write(h);let a=this.times(e);if(a){let{atime:h,mtime:l}=a;await o.utimes(h,l).catch(async d=>{await r.utimes(t,h,l).catch(()=>{throw d})})}let c=this.owner(e);if(c){let{uid:h,gid:l}=c;await o.chown(h,l).catch(async d=>{await r.chown(t,h,l).catch(()=>{throw d})})}}catch(a){throw await o.close().catch(()=>{}),a}await o.close()}async#g(e,t,s,n){let r=0,o=async()=>{if(r<t.length)return t[r++];try{for(;;){let f=s.readBody(e);if(f!==void 0)return f;await s.fill()}}catch(f){throw this.fail(f)}},a=this.opt.transform?.(e);if(!a){let f,w;try{for(let u;(u=await o())&&(await f,!w);)f=n.write(u).then(()=>{},m=>{w={error:m}})}finally{await f}if(w)throw w.error;return}let c=a.writable.getWriter(),h=a.readable.getReader(),l,d=async f=>{l??={error:f},await h.cancel(f).catch(()=>{}),await c.abort(f).catch(()=>{})},p=(async()=>{try{for(let f;f=await o();)await c.write(f);await c.close()}catch(f){await d(f)}})();try{for(;;){let{done:f,value:w}=await h.read();if(f)break;await n.write(w)}}catch(f){await d(f)}if(await p,l)throw l.error}},Te=class extends Re{#e;#t=!1;constructor(e){super(e),this.#e=this.opt.fs}extract(e){let t=new E(e,this.readerOptions()),{onEntry:s}=this.opt;try{for(let n of t)if(s?.(n),!n.bodyUsed&&this.check(n))try{this.#s(n,t)}catch(r){this.entryError(r,n)}}catch(n){throw n&&typeof n=="object"&&"tarCode"in n&&Object.assign(n,{cwd:this.cwd}),n}}#i(e,t){pi(this.#e,e,this.mkdirOptions(t))}#s(e,t){let s=this.#e,n=e.absolute,{cwd:r}=this;if(this.#t||(this.#i(r,this.dmode),this.#t=!0),n!==r){let a=this.dirname(n);a!==r&&this.#i(a,this.dmode)}let o;try{o=s.lstatSync(n)}catch{}if(!(o&&this.skip(e,o))){if(o&&!this.isReusable(e,o)&&(o.isDirectory()&&ae.has(e.type)?this.chmod&&e.mode&&(o.mode&4095)!==e.mode&&s.chmodSync(n,e.mode):n!==r&&(o.isDirectory()?s.rmdirSync(n):this.#r(n))),qe.has(e.type))return this.#a(e,n,t);if(ae.has(e.type))this.#o(e,n);else{this.#n(this.linkParts(e,n));let a=String(e.linkpath);e.type==="Link"?s.linkSync(this.resolve(r,a),n):s.symlinkSync(a,n)}this.#n(this.parentParts(n))}}#r(e){let t=this.#e;if(!this.win32)return t.unlinkSync(e);let s=gi(e);t.renameSync(e,s),t.unlinkSync(s)}#n(e){if(this.preservePaths)return;let t=this.cwd;for(let s of e){t=this.resolve(t,s);let n;try{n=this.#e.lstatSync(t)}catch{return}if(n.isSymbolicLink())throw this.symlinkError(t,e)}}#o(e,t){let s=this.#e;this.#i(t,e.mode??this.dmode);let n=this.times(e);if(n)try{s.lutimesSync(t,n.atime,n.mtime)}catch{}let r=this.owner(e);if(r)try{s.lchownSync(t,r.uid,r.gid)}catch{}}#a(e,t,s){let n=this.#e,r=n.openSync(t,this.writeFlag(e.size),e.mode??this.fmode);try{this.#n(this.parentParts(t));let o=this.opt.transform?.(e);for(;;){let h;try{h=s.readBody(e)}catch(l){throw this.fail(l)}if(!h)break;n.writeSync(r,o?o(h):h)}let a=this.times(e);if(a){let{atime:h,mtime:l}=a;try{n.futimesSync(r,h,l)}catch(d){try{n.utimesSync(t,h,l)}catch{throw d}}}let c=this.owner(e);if(c){let{uid:h,gid:l}=c;try{n.fchownSync(r,h,l)}catch(d){try{n.chownSync(t,h,l)}catch{throw d}}}}catch(o){try{n.closeSync(r)}catch{}throw o}n.closeSync(r)}};var xi=()=>new TypeError("extract needs input or file"),Ke=async(i,e)=>{let t=y(i),s=t.input??(t.file?H(t.fs,t.file,t.maxReadSize):void 0);if(!s)throw xi();let[n,r]=e?.length?J(e,t.filter):[];n&&(t.filter=n),await new Ae(t).extract(s),r?.(t)},ki=(i,e)=>{let t=y(i),s=t.input??(t.file?$(t.fs,t.file,t.maxReadSize):void 0);if(!s)throw xi();let[n,r]=e?.length?J(e,t.filter):[];n&&(t.filter=n),new Te(t).extract(s),r?.(t)};var Si=64*1024,bi={},Es=()=>{},Xe=()=>new Error("cannot append to compressed archives"),Ei=(i,e)=>{let{file:t}=i;if(!t)throw new TypeError("file is required");if(i.gzip||i.brotli||i.zstd||t.endsWith(".br")||t.endsWith(".tbr"))throw new TypeError(Xe().message);if(!e?.length)throw new TypeError("no paths specified to add/replace")},Oe=class{buf=new Uint8Array(Si);pos=0;#e;#t;#i;#s;constructor(e,t=[],s){this.#e=e,this.#i=[...t,T],this.#s=s,this.#t=new B({filter:()=>!1,onwarn:(n,r,o)=>{throw o instanceof Error?o:bi}})}get position(){return this.#t.position}get want(){return Math.min(Si,this.#e-this.pos)}push(e){let t=this.buf.subarray(0,e);if(this.pos===0&&this.#i.some(r=>r.detect(t)))throw Xe();let s=this.#t;this.pos+=e;let n=0;s.push(t);try{for(let r;r=s.next();){if(r.type!=="entry")return!1;let{entry:o}=r;if(n=s.offset+512*Math.ceil(o.size/512),n>this.#e)return!1;o.mtime&&this.#s?.set(o.path,o.mtime)}this.pos<n&&(s.skipBody(),this.pos=n)}catch(r){if(r!==bi)throw r;return!1}return e>0&&this.pos<this.#e}},ce=async(i,e)=>{let t=y(i);Ei(t,e);let{fs:s,file:n}=t,r=We(t,e);if(r.codec)throw new TypeError(Xe().message);let o=await s.open(n,"r+").catch(c=>{if(c?.code!=="ENOENT")throw c;return s.open(n,"w+",t.mode||438)}),a=!1;try{let{size:c}=await o.stat(),h=new Oe(c,t.codecs,t.mtimeCache);for(;h.push((await o.read(h.buf,0,h.want,h.pos)).bytesRead););await wt(o,r,h.position),a=!0}finally{let c=o.close();await(a?c:c.catch(Es))}},Ze=(i,e)=>{let t=y(i);Ei(t,e);let{fs:s,file:n}=t,r=gt(t,e);if(r.codec)throw new TypeError(Xe().message);let o;try{o=s.openSync(n,"r+")}catch(a){if(a?.code!=="ENOENT")throw a;o=s.openSync(n,"w+",t.mode||438)}try{let{size:a}=s.fstatSync(o),c=new Oe(a,t.codecs,t.mtimeCache);for(;c.push(s.readSync(o,c.buf,0,c.want,c.pos)););yt(s,o,r,c.position)}catch(a){try{s.closeSync(o)}catch{}throw a}s.closeSync(o)};var vs=(i,e)=>{let t=e.getTime(),s=i.getTime();return(t%1e3===0?s-s%1e3:s)>t},vi=i=>{let{filter:e}=i,t=i.mtimeCache??new Map;return{...i,mtimeCache:t,filter:(s,n)=>{if(e&&!e(s,n))return!1;if("isDirectory"in n&&n.isDirectory())return!0;let r=t.get(s);return!r||!n.mtime||vs(n.mtime,r)}}},Je=(i,e)=>ce(vi(i),e),Ri=(i,e)=>Ze(vi(i),e);import{constants as As}from"node:buffer";import*as Ts from"node:zlib";var Qe=64*1024,et=(i,e=!1,t)=>{let s,n,r=!1,o=!1,a,c,h=e?new Uint8Array(Qe):void 0,l=0,d=u=>new Promise(m=>{a=m,i.write(u,()=>m())}),p=async u=>{l&&await d(u.subarray(0,l)),l=0},f=()=>{o=!0,a?.(),c?.()},w=()=>{f(),i.destroy()};return i.pause(),i.on("data",u=>{t?.(u),t=void 0,r=!1,i.pause(),s.enqueue(u)}),i.on("end",()=>{o||s.close()}),i.on("error",u=>{s.error(u),n.error(u),f()}),i.on("close",f),{readable:new ReadableStream({start:u=>{s=u},pull:()=>{r=!0,c?.(),i.resume()},cancel:u=>{n.error(u),w()}},{highWaterMark:0}),writable:new WritableStream({start:u=>{n=u;let{signal:m}=u;m.addEventListener("abort",()=>{s.error(m.reason),w()})},write:async u=>{h?(l+u.length>Qe&&await p(h),u.length>Qe?await d(u):(h.set(u,l),l+=u.length)):await d(u),!r&&!o&&await new Promise(m=>c=m)},close:async()=>{h&&await p(h),await new Promise(u=>{a=u,i.end()})}})}},Os=i=>i>=As.MAX_LENGTH?{}:{maxOutputLength:Math.max(1,Math.floor(i))},St=(i,e,t,s,n)=>({...i,decompress:()=>et(t({chunkSize:Qe})),compress:r=>et(e(r),!0),decompressSync:(r,{maxOutputLength:o})=>{try{return n(r,Os(o))}catch(a){throw a?.code!=="ERR_BUFFER_TOO_LARGE"?a:new Error(`max decompression ratio exceeded: the output is larger than ${o} bytes`)}},compressSync:s}),Ai=i=>{i[9]=255},bt=(i=Ts)=>{let{createBrotliCompress:e,createBrotliDecompress:t,brotliCompressSync:s,brotliDecompressSync:n,createZstdCompress:r,createZstdDecompress:o,zstdCompressSync:a,zstdDecompressSync:c}=i,l=[{...St({name:"gzip",headLength:2,detect:d=>d[0]===31&&d[1]===139},i.createGzip,i.createGunzip,i.gzipSync,i.gunzipSync),compress:({portable:d,...p}={})=>et(i.createGzip(p),!0,d?Ai:void 0),compressSync:(d,{portable:p,...f}={})=>{let w=i.gzipSync(d,f);return p&&Ai(w),w}}];return e&&t&&s&&n&&l.push(St({name:"brotli",headLength:0,detect:()=>!1,extensions:[".tar.br",".tbr"]},e,t,s,n)),r&&o&&a&&c&&l.push(St({name:"zstd",headLength:4,detect:d=>d[0]===40&&d[1]===181&&d[2]===47&&d[3]===253},r,o,a,c)),l};var Q=zs,ee=Ps,Ns=process.platform==="win32"?"win32":"posix",Us=bt(),x=(i,e,t)=>{let s=y(i);return s.fs??=e,s.platform??=Ns,s.codecs=[...s.codecs??[],...Us],t&&(s.cwd=Fs(s.cwd??""),s.processUid??=process.getuid?.(),s.processGid??=process.getgid?.(),s.processUname??=process.env.USER,s.chmod&&(s.processUmask??=process.umask())),s},ko=(i,e={})=>lt(i,x(e,Q,!1)),So=(i,e={})=>Bt(i,x(e,ee,!1)),bo=(i,e)=>Ve(x(i,Q,!1),e),Eo=(i,e)=>ni(x(i,ee,!1),e),vo=(i,e)=>Ke(x(i,Q,!0),e),Ro=(i,e)=>ki(x(i,ee,!0),e);function Ao(i,e){return ne(x(i,Q,!0),e)}function To(i,e){return Ye(x(i,ee,!0),e)}var Oo=(i,e)=>ce(x(i,Q,!0),e),Po=(i,e)=>Ze(x(i,ee,!0),e),zo=(i,e)=>Je(x(i,Q,!0),e),Fo=(i,e)=>Ri(x(i,ee,!0),e),No=(i,e)=>xt(x(i,Q,!1),e),Uo=(i,e)=>ai(x(i,ee,!1),e);export{Oe as AppendScan,re as CwdError,me as EntryCursor,q as EntryData,R as Header,Se as Pack,ke as PackBase,F as PackJob,be as PackSync,B as Parser,ve as PathReservations,I as Pax,fe as ReadEntry,ue as ReadEntrySync,G as SymlinkError,b as TarReader,E as TarReaderSync,Ae as Unpack,Re as UnpackBase,Te as UnpackSync,se as WriteEntry,Ot as aliases,Ao as c,et as codecStream,Ao as create,To as createSync,No as delete,Uo as deleteSync,ko as entries,So as entriesSync,vo as extract,Ro as extractSync,T as gzip,bo as list,Eo as listSync,Oo as r,Oo as replace,Po as replaceSync,bo as t,nt as types,zo as u,zo as update,Fo as updateSync,vo as x,bt as zlibCodecs};
3
3
  //# sourceMappingURL=index.min.js.map