@keystrokehq/cli 0.0.1
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.
- package/AGENTS-blurb.md +123 -0
- package/LICENSE +42 -0
- package/README.md +177 -0
- package/THIRD_PARTY_NOTICES.md +16 -0
- package/bin/keystroke.mjs +107 -0
- package/dist/_manifest-JSRE3H8k.mjs +385 -0
- package/dist/agent-bundle-package-DWV6B_5q-BtV7Xycc.mjs +2344 -0
- package/dist/agent-manifest-CDnbkR2f.mjs +245 -0
- package/dist/agents-CZJGxVqV.mjs +228 -0
- package/dist/api-keys-D2lgguuY.mjs +40 -0
- package/dist/auth-DN2VusyU.mjs +59 -0
- package/dist/auth.handler-CT1BQUvu.mjs +340 -0
- package/dist/browser-qwFrUH82.mjs +24 -0
- package/dist/build-agents-BmM_AsSd-BGi9wtzt.mjs +514 -0
- package/dist/build-metadata-BWS7uhd_-DR8gJjTX.mjs +1422 -0
- package/dist/build-progress-DgYKb4hB.mjs +183 -0
- package/dist/build-tasks-CdihpudT-D5r5HUHe.mjs +91 -0
- package/dist/build-workflows-CfxBnIWh-CdYPv8w2.mjs +370 -0
- package/dist/build.handler-4799CjWH.mjs +36 -0
- package/dist/chunk-CH6r78ws.mjs +37 -0
- package/dist/clear-cache.handler-B9tqSoSM.mjs +11 -0
- package/dist/clear.handler-BTIXXPTJ.mjs +42 -0
- package/dist/clear.handler-BydlX-zE.mjs +11 -0
- package/dist/commander-DfTVqQ-3.mjs +133 -0
- package/dist/concurrency-gXn9Rw8x-DNl2YtrS.mjs +20 -0
- package/dist/connect-BUXkeH0F.mjs +43 -0
- package/dist/connect.handler-CYel9cy6.mjs +430 -0
- package/dist/constants-CPpPdSNg.mjs +8 -0
- package/dist/context-T7HZuB97.mjs +138 -0
- package/dist/credential-env-map-CI8yWHVy.mjs +28 -0
- package/dist/credential-schema-mismatch-BKo5PjcQ.mjs +76 -0
- package/dist/credentials-CvmjU0lK.mjs +171 -0
- package/dist/credentials-OfVHOtG3.mjs +151216 -0
- package/dist/current-deployment-workflow-poHt27i3.mjs +94 -0
- package/dist/current.handler-B8zKzfPp.mjs +21 -0
- package/dist/delete.handler-bAu1iXVQ.mjs +17 -0
- package/dist/deploy-7Jjls436.mjs +26 -0
- package/dist/deploy-BOPIpRWm.mjs +74 -0
- package/dist/deploy-progress-BmGUNFKg.mjs +70 -0
- package/dist/deploy.handler-BAzgiNhd.mjs +370 -0
- package/dist/detect-env-access-CwkOYeYM-D_BCZqV6.mjs +209 -0
- package/dist/diff-utils-NEfcjqxt.mjs +185 -0
- package/dist/diff.handler-Du7SY8K4.mjs +47 -0
- package/dist/dist-BkJUoBiG.mjs +1116 -0
- package/dist/dist-CUK7yBM0.mjs +308 -0
- package/dist/env-91KwMKov.mjs +140 -0
- package/dist/env.handler-BAzBuMzQ.mjs +277 -0
- package/dist/error-boundary-VL-JLfIa.mjs +34 -0
- package/dist/file-metadata-D1vm-XY2.mjs +191 -0
- package/dist/get-intrinsic-zLxwtrLK.mjs +658 -0
- package/dist/import-module-CV84H5fZ-B_CBCmb4.mjs +1747 -0
- package/dist/init-DpMCotSK.mjs +45 -0
- package/dist/init.handler-CPRnif52.mjs +585 -0
- package/dist/inspect.handler-DT_cD036.mjs +146 -0
- package/dist/integration-catalog-Bt-L3GjF.mjs +104 -0
- package/dist/integrations-DlatPK4W.mjs +79 -0
- package/dist/keystroke.d.mts +3 -0
- package/dist/keystroke.mjs +707 -0
- package/dist/layout-CbMtQ2tm.mjs +67 -0
- package/dist/list-enrichment-y-cwizLr.mjs +189 -0
- package/dist/list.handler-BTWvCyjA.mjs +52 -0
- package/dist/list.handler-CWF_Dj15.mjs +24 -0
- package/dist/list.handler-CZ6G2x_G.mjs +75 -0
- package/dist/list.handler-DWaQkJaR.mjs +51 -0
- package/dist/list.handler-DqbFcBW7.mjs +180 -0
- package/dist/list.handler-lq3ZGAn4.mjs +104 -0
- package/dist/logs-BEg9L5l8.mjs +28 -0
- package/dist/logs.handler-6hoMBzqw.mjs +35 -0
- package/dist/logs.handler-BD_dXiL1.mjs +231 -0
- package/dist/metadata-layout-GUYIUo0i-_aG2zjue.mjs +5877 -0
- package/dist/normalize-path-CojS-CgQ-DLCOvnD1.mjs +20 -0
- package/dist/options-CeaTcFxP.mjs +43 -0
- package/dist/org-xLzBtt2_.mjs +41 -0
- package/dist/output-DM4b7KgY.mjs +72 -0
- package/dist/oxc-B3KI3rf_-n9d1hKNq.mjs +119 -0
- package/dist/paused.handler-BMFm9Cff.mjs +94 -0
- package/dist/project-config-D1qsQlO7.mjs +107 -0
- package/dist/projects-CHkRE9rS.mjs +1574 -0
- package/dist/projects-Cjb7sovS.mjs +30 -0
- package/dist/read-credential-keys-77a91T8M-KA0Iw0Z1.mjs +9 -0
- package/dist/register.handler-BPCdor1_.mjs +86 -0
- package/dist/requirements.handler-DPXdSks3.mjs +201 -0
- package/dist/resolve-project-DDJ29sCF.mjs +35 -0
- package/dist/rolldown-runtime-twds-ZHy-BWWzu8VG.mjs +15 -0
- package/dist/run-polling-CAgFRdK3.mjs +20 -0
- package/dist/runs-D9hNLb9A.mjs +259 -0
- package/dist/schedule-BXx3uXwr.mjs +1142 -0
- package/dist/schema-17qMfNyI.mjs +18 -0
- package/dist/schema-display-CgmeKigW.mjs +130 -0
- package/dist/schemas-CDib1RhE.mjs +125 -0
- package/dist/skills-sync.handler-DIy8GR16.mjs +34 -0
- package/dist/skills.command-CrjI2dN9.mjs +35 -0
- package/dist/skills.handler-Bz8bJKql.mjs +9 -0
- package/dist/source-analysis-Cj-ADyu--BJQcFPCG.mjs +144 -0
- package/dist/spinner-progress-DMVwgqO9.mjs +173 -0
- package/dist/src-C0X6u_Mw.mjs +1340 -0
- package/dist/src-eHwu-Gfw.mjs +369 -0
- package/dist/status.handler-BO4nwvWn.mjs +101 -0
- package/dist/switch.handler-D_9213Vf.mjs +51 -0
- package/dist/sync-BL_Mo5st.mjs +39 -0
- package/dist/sync-keystroke-agent-skills-Kx_H7UTd.mjs +70 -0
- package/dist/sync.handler-BUFPdzWz.mjs +82 -0
- package/dist/task-B2sZMaZu.mjs +8 -0
- package/dist/task-target-build-CBeCKbu2.mjs +432 -0
- package/dist/task-target-deploy-C5X-USeR.mjs +4 -0
- package/dist/task-target-deploy-CA6elFpF-BEr4gkol.mjs +271 -0
- package/dist/task-target-deploy-runner.d.mts +3 -0
- package/dist/task-target-deploy-runner.mjs +202 -0
- package/dist/test-BHTgR3UA.mjs +698 -0
- package/dist/test.handler-BcPQ8b74.mjs +13 -0
- package/dist/trigger-artifacts-DQPbQNqC-B4yeeFBY.mjs +239 -0
- package/dist/trigger-manifest-CY7brZeg.mjs +30 -0
- package/dist/try-deploy.handler-DqybNhXx.mjs +490 -0
- package/dist/upload-CkU--iDC.mjs +207 -0
- package/dist/upload.handler-DCtiznQp.mjs +441 -0
- package/dist/utils-CywxCDM7.mjs +14 -0
- package/dist/validate.handler-DOcTaJL0.mjs +280 -0
- package/dist/workflow-build-DBQaBfnn.mjs +1819 -0
- package/dist/workflow-bundler-BPiqVscj-X1PFFAuP.mjs +167 -0
- package/dist/workflows-g9z87AJJ.mjs +799 -0
- package/dist/writer-BG8poUm3-BbXlU2kI.mjs +426 -0
- package/package.json +87 -0
|
@@ -0,0 +1,2344 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { i as __toESM, r as __require, t as __commonJSMin } from "./chunk-CH6r78ws.mjs";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { Readable } from "node:stream";
|
|
6
|
+
import { createGunzip, createGzip } from "node:zlib";
|
|
7
|
+
//#region ../../node_modules/.pnpm/events-universal@1.0.1/node_modules/events-universal/default.js
|
|
8
|
+
var require_default = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
9
|
+
module.exports = __require("events");
|
|
10
|
+
}));
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region ../../node_modules/.pnpm/fast-fifo@1.3.2/node_modules/fast-fifo/fixed-size.js
|
|
13
|
+
var require_fixed_size = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
14
|
+
module.exports = class FixedFIFO {
|
|
15
|
+
constructor(hwm) {
|
|
16
|
+
if (!(hwm > 0) || (hwm - 1 & hwm) !== 0) throw new Error("Max size for a FixedFIFO should be a power of two");
|
|
17
|
+
this.buffer = new Array(hwm);
|
|
18
|
+
this.mask = hwm - 1;
|
|
19
|
+
this.top = 0;
|
|
20
|
+
this.btm = 0;
|
|
21
|
+
this.next = null;
|
|
22
|
+
}
|
|
23
|
+
clear() {
|
|
24
|
+
this.top = this.btm = 0;
|
|
25
|
+
this.next = null;
|
|
26
|
+
this.buffer.fill(void 0);
|
|
27
|
+
}
|
|
28
|
+
push(data) {
|
|
29
|
+
if (this.buffer[this.top] !== void 0) return false;
|
|
30
|
+
this.buffer[this.top] = data;
|
|
31
|
+
this.top = this.top + 1 & this.mask;
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
shift() {
|
|
35
|
+
const last = this.buffer[this.btm];
|
|
36
|
+
if (last === void 0) return void 0;
|
|
37
|
+
this.buffer[this.btm] = void 0;
|
|
38
|
+
this.btm = this.btm + 1 & this.mask;
|
|
39
|
+
return last;
|
|
40
|
+
}
|
|
41
|
+
peek() {
|
|
42
|
+
return this.buffer[this.btm];
|
|
43
|
+
}
|
|
44
|
+
isEmpty() {
|
|
45
|
+
return this.buffer[this.btm] === void 0;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}));
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region ../../node_modules/.pnpm/fast-fifo@1.3.2/node_modules/fast-fifo/index.js
|
|
51
|
+
var require_fast_fifo = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
52
|
+
const FixedFIFO = require_fixed_size();
|
|
53
|
+
module.exports = class FastFIFO {
|
|
54
|
+
constructor(hwm) {
|
|
55
|
+
this.hwm = hwm || 16;
|
|
56
|
+
this.head = new FixedFIFO(this.hwm);
|
|
57
|
+
this.tail = this.head;
|
|
58
|
+
this.length = 0;
|
|
59
|
+
}
|
|
60
|
+
clear() {
|
|
61
|
+
this.head = this.tail;
|
|
62
|
+
this.head.clear();
|
|
63
|
+
this.length = 0;
|
|
64
|
+
}
|
|
65
|
+
push(val) {
|
|
66
|
+
this.length++;
|
|
67
|
+
if (!this.head.push(val)) {
|
|
68
|
+
const prev = this.head;
|
|
69
|
+
this.head = prev.next = new FixedFIFO(2 * this.head.buffer.length);
|
|
70
|
+
this.head.push(val);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
shift() {
|
|
74
|
+
if (this.length !== 0) this.length--;
|
|
75
|
+
const val = this.tail.shift();
|
|
76
|
+
if (val === void 0 && this.tail.next) {
|
|
77
|
+
const next = this.tail.next;
|
|
78
|
+
this.tail.next = null;
|
|
79
|
+
this.tail = next;
|
|
80
|
+
return this.tail.shift();
|
|
81
|
+
}
|
|
82
|
+
return val;
|
|
83
|
+
}
|
|
84
|
+
peek() {
|
|
85
|
+
const val = this.tail.peek();
|
|
86
|
+
if (val === void 0 && this.tail.next) return this.tail.next.peek();
|
|
87
|
+
return val;
|
|
88
|
+
}
|
|
89
|
+
isEmpty() {
|
|
90
|
+
return this.length === 0;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}));
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region ../../node_modules/.pnpm/b4a@1.8.0/node_modules/b4a/index.js
|
|
96
|
+
var require_b4a = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
97
|
+
function isBuffer(value) {
|
|
98
|
+
return Buffer.isBuffer(value) || value instanceof Uint8Array;
|
|
99
|
+
}
|
|
100
|
+
function isEncoding(encoding) {
|
|
101
|
+
return Buffer.isEncoding(encoding);
|
|
102
|
+
}
|
|
103
|
+
function alloc(size, fill, encoding) {
|
|
104
|
+
return Buffer.alloc(size, fill, encoding);
|
|
105
|
+
}
|
|
106
|
+
function allocUnsafe(size) {
|
|
107
|
+
return Buffer.allocUnsafe(size);
|
|
108
|
+
}
|
|
109
|
+
function allocUnsafeSlow(size) {
|
|
110
|
+
return Buffer.allocUnsafeSlow(size);
|
|
111
|
+
}
|
|
112
|
+
function byteLength(string, encoding) {
|
|
113
|
+
return Buffer.byteLength(string, encoding);
|
|
114
|
+
}
|
|
115
|
+
function compare(a, b) {
|
|
116
|
+
return Buffer.compare(a, b);
|
|
117
|
+
}
|
|
118
|
+
function concat(buffers, totalLength) {
|
|
119
|
+
return Buffer.concat(buffers, totalLength);
|
|
120
|
+
}
|
|
121
|
+
function copy(source, target, targetStart, start, end) {
|
|
122
|
+
return toBuffer(source).copy(target, targetStart, start, end);
|
|
123
|
+
}
|
|
124
|
+
function equals(a, b) {
|
|
125
|
+
return toBuffer(a).equals(b);
|
|
126
|
+
}
|
|
127
|
+
function fill(buffer, value, offset, end, encoding) {
|
|
128
|
+
return toBuffer(buffer).fill(value, offset, end, encoding);
|
|
129
|
+
}
|
|
130
|
+
function from(value, encodingOrOffset, length) {
|
|
131
|
+
return Buffer.from(value, encodingOrOffset, length);
|
|
132
|
+
}
|
|
133
|
+
function includes(buffer, value, byteOffset, encoding) {
|
|
134
|
+
return toBuffer(buffer).includes(value, byteOffset, encoding);
|
|
135
|
+
}
|
|
136
|
+
function indexOf(buffer, value, byfeOffset, encoding) {
|
|
137
|
+
return toBuffer(buffer).indexOf(value, byfeOffset, encoding);
|
|
138
|
+
}
|
|
139
|
+
function lastIndexOf(buffer, value, byteOffset, encoding) {
|
|
140
|
+
return toBuffer(buffer).lastIndexOf(value, byteOffset, encoding);
|
|
141
|
+
}
|
|
142
|
+
function swap16(buffer) {
|
|
143
|
+
return toBuffer(buffer).swap16();
|
|
144
|
+
}
|
|
145
|
+
function swap32(buffer) {
|
|
146
|
+
return toBuffer(buffer).swap32();
|
|
147
|
+
}
|
|
148
|
+
function swap64(buffer) {
|
|
149
|
+
return toBuffer(buffer).swap64();
|
|
150
|
+
}
|
|
151
|
+
function toBuffer(buffer) {
|
|
152
|
+
if (Buffer.isBuffer(buffer)) return buffer;
|
|
153
|
+
return Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
154
|
+
}
|
|
155
|
+
function toString(buffer, encoding, start, end) {
|
|
156
|
+
return toBuffer(buffer).toString(encoding, start, end);
|
|
157
|
+
}
|
|
158
|
+
function write(buffer, string, offset, length, encoding) {
|
|
159
|
+
return toBuffer(buffer).write(string, offset, length, encoding);
|
|
160
|
+
}
|
|
161
|
+
function readDoubleBE(buffer, offset) {
|
|
162
|
+
return toBuffer(buffer).readDoubleBE(offset);
|
|
163
|
+
}
|
|
164
|
+
function readDoubleLE(buffer, offset) {
|
|
165
|
+
return toBuffer(buffer).readDoubleLE(offset);
|
|
166
|
+
}
|
|
167
|
+
function readFloatBE(buffer, offset) {
|
|
168
|
+
return toBuffer(buffer).readFloatBE(offset);
|
|
169
|
+
}
|
|
170
|
+
function readFloatLE(buffer, offset) {
|
|
171
|
+
return toBuffer(buffer).readFloatLE(offset);
|
|
172
|
+
}
|
|
173
|
+
function readInt32BE(buffer, offset) {
|
|
174
|
+
return toBuffer(buffer).readInt32BE(offset);
|
|
175
|
+
}
|
|
176
|
+
function readInt32LE(buffer, offset) {
|
|
177
|
+
return toBuffer(buffer).readInt32LE(offset);
|
|
178
|
+
}
|
|
179
|
+
function readUInt32BE(buffer, offset) {
|
|
180
|
+
return toBuffer(buffer).readUInt32BE(offset);
|
|
181
|
+
}
|
|
182
|
+
function readUInt32LE(buffer, offset) {
|
|
183
|
+
return toBuffer(buffer).readUInt32LE(offset);
|
|
184
|
+
}
|
|
185
|
+
function writeDoubleBE(buffer, value, offset) {
|
|
186
|
+
return toBuffer(buffer).writeDoubleBE(value, offset);
|
|
187
|
+
}
|
|
188
|
+
function writeDoubleLE(buffer, value, offset) {
|
|
189
|
+
return toBuffer(buffer).writeDoubleLE(value, offset);
|
|
190
|
+
}
|
|
191
|
+
function writeFloatBE(buffer, value, offset) {
|
|
192
|
+
return toBuffer(buffer).writeFloatBE(value, offset);
|
|
193
|
+
}
|
|
194
|
+
function writeFloatLE(buffer, value, offset) {
|
|
195
|
+
return toBuffer(buffer).writeFloatLE(value, offset);
|
|
196
|
+
}
|
|
197
|
+
function writeInt32BE(buffer, value, offset) {
|
|
198
|
+
return toBuffer(buffer).writeInt32BE(value, offset);
|
|
199
|
+
}
|
|
200
|
+
function writeInt32LE(buffer, value, offset) {
|
|
201
|
+
return toBuffer(buffer).writeInt32LE(value, offset);
|
|
202
|
+
}
|
|
203
|
+
function writeUInt32BE(buffer, value, offset) {
|
|
204
|
+
return toBuffer(buffer).writeUInt32BE(value, offset);
|
|
205
|
+
}
|
|
206
|
+
function writeUInt32LE(buffer, value, offset) {
|
|
207
|
+
return toBuffer(buffer).writeUInt32LE(value, offset);
|
|
208
|
+
}
|
|
209
|
+
module.exports = {
|
|
210
|
+
isBuffer,
|
|
211
|
+
isEncoding,
|
|
212
|
+
alloc,
|
|
213
|
+
allocUnsafe,
|
|
214
|
+
allocUnsafeSlow,
|
|
215
|
+
byteLength,
|
|
216
|
+
compare,
|
|
217
|
+
concat,
|
|
218
|
+
copy,
|
|
219
|
+
equals,
|
|
220
|
+
fill,
|
|
221
|
+
from,
|
|
222
|
+
includes,
|
|
223
|
+
indexOf,
|
|
224
|
+
lastIndexOf,
|
|
225
|
+
swap16,
|
|
226
|
+
swap32,
|
|
227
|
+
swap64,
|
|
228
|
+
toBuffer,
|
|
229
|
+
toString,
|
|
230
|
+
write,
|
|
231
|
+
readDoubleBE,
|
|
232
|
+
readDoubleLE,
|
|
233
|
+
readFloatBE,
|
|
234
|
+
readFloatLE,
|
|
235
|
+
readInt32BE,
|
|
236
|
+
readInt32LE,
|
|
237
|
+
readUInt32BE,
|
|
238
|
+
readUInt32LE,
|
|
239
|
+
writeDoubleBE,
|
|
240
|
+
writeDoubleLE,
|
|
241
|
+
writeFloatBE,
|
|
242
|
+
writeFloatLE,
|
|
243
|
+
writeInt32BE,
|
|
244
|
+
writeInt32LE,
|
|
245
|
+
writeUInt32BE,
|
|
246
|
+
writeUInt32LE
|
|
247
|
+
};
|
|
248
|
+
}));
|
|
249
|
+
//#endregion
|
|
250
|
+
//#region ../../node_modules/.pnpm/text-decoder@1.2.7/node_modules/text-decoder/lib/pass-through-decoder.js
|
|
251
|
+
var require_pass_through_decoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
252
|
+
const b4a = require_b4a();
|
|
253
|
+
module.exports = class PassThroughDecoder {
|
|
254
|
+
constructor(encoding) {
|
|
255
|
+
this.encoding = encoding;
|
|
256
|
+
}
|
|
257
|
+
get remaining() {
|
|
258
|
+
return 0;
|
|
259
|
+
}
|
|
260
|
+
decode(data) {
|
|
261
|
+
return b4a.toString(data, this.encoding);
|
|
262
|
+
}
|
|
263
|
+
flush() {
|
|
264
|
+
return "";
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
}));
|
|
268
|
+
//#endregion
|
|
269
|
+
//#region ../../node_modules/.pnpm/text-decoder@1.2.7/node_modules/text-decoder/lib/utf8-decoder.js
|
|
270
|
+
var require_utf8_decoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
271
|
+
const b4a = require_b4a();
|
|
272
|
+
/**
|
|
273
|
+
* https://encoding.spec.whatwg.org/#utf-8-decoder
|
|
274
|
+
*/
|
|
275
|
+
module.exports = class UTF8Decoder {
|
|
276
|
+
constructor() {
|
|
277
|
+
this._reset();
|
|
278
|
+
}
|
|
279
|
+
get remaining() {
|
|
280
|
+
return this.bytesSeen;
|
|
281
|
+
}
|
|
282
|
+
decode(data) {
|
|
283
|
+
if (data.byteLength === 0) return "";
|
|
284
|
+
if (this.bytesNeeded === 0 && trailingIncomplete(data, 0) === 0) {
|
|
285
|
+
this.bytesSeen = trailingBytesSeen(data);
|
|
286
|
+
return b4a.toString(data, "utf8");
|
|
287
|
+
}
|
|
288
|
+
let result = "";
|
|
289
|
+
let start = 0;
|
|
290
|
+
if (this.bytesNeeded > 0) {
|
|
291
|
+
while (start < data.byteLength) {
|
|
292
|
+
const byte = data[start];
|
|
293
|
+
if (byte < this.lowerBoundary || byte > this.upperBoundary) {
|
|
294
|
+
result += "�";
|
|
295
|
+
this._reset();
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
this.lowerBoundary = 128;
|
|
299
|
+
this.upperBoundary = 191;
|
|
300
|
+
this.codePoint = this.codePoint << 6 | byte & 63;
|
|
301
|
+
this.bytesSeen++;
|
|
302
|
+
start++;
|
|
303
|
+
if (this.bytesSeen === this.bytesNeeded) {
|
|
304
|
+
result += String.fromCodePoint(this.codePoint);
|
|
305
|
+
this._reset();
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
if (this.bytesNeeded > 0) return result;
|
|
310
|
+
}
|
|
311
|
+
const trailing = trailingIncomplete(data, start);
|
|
312
|
+
const end = data.byteLength - trailing;
|
|
313
|
+
if (end > start) result += b4a.toString(data, "utf8", start, end);
|
|
314
|
+
for (let i = end; i < data.byteLength; i++) {
|
|
315
|
+
const byte = data[i];
|
|
316
|
+
if (this.bytesNeeded === 0) {
|
|
317
|
+
if (byte <= 127) {
|
|
318
|
+
this.bytesSeen = 0;
|
|
319
|
+
result += String.fromCharCode(byte);
|
|
320
|
+
} else if (byte >= 194 && byte <= 223) {
|
|
321
|
+
this.bytesNeeded = 2;
|
|
322
|
+
this.bytesSeen = 1;
|
|
323
|
+
this.codePoint = byte & 31;
|
|
324
|
+
} else if (byte >= 224 && byte <= 239) {
|
|
325
|
+
if (byte === 224) this.lowerBoundary = 160;
|
|
326
|
+
else if (byte === 237) this.upperBoundary = 159;
|
|
327
|
+
this.bytesNeeded = 3;
|
|
328
|
+
this.bytesSeen = 1;
|
|
329
|
+
this.codePoint = byte & 15;
|
|
330
|
+
} else if (byte >= 240 && byte <= 244) {
|
|
331
|
+
if (byte === 240) this.lowerBoundary = 144;
|
|
332
|
+
else if (byte === 244) this.upperBoundary = 143;
|
|
333
|
+
this.bytesNeeded = 4;
|
|
334
|
+
this.bytesSeen = 1;
|
|
335
|
+
this.codePoint = byte & 7;
|
|
336
|
+
} else {
|
|
337
|
+
this.bytesSeen = 1;
|
|
338
|
+
result += "�";
|
|
339
|
+
}
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
if (byte < this.lowerBoundary || byte > this.upperBoundary) {
|
|
343
|
+
result += "�";
|
|
344
|
+
i--;
|
|
345
|
+
this._reset();
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
this.lowerBoundary = 128;
|
|
349
|
+
this.upperBoundary = 191;
|
|
350
|
+
this.codePoint = this.codePoint << 6 | byte & 63;
|
|
351
|
+
this.bytesSeen++;
|
|
352
|
+
if (this.bytesSeen === this.bytesNeeded) {
|
|
353
|
+
result += String.fromCodePoint(this.codePoint);
|
|
354
|
+
this._reset();
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return result;
|
|
358
|
+
}
|
|
359
|
+
flush() {
|
|
360
|
+
const result = this.bytesNeeded > 0 ? "�" : "";
|
|
361
|
+
this._reset();
|
|
362
|
+
return result;
|
|
363
|
+
}
|
|
364
|
+
_reset() {
|
|
365
|
+
this.codePoint = 0;
|
|
366
|
+
this.bytesNeeded = 0;
|
|
367
|
+
this.bytesSeen = 0;
|
|
368
|
+
this.lowerBoundary = 128;
|
|
369
|
+
this.upperBoundary = 191;
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
function trailingIncomplete(data, start) {
|
|
373
|
+
const len = data.byteLength;
|
|
374
|
+
if (len <= start) return 0;
|
|
375
|
+
const limit = Math.max(start, len - 4);
|
|
376
|
+
let i = len - 1;
|
|
377
|
+
while (i > limit && (data[i] & 192) === 128) i--;
|
|
378
|
+
if (i < start) return 0;
|
|
379
|
+
const byte = data[i];
|
|
380
|
+
let needed;
|
|
381
|
+
if (byte <= 127) return 0;
|
|
382
|
+
if (byte >= 194 && byte <= 223) needed = 2;
|
|
383
|
+
else if (byte >= 224 && byte <= 239) needed = 3;
|
|
384
|
+
else if (byte >= 240 && byte <= 244) needed = 4;
|
|
385
|
+
else return 0;
|
|
386
|
+
const available = len - i;
|
|
387
|
+
return available < needed ? available : 0;
|
|
388
|
+
}
|
|
389
|
+
function trailingBytesSeen(data) {
|
|
390
|
+
const len = data.byteLength;
|
|
391
|
+
if (len === 0) return 0;
|
|
392
|
+
const last = data[len - 1];
|
|
393
|
+
if (last <= 127) return 0;
|
|
394
|
+
if ((last & 192) !== 128) return 1;
|
|
395
|
+
const limit = Math.max(0, len - 4);
|
|
396
|
+
let i = len - 2;
|
|
397
|
+
while (i >= limit && (data[i] & 192) === 128) i--;
|
|
398
|
+
if (i < 0) return 1;
|
|
399
|
+
const first = data[i];
|
|
400
|
+
let needed;
|
|
401
|
+
if (first >= 194 && first <= 223) needed = 2;
|
|
402
|
+
else if (first >= 224 && first <= 239) needed = 3;
|
|
403
|
+
else if (first >= 240 && first <= 244) needed = 4;
|
|
404
|
+
else return 1;
|
|
405
|
+
if (len - i !== needed) return 1;
|
|
406
|
+
if (needed >= 3) {
|
|
407
|
+
const second = data[i + 1];
|
|
408
|
+
if (first === 224 && second < 160) return 1;
|
|
409
|
+
if (first === 237 && second > 159) return 1;
|
|
410
|
+
if (first === 240 && second < 144) return 1;
|
|
411
|
+
if (first === 244 && second > 143) return 1;
|
|
412
|
+
}
|
|
413
|
+
return 0;
|
|
414
|
+
}
|
|
415
|
+
}));
|
|
416
|
+
//#endregion
|
|
417
|
+
//#region ../../node_modules/.pnpm/text-decoder@1.2.7/node_modules/text-decoder/index.js
|
|
418
|
+
var require_text_decoder = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
419
|
+
const PassThroughDecoder = require_pass_through_decoder();
|
|
420
|
+
const UTF8Decoder = require_utf8_decoder();
|
|
421
|
+
module.exports = class TextDecoder {
|
|
422
|
+
constructor(encoding = "utf8") {
|
|
423
|
+
this.encoding = normalizeEncoding(encoding);
|
|
424
|
+
switch (this.encoding) {
|
|
425
|
+
case "utf8":
|
|
426
|
+
this.decoder = new UTF8Decoder();
|
|
427
|
+
break;
|
|
428
|
+
case "utf16le":
|
|
429
|
+
case "base64": throw new Error("Unsupported encoding: " + this.encoding);
|
|
430
|
+
default: this.decoder = new PassThroughDecoder(this.encoding);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
get remaining() {
|
|
434
|
+
return this.decoder.remaining;
|
|
435
|
+
}
|
|
436
|
+
push(data) {
|
|
437
|
+
if (typeof data === "string") return data;
|
|
438
|
+
return this.decoder.decode(data);
|
|
439
|
+
}
|
|
440
|
+
write(data) {
|
|
441
|
+
return this.push(data);
|
|
442
|
+
}
|
|
443
|
+
end(data) {
|
|
444
|
+
let result = "";
|
|
445
|
+
if (data) result = this.push(data);
|
|
446
|
+
result += this.decoder.flush();
|
|
447
|
+
return result;
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
function normalizeEncoding(encoding) {
|
|
451
|
+
encoding = encoding.toLowerCase();
|
|
452
|
+
switch (encoding) {
|
|
453
|
+
case "utf8":
|
|
454
|
+
case "utf-8": return "utf8";
|
|
455
|
+
case "ucs2":
|
|
456
|
+
case "ucs-2":
|
|
457
|
+
case "utf16le":
|
|
458
|
+
case "utf-16le": return "utf16le";
|
|
459
|
+
case "latin1":
|
|
460
|
+
case "binary": return "latin1";
|
|
461
|
+
case "base64":
|
|
462
|
+
case "ascii":
|
|
463
|
+
case "hex": return encoding;
|
|
464
|
+
default: throw new Error("Unknown encoding: " + encoding);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}));
|
|
468
|
+
//#endregion
|
|
469
|
+
//#region ../../node_modules/.pnpm/streamx@2.25.0/node_modules/streamx/index.js
|
|
470
|
+
var require_streamx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
471
|
+
const { EventEmitter } = require_default();
|
|
472
|
+
const STREAM_DESTROYED = /* @__PURE__ */ new Error("Stream was destroyed");
|
|
473
|
+
const PREMATURE_CLOSE = /* @__PURE__ */ new Error("Premature close");
|
|
474
|
+
const FIFO = require_fast_fifo();
|
|
475
|
+
const TextDecoder = require_text_decoder();
|
|
476
|
+
const qmt = typeof queueMicrotask === "undefined" ? (fn) => global.process.nextTick(fn) : queueMicrotask;
|
|
477
|
+
const MAX = (1 << 29) - 1;
|
|
478
|
+
const OPENING = 1;
|
|
479
|
+
const PREDESTROYING = 2;
|
|
480
|
+
const DESTROYING = 4;
|
|
481
|
+
const DESTROYED = 8;
|
|
482
|
+
const NOT_OPENING = MAX ^ OPENING;
|
|
483
|
+
const NOT_PREDESTROYING = MAX ^ PREDESTROYING;
|
|
484
|
+
const READ_ACTIVE = 16;
|
|
485
|
+
const READ_UPDATING = 32;
|
|
486
|
+
const READ_PRIMARY = 64;
|
|
487
|
+
const READ_QUEUED = 128;
|
|
488
|
+
const READ_RESUMED = 256;
|
|
489
|
+
const READ_PIPE_DRAINED = 512;
|
|
490
|
+
const READ_ENDING = 1024;
|
|
491
|
+
const READ_EMIT_DATA = 2048;
|
|
492
|
+
const READ_EMIT_READABLE = 4096;
|
|
493
|
+
const READ_EMITTED_READABLE = 8192;
|
|
494
|
+
const READ_DONE = 16384;
|
|
495
|
+
const READ_NEXT_TICK = 32768;
|
|
496
|
+
const READ_NEEDS_PUSH = 65536;
|
|
497
|
+
const READ_READ_AHEAD = 131072;
|
|
498
|
+
const READ_FLOWING = READ_RESUMED | READ_PIPE_DRAINED;
|
|
499
|
+
const READ_ACTIVE_AND_NEEDS_PUSH = READ_ACTIVE | READ_NEEDS_PUSH;
|
|
500
|
+
const READ_PRIMARY_AND_ACTIVE = READ_PRIMARY | READ_ACTIVE;
|
|
501
|
+
const READ_EMIT_READABLE_AND_QUEUED = READ_EMIT_READABLE | READ_QUEUED;
|
|
502
|
+
const READ_RESUMED_READ_AHEAD = READ_RESUMED | READ_READ_AHEAD;
|
|
503
|
+
const READ_NOT_ACTIVE = MAX ^ READ_ACTIVE;
|
|
504
|
+
const READ_NON_PRIMARY = MAX ^ READ_PRIMARY;
|
|
505
|
+
const READ_NON_PRIMARY_AND_PUSHED = MAX ^ (READ_PRIMARY | READ_NEEDS_PUSH);
|
|
506
|
+
const READ_PUSHED = MAX ^ READ_NEEDS_PUSH;
|
|
507
|
+
const READ_PAUSED = MAX ^ READ_RESUMED;
|
|
508
|
+
const READ_NOT_QUEUED = MAX ^ (READ_QUEUED | READ_EMITTED_READABLE);
|
|
509
|
+
const READ_NOT_ENDING = MAX ^ READ_ENDING;
|
|
510
|
+
const READ_PIPE_NOT_DRAINED = MAX ^ READ_FLOWING;
|
|
511
|
+
const READ_NOT_NEXT_TICK = MAX ^ READ_NEXT_TICK;
|
|
512
|
+
const READ_NOT_UPDATING = MAX ^ READ_UPDATING;
|
|
513
|
+
const READ_NO_READ_AHEAD = MAX ^ READ_READ_AHEAD;
|
|
514
|
+
const READ_PAUSED_NO_READ_AHEAD = MAX ^ READ_RESUMED_READ_AHEAD;
|
|
515
|
+
const WRITE_ACTIVE = 1 << 18;
|
|
516
|
+
const WRITE_UPDATING = 2 << 18;
|
|
517
|
+
const WRITE_PRIMARY = 4 << 18;
|
|
518
|
+
const WRITE_QUEUED = 8 << 18;
|
|
519
|
+
const WRITE_UNDRAINED = 16 << 18;
|
|
520
|
+
const WRITE_DONE = 32 << 18;
|
|
521
|
+
const WRITE_EMIT_DRAIN = 64 << 18;
|
|
522
|
+
const WRITE_NEXT_TICK = 128 << 18;
|
|
523
|
+
const WRITE_WRITING = 256 << 18;
|
|
524
|
+
const WRITE_FINISHING = 512 << 18;
|
|
525
|
+
const WRITE_CORKED = 1024 << 18;
|
|
526
|
+
const WRITE_NOT_ACTIVE = MAX ^ (WRITE_ACTIVE | WRITE_WRITING);
|
|
527
|
+
const WRITE_NON_PRIMARY = MAX ^ WRITE_PRIMARY;
|
|
528
|
+
const WRITE_NOT_FINISHING = MAX ^ (WRITE_ACTIVE | WRITE_FINISHING);
|
|
529
|
+
const WRITE_DRAINED = MAX ^ WRITE_UNDRAINED;
|
|
530
|
+
const WRITE_NOT_QUEUED = MAX ^ WRITE_QUEUED;
|
|
531
|
+
const WRITE_NOT_NEXT_TICK = MAX ^ WRITE_NEXT_TICK;
|
|
532
|
+
const WRITE_NOT_UPDATING = MAX ^ WRITE_UPDATING;
|
|
533
|
+
const WRITE_NOT_CORKED = MAX ^ WRITE_CORKED;
|
|
534
|
+
const ACTIVE = READ_ACTIVE | WRITE_ACTIVE;
|
|
535
|
+
const NOT_ACTIVE = MAX ^ ACTIVE;
|
|
536
|
+
const DONE = READ_DONE | WRITE_DONE;
|
|
537
|
+
const DESTROY_STATUS = DESTROYED | 6;
|
|
538
|
+
const OPEN_STATUS = DESTROY_STATUS | OPENING;
|
|
539
|
+
const AUTO_DESTROY = DESTROY_STATUS | DONE;
|
|
540
|
+
const NON_PRIMARY = WRITE_NON_PRIMARY & READ_NON_PRIMARY;
|
|
541
|
+
const ACTIVE_OR_TICKING = WRITE_NEXT_TICK | READ_NEXT_TICK;
|
|
542
|
+
const IS_OPENING = OPEN_STATUS | ACTIVE_OR_TICKING & NOT_ACTIVE;
|
|
543
|
+
const READ_PRIMARY_STATUS = READ_ENDING | 16399;
|
|
544
|
+
const READ_STATUS = READ_DONE | 143;
|
|
545
|
+
const READ_ENDING_STATUS = READ_ENDING | 143;
|
|
546
|
+
const READ_READABLE_STATUS = 12431;
|
|
547
|
+
const SHOULD_NOT_READ = 214047;
|
|
548
|
+
const READ_BACKPRESSURE_STATUS = READ_ENDING | 16398;
|
|
549
|
+
const READ_UPDATE_SYNC_STATUS = 32879;
|
|
550
|
+
const READ_NEXT_TICK_OR_OPENING = READ_NEXT_TICK | OPENING;
|
|
551
|
+
const WRITE_PRIMARY_STATUS = WRITE_FINISHING | 8388623;
|
|
552
|
+
const WRITE_QUEUED_AND_UNDRAINED = WRITE_QUEUED | WRITE_UNDRAINED;
|
|
553
|
+
const WRITE_QUEUED_AND_ACTIVE = WRITE_QUEUED | WRITE_ACTIVE;
|
|
554
|
+
const WRITE_DRAIN_STATUS = 6553615;
|
|
555
|
+
const WRITE_STATUS = 270794767;
|
|
556
|
+
const WRITE_PRIMARY_AND_ACTIVE = WRITE_PRIMARY | WRITE_ACTIVE;
|
|
557
|
+
const WRITE_ACTIVE_AND_WRITING = WRITE_ACTIVE | WRITE_WRITING;
|
|
558
|
+
const WRITE_FINISHING_STATUS = 144965647;
|
|
559
|
+
const WRITE_BACKPRESSURE_STATUS = 146800654;
|
|
560
|
+
const WRITE_UPDATE_SYNC_STATUS = 35127311;
|
|
561
|
+
const WRITE_DROP_DATA = WRITE_DONE | 134217742;
|
|
562
|
+
const asyncIterator = Symbol.asyncIterator || Symbol("asyncIterator");
|
|
563
|
+
var WritableState = class {
|
|
564
|
+
constructor(stream, { highWaterMark = 16384, map = null, mapWritable, byteLength, byteLengthWritable } = {}) {
|
|
565
|
+
this.stream = stream;
|
|
566
|
+
this.queue = new FIFO();
|
|
567
|
+
this.highWaterMark = highWaterMark;
|
|
568
|
+
this.buffered = 0;
|
|
569
|
+
this.error = null;
|
|
570
|
+
this.pipeline = null;
|
|
571
|
+
this.drains = null;
|
|
572
|
+
this.byteLength = byteLengthWritable || byteLength || defaultByteLength;
|
|
573
|
+
this.map = mapWritable || map;
|
|
574
|
+
this.afterWrite = afterWrite.bind(this);
|
|
575
|
+
this.afterUpdateNextTick = updateWriteNT.bind(this);
|
|
576
|
+
}
|
|
577
|
+
get ending() {
|
|
578
|
+
return (this.stream._duplexState & WRITE_FINISHING) !== 0;
|
|
579
|
+
}
|
|
580
|
+
get ended() {
|
|
581
|
+
return (this.stream._duplexState & WRITE_DONE) !== 0;
|
|
582
|
+
}
|
|
583
|
+
push(data) {
|
|
584
|
+
if ((this.stream._duplexState & WRITE_DROP_DATA) !== 0) return false;
|
|
585
|
+
if (this.map !== null) data = this.map(data);
|
|
586
|
+
this.buffered += this.byteLength(data);
|
|
587
|
+
this.queue.push(data);
|
|
588
|
+
if (this.buffered < this.highWaterMark) {
|
|
589
|
+
this.stream._duplexState |= WRITE_QUEUED;
|
|
590
|
+
return true;
|
|
591
|
+
}
|
|
592
|
+
this.stream._duplexState |= WRITE_QUEUED_AND_UNDRAINED;
|
|
593
|
+
return false;
|
|
594
|
+
}
|
|
595
|
+
shift() {
|
|
596
|
+
const data = this.queue.shift();
|
|
597
|
+
this.buffered -= this.byteLength(data);
|
|
598
|
+
if (this.buffered === 0) this.stream._duplexState &= WRITE_NOT_QUEUED;
|
|
599
|
+
return data;
|
|
600
|
+
}
|
|
601
|
+
end(data) {
|
|
602
|
+
if (typeof data === "function") this.stream.once("finish", data);
|
|
603
|
+
else if (data !== void 0 && data !== null) this.push(data);
|
|
604
|
+
this.stream._duplexState = (this.stream._duplexState | WRITE_FINISHING) & WRITE_NON_PRIMARY;
|
|
605
|
+
}
|
|
606
|
+
autoBatch(data, cb) {
|
|
607
|
+
const buffer = [];
|
|
608
|
+
const stream = this.stream;
|
|
609
|
+
buffer.push(data);
|
|
610
|
+
while ((stream._duplexState & WRITE_STATUS) === WRITE_QUEUED_AND_ACTIVE) buffer.push(stream._writableState.shift());
|
|
611
|
+
if ((stream._duplexState & OPEN_STATUS) !== 0) return cb(null);
|
|
612
|
+
stream._writev(buffer, cb);
|
|
613
|
+
}
|
|
614
|
+
update() {
|
|
615
|
+
const stream = this.stream;
|
|
616
|
+
stream._duplexState |= WRITE_UPDATING;
|
|
617
|
+
do {
|
|
618
|
+
while ((stream._duplexState & WRITE_STATUS) === WRITE_QUEUED) {
|
|
619
|
+
const data = this.shift();
|
|
620
|
+
stream._duplexState |= WRITE_ACTIVE_AND_WRITING;
|
|
621
|
+
stream._write(data, this.afterWrite);
|
|
622
|
+
}
|
|
623
|
+
if ((stream._duplexState & WRITE_PRIMARY_AND_ACTIVE) === 0) this.updateNonPrimary();
|
|
624
|
+
} while (this.continueUpdate() === true);
|
|
625
|
+
stream._duplexState &= WRITE_NOT_UPDATING;
|
|
626
|
+
}
|
|
627
|
+
updateNonPrimary() {
|
|
628
|
+
const stream = this.stream;
|
|
629
|
+
if ((stream._duplexState & WRITE_FINISHING_STATUS) === WRITE_FINISHING) {
|
|
630
|
+
stream._duplexState = stream._duplexState | WRITE_ACTIVE;
|
|
631
|
+
stream._final(afterFinal.bind(this));
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
if ((stream._duplexState & DESTROY_STATUS) === DESTROYING) {
|
|
635
|
+
if ((stream._duplexState & ACTIVE_OR_TICKING) === 0) {
|
|
636
|
+
stream._duplexState |= ACTIVE;
|
|
637
|
+
stream._destroy(afterDestroy.bind(this));
|
|
638
|
+
}
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
if ((stream._duplexState & IS_OPENING) === OPENING) {
|
|
642
|
+
stream._duplexState = (stream._duplexState | ACTIVE) & NOT_OPENING;
|
|
643
|
+
stream._open(afterOpen.bind(this));
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
continueUpdate() {
|
|
647
|
+
if ((this.stream._duplexState & WRITE_NEXT_TICK) === 0) return false;
|
|
648
|
+
this.stream._duplexState &= WRITE_NOT_NEXT_TICK;
|
|
649
|
+
return true;
|
|
650
|
+
}
|
|
651
|
+
updateCallback() {
|
|
652
|
+
if ((this.stream._duplexState & WRITE_UPDATE_SYNC_STATUS) === WRITE_PRIMARY) this.update();
|
|
653
|
+
else this.updateNextTick();
|
|
654
|
+
}
|
|
655
|
+
updateNextTick() {
|
|
656
|
+
if ((this.stream._duplexState & WRITE_NEXT_TICK) !== 0) return;
|
|
657
|
+
this.stream._duplexState |= WRITE_NEXT_TICK;
|
|
658
|
+
if ((this.stream._duplexState & WRITE_UPDATING) === 0) qmt(this.afterUpdateNextTick);
|
|
659
|
+
}
|
|
660
|
+
};
|
|
661
|
+
var ReadableState = class {
|
|
662
|
+
constructor(stream, { highWaterMark = 16384, map = null, mapReadable, byteLength, byteLengthReadable } = {}) {
|
|
663
|
+
this.stream = stream;
|
|
664
|
+
this.queue = new FIFO();
|
|
665
|
+
this.highWaterMark = highWaterMark === 0 ? 1 : highWaterMark;
|
|
666
|
+
this.buffered = 0;
|
|
667
|
+
this.readAhead = highWaterMark > 0;
|
|
668
|
+
this.error = null;
|
|
669
|
+
this.pipeline = null;
|
|
670
|
+
this.byteLength = byteLengthReadable || byteLength || defaultByteLength;
|
|
671
|
+
this.map = mapReadable || map;
|
|
672
|
+
this.pipeTo = null;
|
|
673
|
+
this.afterRead = afterRead.bind(this);
|
|
674
|
+
this.afterUpdateNextTick = updateReadNT.bind(this);
|
|
675
|
+
}
|
|
676
|
+
get ending() {
|
|
677
|
+
return (this.stream._duplexState & READ_ENDING) !== 0;
|
|
678
|
+
}
|
|
679
|
+
get ended() {
|
|
680
|
+
return (this.stream._duplexState & READ_DONE) !== 0;
|
|
681
|
+
}
|
|
682
|
+
pipe(pipeTo, cb) {
|
|
683
|
+
if (this.pipeTo !== null) throw new Error("Can only pipe to one destination");
|
|
684
|
+
if (typeof cb !== "function") cb = null;
|
|
685
|
+
this.stream._duplexState |= READ_PIPE_DRAINED;
|
|
686
|
+
this.pipeTo = pipeTo;
|
|
687
|
+
this.pipeline = new Pipeline(this.stream, pipeTo, cb);
|
|
688
|
+
if (cb) this.stream.on("error", noop);
|
|
689
|
+
if (isStreamx(pipeTo)) {
|
|
690
|
+
pipeTo._writableState.pipeline = this.pipeline;
|
|
691
|
+
if (cb) pipeTo.on("error", noop);
|
|
692
|
+
pipeTo.on("finish", this.pipeline.finished.bind(this.pipeline));
|
|
693
|
+
} else {
|
|
694
|
+
const onerror = this.pipeline.done.bind(this.pipeline, pipeTo);
|
|
695
|
+
const onclose = this.pipeline.done.bind(this.pipeline, pipeTo, null);
|
|
696
|
+
pipeTo.on("error", onerror);
|
|
697
|
+
pipeTo.on("close", onclose);
|
|
698
|
+
pipeTo.on("finish", this.pipeline.finished.bind(this.pipeline));
|
|
699
|
+
}
|
|
700
|
+
pipeTo.on("drain", afterDrain.bind(this));
|
|
701
|
+
this.stream.emit("piping", pipeTo);
|
|
702
|
+
pipeTo.emit("pipe", this.stream);
|
|
703
|
+
}
|
|
704
|
+
push(data) {
|
|
705
|
+
const stream = this.stream;
|
|
706
|
+
if (data === null) {
|
|
707
|
+
this.highWaterMark = 0;
|
|
708
|
+
stream._duplexState = (stream._duplexState | READ_ENDING) & READ_NON_PRIMARY_AND_PUSHED;
|
|
709
|
+
return false;
|
|
710
|
+
}
|
|
711
|
+
if (this.map !== null) {
|
|
712
|
+
data = this.map(data);
|
|
713
|
+
if (data === null) {
|
|
714
|
+
stream._duplexState &= READ_PUSHED;
|
|
715
|
+
return this.buffered < this.highWaterMark;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
this.buffered += this.byteLength(data);
|
|
719
|
+
this.queue.push(data);
|
|
720
|
+
stream._duplexState = (stream._duplexState | READ_QUEUED) & READ_PUSHED;
|
|
721
|
+
return this.buffered < this.highWaterMark;
|
|
722
|
+
}
|
|
723
|
+
shift() {
|
|
724
|
+
const data = this.queue.shift();
|
|
725
|
+
this.buffered -= this.byteLength(data);
|
|
726
|
+
if (this.buffered === 0) this.stream._duplexState &= READ_NOT_QUEUED;
|
|
727
|
+
return data;
|
|
728
|
+
}
|
|
729
|
+
unshift(data) {
|
|
730
|
+
const pending = [this.map !== null ? this.map(data) : data];
|
|
731
|
+
while (this.buffered > 0) pending.push(this.shift());
|
|
732
|
+
for (let i = 0; i < pending.length - 1; i++) {
|
|
733
|
+
const data = pending[i];
|
|
734
|
+
this.buffered += this.byteLength(data);
|
|
735
|
+
this.queue.push(data);
|
|
736
|
+
}
|
|
737
|
+
this.push(pending[pending.length - 1]);
|
|
738
|
+
}
|
|
739
|
+
read() {
|
|
740
|
+
const stream = this.stream;
|
|
741
|
+
if ((stream._duplexState & READ_STATUS) === READ_QUEUED) {
|
|
742
|
+
const data = this.shift();
|
|
743
|
+
if (this.pipeTo !== null && this.pipeTo.write(data) === false) stream._duplexState &= READ_PIPE_NOT_DRAINED;
|
|
744
|
+
if ((stream._duplexState & READ_EMIT_DATA) !== 0) stream.emit("data", data);
|
|
745
|
+
return data;
|
|
746
|
+
}
|
|
747
|
+
if (this.readAhead === false) {
|
|
748
|
+
stream._duplexState |= READ_READ_AHEAD;
|
|
749
|
+
this.updateNextTick();
|
|
750
|
+
}
|
|
751
|
+
return null;
|
|
752
|
+
}
|
|
753
|
+
drain() {
|
|
754
|
+
const stream = this.stream;
|
|
755
|
+
while ((stream._duplexState & READ_STATUS) === READ_QUEUED && (stream._duplexState & READ_FLOWING) !== 0) {
|
|
756
|
+
const data = this.shift();
|
|
757
|
+
if (this.pipeTo !== null && this.pipeTo.write(data) === false) stream._duplexState &= READ_PIPE_NOT_DRAINED;
|
|
758
|
+
if ((stream._duplexState & READ_EMIT_DATA) !== 0) stream.emit("data", data);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
update() {
|
|
762
|
+
const stream = this.stream;
|
|
763
|
+
stream._duplexState |= READ_UPDATING;
|
|
764
|
+
do {
|
|
765
|
+
this.drain();
|
|
766
|
+
while (this.buffered < this.highWaterMark && (stream._duplexState & SHOULD_NOT_READ) === READ_READ_AHEAD) {
|
|
767
|
+
stream._duplexState |= READ_ACTIVE_AND_NEEDS_PUSH;
|
|
768
|
+
stream._read(this.afterRead);
|
|
769
|
+
this.drain();
|
|
770
|
+
}
|
|
771
|
+
if ((stream._duplexState & READ_READABLE_STATUS) === READ_EMIT_READABLE_AND_QUEUED) {
|
|
772
|
+
stream._duplexState |= READ_EMITTED_READABLE;
|
|
773
|
+
stream.emit("readable");
|
|
774
|
+
}
|
|
775
|
+
if ((stream._duplexState & READ_PRIMARY_AND_ACTIVE) === 0) this.updateNonPrimary();
|
|
776
|
+
} while (this.continueUpdate() === true);
|
|
777
|
+
stream._duplexState &= READ_NOT_UPDATING;
|
|
778
|
+
}
|
|
779
|
+
updateNonPrimary() {
|
|
780
|
+
const stream = this.stream;
|
|
781
|
+
if ((stream._duplexState & READ_ENDING_STATUS) === READ_ENDING) {
|
|
782
|
+
stream._duplexState = (stream._duplexState | READ_DONE) & READ_NOT_ENDING;
|
|
783
|
+
stream.emit("end");
|
|
784
|
+
if ((stream._duplexState & AUTO_DESTROY) === DONE) stream._duplexState |= DESTROYING;
|
|
785
|
+
if (this.pipeTo !== null) this.pipeTo.end();
|
|
786
|
+
}
|
|
787
|
+
if ((stream._duplexState & DESTROY_STATUS) === DESTROYING) {
|
|
788
|
+
if ((stream._duplexState & ACTIVE_OR_TICKING) === 0) {
|
|
789
|
+
stream._duplexState |= ACTIVE;
|
|
790
|
+
stream._destroy(afterDestroy.bind(this));
|
|
791
|
+
}
|
|
792
|
+
return;
|
|
793
|
+
}
|
|
794
|
+
if ((stream._duplexState & IS_OPENING) === OPENING) {
|
|
795
|
+
stream._duplexState = (stream._duplexState | ACTIVE) & NOT_OPENING;
|
|
796
|
+
stream._open(afterOpen.bind(this));
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
continueUpdate() {
|
|
800
|
+
if ((this.stream._duplexState & READ_NEXT_TICK) === 0) return false;
|
|
801
|
+
this.stream._duplexState &= READ_NOT_NEXT_TICK;
|
|
802
|
+
return true;
|
|
803
|
+
}
|
|
804
|
+
updateCallback() {
|
|
805
|
+
if ((this.stream._duplexState & READ_UPDATE_SYNC_STATUS) === READ_PRIMARY) this.update();
|
|
806
|
+
else this.updateNextTick();
|
|
807
|
+
}
|
|
808
|
+
updateNextTickIfOpen() {
|
|
809
|
+
if ((this.stream._duplexState & READ_NEXT_TICK_OR_OPENING) !== 0) return;
|
|
810
|
+
this.stream._duplexState |= READ_NEXT_TICK;
|
|
811
|
+
if ((this.stream._duplexState & READ_UPDATING) === 0) qmt(this.afterUpdateNextTick);
|
|
812
|
+
}
|
|
813
|
+
updateNextTick() {
|
|
814
|
+
if ((this.stream._duplexState & READ_NEXT_TICK) !== 0) return;
|
|
815
|
+
this.stream._duplexState |= READ_NEXT_TICK;
|
|
816
|
+
if ((this.stream._duplexState & READ_UPDATING) === 0) qmt(this.afterUpdateNextTick);
|
|
817
|
+
}
|
|
818
|
+
};
|
|
819
|
+
var TransformState = class {
|
|
820
|
+
constructor(stream) {
|
|
821
|
+
this.data = null;
|
|
822
|
+
this.afterTransform = afterTransform.bind(stream);
|
|
823
|
+
this.afterFinal = null;
|
|
824
|
+
}
|
|
825
|
+
};
|
|
826
|
+
var Pipeline = class {
|
|
827
|
+
constructor(src, dst, cb) {
|
|
828
|
+
this.from = src;
|
|
829
|
+
this.to = dst;
|
|
830
|
+
this.afterPipe = cb;
|
|
831
|
+
this.error = null;
|
|
832
|
+
this.pipeToFinished = false;
|
|
833
|
+
}
|
|
834
|
+
finished() {
|
|
835
|
+
this.pipeToFinished = true;
|
|
836
|
+
}
|
|
837
|
+
done(stream, err) {
|
|
838
|
+
if (err) this.error = err;
|
|
839
|
+
if (stream === this.to) {
|
|
840
|
+
this.to = null;
|
|
841
|
+
if (this.from !== null) {
|
|
842
|
+
if ((this.from._duplexState & READ_DONE) === 0 || !this.pipeToFinished) this.from.destroy(this.error || /* @__PURE__ */ new Error("Writable stream closed prematurely"));
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
if (stream === this.from) {
|
|
847
|
+
this.from = null;
|
|
848
|
+
if (this.to !== null) {
|
|
849
|
+
if ((stream._duplexState & READ_DONE) === 0) this.to.destroy(this.error || /* @__PURE__ */ new Error("Readable stream closed before ending"));
|
|
850
|
+
return;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
if (this.afterPipe !== null) this.afterPipe(this.error);
|
|
854
|
+
this.to = this.from = this.afterPipe = null;
|
|
855
|
+
}
|
|
856
|
+
};
|
|
857
|
+
function afterDrain() {
|
|
858
|
+
this.stream._duplexState |= READ_PIPE_DRAINED;
|
|
859
|
+
this.updateCallback();
|
|
860
|
+
}
|
|
861
|
+
function afterFinal(err) {
|
|
862
|
+
const stream = this.stream;
|
|
863
|
+
if (err) stream.destroy(err);
|
|
864
|
+
if ((stream._duplexState & DESTROY_STATUS) === 0) {
|
|
865
|
+
stream._duplexState |= WRITE_DONE;
|
|
866
|
+
stream.emit("finish");
|
|
867
|
+
}
|
|
868
|
+
if ((stream._duplexState & AUTO_DESTROY) === DONE) stream._duplexState |= DESTROYING;
|
|
869
|
+
stream._duplexState &= WRITE_NOT_FINISHING;
|
|
870
|
+
if ((stream._duplexState & WRITE_UPDATING) === 0) this.update();
|
|
871
|
+
else this.updateNextTick();
|
|
872
|
+
}
|
|
873
|
+
function afterDestroy(err) {
|
|
874
|
+
const stream = this.stream;
|
|
875
|
+
if (!err && this.error !== STREAM_DESTROYED) err = this.error;
|
|
876
|
+
if (err) stream.emit("error", err);
|
|
877
|
+
stream._duplexState |= DESTROYED;
|
|
878
|
+
stream.emit("close");
|
|
879
|
+
const rs = stream._readableState;
|
|
880
|
+
const ws = stream._writableState;
|
|
881
|
+
if (rs !== null && rs.pipeline !== null) rs.pipeline.done(stream, err);
|
|
882
|
+
if (ws !== null) {
|
|
883
|
+
while (ws.drains !== null && ws.drains.length > 0) ws.drains.shift().resolve(false);
|
|
884
|
+
if (ws.pipeline !== null) ws.pipeline.done(stream, err);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
function afterWrite(err) {
|
|
888
|
+
const stream = this.stream;
|
|
889
|
+
if (err) stream.destroy(err);
|
|
890
|
+
stream._duplexState &= WRITE_NOT_ACTIVE;
|
|
891
|
+
if (this.drains !== null) tickDrains(this.drains);
|
|
892
|
+
if ((stream._duplexState & WRITE_DRAIN_STATUS) === WRITE_UNDRAINED) {
|
|
893
|
+
stream._duplexState &= WRITE_DRAINED;
|
|
894
|
+
if ((stream._duplexState & WRITE_EMIT_DRAIN) === WRITE_EMIT_DRAIN) stream.emit("drain");
|
|
895
|
+
}
|
|
896
|
+
this.updateCallback();
|
|
897
|
+
}
|
|
898
|
+
function afterRead(err) {
|
|
899
|
+
if (err) this.stream.destroy(err);
|
|
900
|
+
this.stream._duplexState &= READ_NOT_ACTIVE;
|
|
901
|
+
if (this.readAhead === false && (this.stream._duplexState & READ_RESUMED) === 0) this.stream._duplexState &= READ_NO_READ_AHEAD;
|
|
902
|
+
this.updateCallback();
|
|
903
|
+
}
|
|
904
|
+
function updateReadNT() {
|
|
905
|
+
if ((this.stream._duplexState & READ_UPDATING) === 0) {
|
|
906
|
+
this.stream._duplexState &= READ_NOT_NEXT_TICK;
|
|
907
|
+
this.update();
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
function updateWriteNT() {
|
|
911
|
+
if ((this.stream._duplexState & WRITE_UPDATING) === 0) {
|
|
912
|
+
this.stream._duplexState &= WRITE_NOT_NEXT_TICK;
|
|
913
|
+
this.update();
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
function tickDrains(drains) {
|
|
917
|
+
for (let i = 0; i < drains.length; i++) if (--drains[i].writes === 0) {
|
|
918
|
+
drains.shift().resolve(true);
|
|
919
|
+
i--;
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
function afterOpen(err) {
|
|
923
|
+
const stream = this.stream;
|
|
924
|
+
if (err) stream.destroy(err);
|
|
925
|
+
if ((stream._duplexState & DESTROYING) === 0) {
|
|
926
|
+
if ((stream._duplexState & READ_PRIMARY_STATUS) === 0) stream._duplexState |= READ_PRIMARY;
|
|
927
|
+
if ((stream._duplexState & WRITE_PRIMARY_STATUS) === 0) stream._duplexState |= WRITE_PRIMARY;
|
|
928
|
+
stream.emit("open");
|
|
929
|
+
}
|
|
930
|
+
stream._duplexState &= NOT_ACTIVE;
|
|
931
|
+
if (stream._writableState !== null) stream._writableState.updateCallback();
|
|
932
|
+
if (stream._readableState !== null) stream._readableState.updateCallback();
|
|
933
|
+
}
|
|
934
|
+
function afterTransform(err, data) {
|
|
935
|
+
if (data !== void 0 && data !== null) this.push(data);
|
|
936
|
+
this._writableState.afterWrite(err);
|
|
937
|
+
}
|
|
938
|
+
function newListener(name) {
|
|
939
|
+
if (this._readableState !== null) {
|
|
940
|
+
if (name === "data") {
|
|
941
|
+
this._duplexState |= READ_EMIT_DATA | READ_RESUMED_READ_AHEAD;
|
|
942
|
+
this._readableState.updateNextTick();
|
|
943
|
+
}
|
|
944
|
+
if (name === "readable") {
|
|
945
|
+
this._duplexState |= READ_EMIT_READABLE;
|
|
946
|
+
this._readableState.updateNextTick();
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
if (this._writableState !== null) {
|
|
950
|
+
if (name === "drain") {
|
|
951
|
+
this._duplexState |= WRITE_EMIT_DRAIN;
|
|
952
|
+
this._writableState.updateNextTick();
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
var Stream = class extends EventEmitter {
|
|
957
|
+
constructor(opts) {
|
|
958
|
+
super();
|
|
959
|
+
this._duplexState = 0;
|
|
960
|
+
this._readableState = null;
|
|
961
|
+
this._writableState = null;
|
|
962
|
+
if (opts) {
|
|
963
|
+
if (opts.open) this._open = opts.open;
|
|
964
|
+
if (opts.destroy) this._destroy = opts.destroy;
|
|
965
|
+
if (opts.predestroy) this._predestroy = opts.predestroy;
|
|
966
|
+
if (opts.signal) opts.signal.addEventListener("abort", abort.bind(this));
|
|
967
|
+
}
|
|
968
|
+
this.on("newListener", newListener);
|
|
969
|
+
}
|
|
970
|
+
_open(cb) {
|
|
971
|
+
cb(null);
|
|
972
|
+
}
|
|
973
|
+
_destroy(cb) {
|
|
974
|
+
cb(null);
|
|
975
|
+
}
|
|
976
|
+
_predestroy() {}
|
|
977
|
+
get readable() {
|
|
978
|
+
return this._readableState !== null ? true : void 0;
|
|
979
|
+
}
|
|
980
|
+
get writable() {
|
|
981
|
+
return this._writableState !== null ? true : void 0;
|
|
982
|
+
}
|
|
983
|
+
get destroyed() {
|
|
984
|
+
return (this._duplexState & DESTROYED) !== 0;
|
|
985
|
+
}
|
|
986
|
+
get destroying() {
|
|
987
|
+
return (this._duplexState & DESTROY_STATUS) !== 0;
|
|
988
|
+
}
|
|
989
|
+
destroy(err) {
|
|
990
|
+
if ((this._duplexState & DESTROY_STATUS) === 0) {
|
|
991
|
+
if (!err) err = STREAM_DESTROYED;
|
|
992
|
+
this._duplexState = (this._duplexState | DESTROYING) & NON_PRIMARY;
|
|
993
|
+
if (this._readableState !== null) {
|
|
994
|
+
this._readableState.highWaterMark = 0;
|
|
995
|
+
this._readableState.error = err;
|
|
996
|
+
}
|
|
997
|
+
if (this._writableState !== null) {
|
|
998
|
+
this._writableState.highWaterMark = 0;
|
|
999
|
+
this._writableState.error = err;
|
|
1000
|
+
}
|
|
1001
|
+
this._duplexState |= PREDESTROYING;
|
|
1002
|
+
this._predestroy();
|
|
1003
|
+
this._duplexState &= NOT_PREDESTROYING;
|
|
1004
|
+
if (this._readableState !== null) this._readableState.updateNextTick();
|
|
1005
|
+
if (this._writableState !== null) this._writableState.updateNextTick();
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
};
|
|
1009
|
+
var Readable = class Readable extends Stream {
|
|
1010
|
+
constructor(opts) {
|
|
1011
|
+
super(opts);
|
|
1012
|
+
this._duplexState |= WRITE_DONE | 131073;
|
|
1013
|
+
this._readableState = new ReadableState(this, opts);
|
|
1014
|
+
if (opts) {
|
|
1015
|
+
if (this._readableState.readAhead === false) this._duplexState &= READ_NO_READ_AHEAD;
|
|
1016
|
+
if (opts.read) this._read = opts.read;
|
|
1017
|
+
if (opts.eagerOpen) this._readableState.updateNextTick();
|
|
1018
|
+
if (opts.encoding) this.setEncoding(opts.encoding);
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
setEncoding(encoding) {
|
|
1022
|
+
const dec = new TextDecoder(encoding);
|
|
1023
|
+
const map = this._readableState.map || echo;
|
|
1024
|
+
this._readableState.map = mapOrSkip;
|
|
1025
|
+
return this;
|
|
1026
|
+
function mapOrSkip(data) {
|
|
1027
|
+
const next = dec.push(data);
|
|
1028
|
+
return next === "" && (data.byteLength !== 0 || dec.remaining > 0) ? null : map(next);
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
_read(cb) {
|
|
1032
|
+
cb(null);
|
|
1033
|
+
}
|
|
1034
|
+
pipe(dest, cb) {
|
|
1035
|
+
this._readableState.updateNextTick();
|
|
1036
|
+
this._readableState.pipe(dest, cb);
|
|
1037
|
+
return dest;
|
|
1038
|
+
}
|
|
1039
|
+
read() {
|
|
1040
|
+
this._readableState.updateNextTick();
|
|
1041
|
+
return this._readableState.read();
|
|
1042
|
+
}
|
|
1043
|
+
push(data) {
|
|
1044
|
+
this._readableState.updateNextTickIfOpen();
|
|
1045
|
+
return this._readableState.push(data);
|
|
1046
|
+
}
|
|
1047
|
+
unshift(data) {
|
|
1048
|
+
this._readableState.updateNextTickIfOpen();
|
|
1049
|
+
return this._readableState.unshift(data);
|
|
1050
|
+
}
|
|
1051
|
+
resume() {
|
|
1052
|
+
this._duplexState |= READ_RESUMED_READ_AHEAD;
|
|
1053
|
+
this._readableState.updateNextTick();
|
|
1054
|
+
return this;
|
|
1055
|
+
}
|
|
1056
|
+
pause() {
|
|
1057
|
+
this._duplexState &= this._readableState.readAhead === false ? READ_PAUSED_NO_READ_AHEAD : READ_PAUSED;
|
|
1058
|
+
return this;
|
|
1059
|
+
}
|
|
1060
|
+
static _fromAsyncIterator(ite, opts) {
|
|
1061
|
+
let destroy;
|
|
1062
|
+
const rs = new Readable({
|
|
1063
|
+
...opts,
|
|
1064
|
+
read(cb) {
|
|
1065
|
+
ite.next().then(push).then(cb.bind(null, null)).catch(cb);
|
|
1066
|
+
},
|
|
1067
|
+
predestroy() {
|
|
1068
|
+
destroy = ite.return();
|
|
1069
|
+
},
|
|
1070
|
+
destroy(cb) {
|
|
1071
|
+
if (!destroy) return cb(null);
|
|
1072
|
+
destroy.then(cb.bind(null, null)).catch(cb);
|
|
1073
|
+
}
|
|
1074
|
+
});
|
|
1075
|
+
return rs;
|
|
1076
|
+
function push(data) {
|
|
1077
|
+
if (data.done) rs.push(null);
|
|
1078
|
+
else rs.push(data.value);
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
static from(data, opts) {
|
|
1082
|
+
if (isReadStreamx(data)) return data;
|
|
1083
|
+
if (data[asyncIterator]) return this._fromAsyncIterator(data[asyncIterator](), opts);
|
|
1084
|
+
if (!Array.isArray(data)) data = data === void 0 ? [] : [data];
|
|
1085
|
+
let i = 0;
|
|
1086
|
+
return new Readable({
|
|
1087
|
+
...opts,
|
|
1088
|
+
read(cb) {
|
|
1089
|
+
this.push(i === data.length ? null : data[i++]);
|
|
1090
|
+
cb(null);
|
|
1091
|
+
}
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
static isBackpressured(rs) {
|
|
1095
|
+
return (rs._duplexState & READ_BACKPRESSURE_STATUS) !== 0 || rs._readableState.buffered >= rs._readableState.highWaterMark;
|
|
1096
|
+
}
|
|
1097
|
+
static isPaused(rs) {
|
|
1098
|
+
return (rs._duplexState & READ_RESUMED) === 0;
|
|
1099
|
+
}
|
|
1100
|
+
[asyncIterator]() {
|
|
1101
|
+
const stream = this;
|
|
1102
|
+
let error = null;
|
|
1103
|
+
let promiseResolve = null;
|
|
1104
|
+
let promiseReject = null;
|
|
1105
|
+
this.on("error", (err) => {
|
|
1106
|
+
error = err;
|
|
1107
|
+
});
|
|
1108
|
+
this.on("readable", onreadable);
|
|
1109
|
+
this.on("close", onclose);
|
|
1110
|
+
return {
|
|
1111
|
+
[asyncIterator]() {
|
|
1112
|
+
return this;
|
|
1113
|
+
},
|
|
1114
|
+
next() {
|
|
1115
|
+
return new Promise(function(resolve, reject) {
|
|
1116
|
+
promiseResolve = resolve;
|
|
1117
|
+
promiseReject = reject;
|
|
1118
|
+
const data = stream.read();
|
|
1119
|
+
if (data !== null) ondata(data);
|
|
1120
|
+
else if ((stream._duplexState & DESTROYED) !== 0) ondata(null);
|
|
1121
|
+
});
|
|
1122
|
+
},
|
|
1123
|
+
return() {
|
|
1124
|
+
return destroy(null);
|
|
1125
|
+
},
|
|
1126
|
+
throw(err) {
|
|
1127
|
+
return destroy(err);
|
|
1128
|
+
}
|
|
1129
|
+
};
|
|
1130
|
+
function onreadable() {
|
|
1131
|
+
if (promiseResolve !== null) ondata(stream.read());
|
|
1132
|
+
}
|
|
1133
|
+
function onclose() {
|
|
1134
|
+
if (promiseResolve !== null) ondata(null);
|
|
1135
|
+
}
|
|
1136
|
+
function ondata(data) {
|
|
1137
|
+
if (promiseReject === null) return;
|
|
1138
|
+
if (error) promiseReject(error);
|
|
1139
|
+
else if (data === null && (stream._duplexState & READ_DONE) === 0) promiseReject(STREAM_DESTROYED);
|
|
1140
|
+
else promiseResolve({
|
|
1141
|
+
value: data,
|
|
1142
|
+
done: data === null
|
|
1143
|
+
});
|
|
1144
|
+
promiseReject = promiseResolve = null;
|
|
1145
|
+
}
|
|
1146
|
+
function destroy(err) {
|
|
1147
|
+
stream.destroy(err);
|
|
1148
|
+
return new Promise((resolve, reject) => {
|
|
1149
|
+
if (stream._duplexState & DESTROYED) return resolve({
|
|
1150
|
+
value: void 0,
|
|
1151
|
+
done: true
|
|
1152
|
+
});
|
|
1153
|
+
stream.once("close", function() {
|
|
1154
|
+
if (err) reject(err);
|
|
1155
|
+
else resolve({
|
|
1156
|
+
value: void 0,
|
|
1157
|
+
done: true
|
|
1158
|
+
});
|
|
1159
|
+
});
|
|
1160
|
+
});
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
};
|
|
1164
|
+
var Writable = class extends Stream {
|
|
1165
|
+
constructor(opts) {
|
|
1166
|
+
super(opts);
|
|
1167
|
+
this._duplexState |= OPENING | READ_DONE;
|
|
1168
|
+
this._writableState = new WritableState(this, opts);
|
|
1169
|
+
if (opts) {
|
|
1170
|
+
if (opts.writev) this._writev = opts.writev;
|
|
1171
|
+
if (opts.write) this._write = opts.write;
|
|
1172
|
+
if (opts.final) this._final = opts.final;
|
|
1173
|
+
if (opts.eagerOpen) this._writableState.updateNextTick();
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
cork() {
|
|
1177
|
+
this._duplexState |= WRITE_CORKED;
|
|
1178
|
+
}
|
|
1179
|
+
uncork() {
|
|
1180
|
+
this._duplexState &= WRITE_NOT_CORKED;
|
|
1181
|
+
this._writableState.updateNextTick();
|
|
1182
|
+
}
|
|
1183
|
+
_writev(batch, cb) {
|
|
1184
|
+
cb(null);
|
|
1185
|
+
}
|
|
1186
|
+
_write(data, cb) {
|
|
1187
|
+
this._writableState.autoBatch(data, cb);
|
|
1188
|
+
}
|
|
1189
|
+
_final(cb) {
|
|
1190
|
+
cb(null);
|
|
1191
|
+
}
|
|
1192
|
+
static isBackpressured(ws) {
|
|
1193
|
+
return (ws._duplexState & WRITE_BACKPRESSURE_STATUS) !== 0;
|
|
1194
|
+
}
|
|
1195
|
+
static drained(ws) {
|
|
1196
|
+
if (ws.destroyed) return Promise.resolve(false);
|
|
1197
|
+
const state = ws._writableState;
|
|
1198
|
+
const writes = (isWritev(ws) ? Math.min(1, state.queue.length) : state.queue.length) + (ws._duplexState & WRITE_WRITING ? 1 : 0);
|
|
1199
|
+
if (writes === 0) return Promise.resolve(true);
|
|
1200
|
+
if (state.drains === null) state.drains = [];
|
|
1201
|
+
return new Promise((resolve) => {
|
|
1202
|
+
state.drains.push({
|
|
1203
|
+
writes,
|
|
1204
|
+
resolve
|
|
1205
|
+
});
|
|
1206
|
+
});
|
|
1207
|
+
}
|
|
1208
|
+
write(data) {
|
|
1209
|
+
this._writableState.updateNextTick();
|
|
1210
|
+
return this._writableState.push(data);
|
|
1211
|
+
}
|
|
1212
|
+
end(data) {
|
|
1213
|
+
this._writableState.updateNextTick();
|
|
1214
|
+
this._writableState.end(data);
|
|
1215
|
+
return this;
|
|
1216
|
+
}
|
|
1217
|
+
};
|
|
1218
|
+
var Duplex = class extends Readable {
|
|
1219
|
+
constructor(opts) {
|
|
1220
|
+
super(opts);
|
|
1221
|
+
this._duplexState = OPENING | this._duplexState & READ_READ_AHEAD;
|
|
1222
|
+
this._writableState = new WritableState(this, opts);
|
|
1223
|
+
if (opts) {
|
|
1224
|
+
if (opts.writev) this._writev = opts.writev;
|
|
1225
|
+
if (opts.write) this._write = opts.write;
|
|
1226
|
+
if (opts.final) this._final = opts.final;
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
cork() {
|
|
1230
|
+
this._duplexState |= WRITE_CORKED;
|
|
1231
|
+
}
|
|
1232
|
+
uncork() {
|
|
1233
|
+
this._duplexState &= WRITE_NOT_CORKED;
|
|
1234
|
+
this._writableState.updateNextTick();
|
|
1235
|
+
}
|
|
1236
|
+
_writev(batch, cb) {
|
|
1237
|
+
cb(null);
|
|
1238
|
+
}
|
|
1239
|
+
_write(data, cb) {
|
|
1240
|
+
this._writableState.autoBatch(data, cb);
|
|
1241
|
+
}
|
|
1242
|
+
_final(cb) {
|
|
1243
|
+
cb(null);
|
|
1244
|
+
}
|
|
1245
|
+
write(data) {
|
|
1246
|
+
this._writableState.updateNextTick();
|
|
1247
|
+
return this._writableState.push(data);
|
|
1248
|
+
}
|
|
1249
|
+
end(data) {
|
|
1250
|
+
this._writableState.updateNextTick();
|
|
1251
|
+
this._writableState.end(data);
|
|
1252
|
+
return this;
|
|
1253
|
+
}
|
|
1254
|
+
};
|
|
1255
|
+
var Transform = class extends Duplex {
|
|
1256
|
+
constructor(opts) {
|
|
1257
|
+
super(opts);
|
|
1258
|
+
this._transformState = new TransformState(this);
|
|
1259
|
+
if (opts) {
|
|
1260
|
+
if (opts.transform) this._transform = opts.transform;
|
|
1261
|
+
if (opts.flush) this._flush = opts.flush;
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
_write(data, cb) {
|
|
1265
|
+
if (this._readableState.buffered >= this._readableState.highWaterMark) this._transformState.data = data;
|
|
1266
|
+
else this._transform(data, this._transformState.afterTransform);
|
|
1267
|
+
}
|
|
1268
|
+
_read(cb) {
|
|
1269
|
+
if (this._transformState.data !== null) {
|
|
1270
|
+
const data = this._transformState.data;
|
|
1271
|
+
this._transformState.data = null;
|
|
1272
|
+
cb(null);
|
|
1273
|
+
this._transform(data, this._transformState.afterTransform);
|
|
1274
|
+
} else cb(null);
|
|
1275
|
+
}
|
|
1276
|
+
destroy(err) {
|
|
1277
|
+
super.destroy(err);
|
|
1278
|
+
if (this._transformState.data !== null) {
|
|
1279
|
+
this._transformState.data = null;
|
|
1280
|
+
this._transformState.afterTransform();
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
_transform(data, cb) {
|
|
1284
|
+
cb(null, data);
|
|
1285
|
+
}
|
|
1286
|
+
_flush(cb) {
|
|
1287
|
+
cb(null);
|
|
1288
|
+
}
|
|
1289
|
+
_final(cb) {
|
|
1290
|
+
this._transformState.afterFinal = cb;
|
|
1291
|
+
this._flush(transformAfterFlush.bind(this));
|
|
1292
|
+
}
|
|
1293
|
+
};
|
|
1294
|
+
var PassThrough = class extends Transform {};
|
|
1295
|
+
function transformAfterFlush(err, data) {
|
|
1296
|
+
const cb = this._transformState.afterFinal;
|
|
1297
|
+
if (err) return cb(err);
|
|
1298
|
+
if (data !== null && data !== void 0) this.push(data);
|
|
1299
|
+
this.push(null);
|
|
1300
|
+
cb(null);
|
|
1301
|
+
}
|
|
1302
|
+
function pipelinePromise(...streams) {
|
|
1303
|
+
return new Promise((resolve, reject) => {
|
|
1304
|
+
return pipeline(...streams, (err) => {
|
|
1305
|
+
if (err) return reject(err);
|
|
1306
|
+
resolve();
|
|
1307
|
+
});
|
|
1308
|
+
});
|
|
1309
|
+
}
|
|
1310
|
+
function pipeline(stream, ...streams) {
|
|
1311
|
+
const all = Array.isArray(stream) ? [...stream, ...streams] : [stream, ...streams];
|
|
1312
|
+
const done = all.length && typeof all[all.length - 1] === "function" ? all.pop() : null;
|
|
1313
|
+
if (all.length < 2) throw new Error("Pipeline requires at least 2 streams");
|
|
1314
|
+
let src = all[0];
|
|
1315
|
+
let dest = null;
|
|
1316
|
+
let error = null;
|
|
1317
|
+
for (let i = 1; i < all.length; i++) {
|
|
1318
|
+
dest = all[i];
|
|
1319
|
+
if (isStreamx(src)) src.pipe(dest, onerror);
|
|
1320
|
+
else {
|
|
1321
|
+
errorHandle(src, true, i > 1, onerror);
|
|
1322
|
+
src.pipe(dest);
|
|
1323
|
+
}
|
|
1324
|
+
src = dest;
|
|
1325
|
+
}
|
|
1326
|
+
if (done) {
|
|
1327
|
+
let fin = false;
|
|
1328
|
+
const autoDestroy = isStreamx(dest) || !!(dest._writableState && dest._writableState.autoDestroy);
|
|
1329
|
+
dest.on("error", (err) => {
|
|
1330
|
+
if (error === null) error = err;
|
|
1331
|
+
});
|
|
1332
|
+
dest.on("finish", () => {
|
|
1333
|
+
fin = true;
|
|
1334
|
+
if (!autoDestroy) done(error);
|
|
1335
|
+
});
|
|
1336
|
+
if (autoDestroy) dest.on("close", () => done(error || (fin ? null : PREMATURE_CLOSE)));
|
|
1337
|
+
}
|
|
1338
|
+
return dest;
|
|
1339
|
+
function errorHandle(s, rd, wr, onerror) {
|
|
1340
|
+
s.on("error", onerror);
|
|
1341
|
+
s.on("close", onclose);
|
|
1342
|
+
function onclose() {
|
|
1343
|
+
if (rd && s._readableState && !s._readableState.ended) return onerror(PREMATURE_CLOSE);
|
|
1344
|
+
if (wr && s._writableState && !s._writableState.ended) return onerror(PREMATURE_CLOSE);
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
function onerror(err) {
|
|
1348
|
+
if (!err || error) return;
|
|
1349
|
+
error = err;
|
|
1350
|
+
for (const s of all) s.destroy(err);
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
function echo(s) {
|
|
1354
|
+
return s;
|
|
1355
|
+
}
|
|
1356
|
+
function isStream(stream) {
|
|
1357
|
+
return !!stream._readableState || !!stream._writableState;
|
|
1358
|
+
}
|
|
1359
|
+
function isStreamx(stream) {
|
|
1360
|
+
return typeof stream._duplexState === "number" && isStream(stream);
|
|
1361
|
+
}
|
|
1362
|
+
function isEnding(stream) {
|
|
1363
|
+
return !!stream._readableState && stream._readableState.ending;
|
|
1364
|
+
}
|
|
1365
|
+
function isEnded(stream) {
|
|
1366
|
+
return !!stream._readableState && stream._readableState.ended;
|
|
1367
|
+
}
|
|
1368
|
+
function isFinishing(stream) {
|
|
1369
|
+
return !!stream._writableState && stream._writableState.ending;
|
|
1370
|
+
}
|
|
1371
|
+
function isFinished(stream) {
|
|
1372
|
+
return !!stream._writableState && stream._writableState.ended;
|
|
1373
|
+
}
|
|
1374
|
+
function getStreamError(stream, opts = {}) {
|
|
1375
|
+
const err = stream._readableState && stream._readableState.error || stream._writableState && stream._writableState.error;
|
|
1376
|
+
return !opts.all && err === STREAM_DESTROYED ? null : err;
|
|
1377
|
+
}
|
|
1378
|
+
function isReadStreamx(stream) {
|
|
1379
|
+
return isStreamx(stream) && stream.readable;
|
|
1380
|
+
}
|
|
1381
|
+
function isDisturbed(stream) {
|
|
1382
|
+
return (stream._duplexState & OPENING) !== OPENING || (stream._duplexState & DESTROYING) === DESTROYING || (stream._duplexState & ACTIVE_OR_TICKING) !== 0;
|
|
1383
|
+
}
|
|
1384
|
+
function isTypedArray(data) {
|
|
1385
|
+
return typeof data === "object" && data !== null && typeof data.byteLength === "number";
|
|
1386
|
+
}
|
|
1387
|
+
function defaultByteLength(data) {
|
|
1388
|
+
return isTypedArray(data) ? data.byteLength : 1024;
|
|
1389
|
+
}
|
|
1390
|
+
function noop() {}
|
|
1391
|
+
function abort() {
|
|
1392
|
+
this.destroy(/* @__PURE__ */ new Error("Stream aborted."));
|
|
1393
|
+
}
|
|
1394
|
+
function isWritev(s) {
|
|
1395
|
+
return s._writev !== Writable.prototype._writev && s._writev !== Duplex.prototype._writev;
|
|
1396
|
+
}
|
|
1397
|
+
module.exports = {
|
|
1398
|
+
pipeline,
|
|
1399
|
+
pipelinePromise,
|
|
1400
|
+
isStream,
|
|
1401
|
+
isStreamx,
|
|
1402
|
+
isEnding,
|
|
1403
|
+
isEnded,
|
|
1404
|
+
isFinishing,
|
|
1405
|
+
isFinished,
|
|
1406
|
+
isDisturbed,
|
|
1407
|
+
getStreamError,
|
|
1408
|
+
Stream,
|
|
1409
|
+
Writable,
|
|
1410
|
+
Readable,
|
|
1411
|
+
Duplex,
|
|
1412
|
+
Transform,
|
|
1413
|
+
PassThrough
|
|
1414
|
+
};
|
|
1415
|
+
}));
|
|
1416
|
+
//#endregion
|
|
1417
|
+
//#region ../../node_modules/.pnpm/tar-stream@3.1.8/node_modules/tar-stream/headers.js
|
|
1418
|
+
var require_headers = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1419
|
+
const b4a = require_b4a();
|
|
1420
|
+
const ZEROS = "0000000000000000000";
|
|
1421
|
+
const SEVENS = "7777777777777777777";
|
|
1422
|
+
const ZERO_OFFSET = "0".charCodeAt(0);
|
|
1423
|
+
const USTAR_MAGIC = b4a.from([
|
|
1424
|
+
117,
|
|
1425
|
+
115,
|
|
1426
|
+
116,
|
|
1427
|
+
97,
|
|
1428
|
+
114,
|
|
1429
|
+
0
|
|
1430
|
+
]);
|
|
1431
|
+
const USTAR_VER = b4a.from([ZERO_OFFSET, ZERO_OFFSET]);
|
|
1432
|
+
const GNU_MAGIC = b4a.from([
|
|
1433
|
+
117,
|
|
1434
|
+
115,
|
|
1435
|
+
116,
|
|
1436
|
+
97,
|
|
1437
|
+
114,
|
|
1438
|
+
32
|
|
1439
|
+
]);
|
|
1440
|
+
const GNU_VER = b4a.from([32, 0]);
|
|
1441
|
+
const MASK = 4095;
|
|
1442
|
+
const MAGIC_OFFSET = 257;
|
|
1443
|
+
const VERSION_OFFSET = 263;
|
|
1444
|
+
exports.decodeLongPath = function decodeLongPath(buf, encoding) {
|
|
1445
|
+
return decodeStr(buf, 0, buf.length, encoding);
|
|
1446
|
+
};
|
|
1447
|
+
exports.encodePax = function encodePax(opts) {
|
|
1448
|
+
let result = "";
|
|
1449
|
+
if (opts.name) result += addLength(" path=" + opts.name + "\n");
|
|
1450
|
+
if (opts.linkname) result += addLength(" linkpath=" + opts.linkname + "\n");
|
|
1451
|
+
const pax = opts.pax;
|
|
1452
|
+
if (pax) for (const key in pax) result += addLength(" " + key + "=" + pax[key] + "\n");
|
|
1453
|
+
return b4a.from(result);
|
|
1454
|
+
};
|
|
1455
|
+
exports.decodePax = function decodePax(buf) {
|
|
1456
|
+
const result = {};
|
|
1457
|
+
while (buf.length) {
|
|
1458
|
+
let i = 0;
|
|
1459
|
+
while (i < buf.length && buf[i] !== 32) i++;
|
|
1460
|
+
const len = parseInt(b4a.toString(buf.subarray(0, i)), 10);
|
|
1461
|
+
if (!len) return result;
|
|
1462
|
+
const b = b4a.toString(buf.subarray(i + 1, len - 1));
|
|
1463
|
+
const keyIndex = b.indexOf("=");
|
|
1464
|
+
if (keyIndex === -1) return result;
|
|
1465
|
+
result[b.slice(0, keyIndex)] = b.slice(keyIndex + 1);
|
|
1466
|
+
buf = buf.subarray(len);
|
|
1467
|
+
}
|
|
1468
|
+
return result;
|
|
1469
|
+
};
|
|
1470
|
+
exports.encode = function encode(opts) {
|
|
1471
|
+
const buf = b4a.alloc(512);
|
|
1472
|
+
let name = opts.name;
|
|
1473
|
+
let prefix = "";
|
|
1474
|
+
if (opts.typeflag === 5 && name[name.length - 1] !== "/") name += "/";
|
|
1475
|
+
if (b4a.byteLength(name) !== name.length) return null;
|
|
1476
|
+
while (b4a.byteLength(name) > 100) {
|
|
1477
|
+
const i = name.indexOf("/");
|
|
1478
|
+
if (i === -1) return null;
|
|
1479
|
+
prefix += prefix ? "/" + name.slice(0, i) : name.slice(0, i);
|
|
1480
|
+
name = name.slice(i + 1);
|
|
1481
|
+
}
|
|
1482
|
+
if (b4a.byteLength(name) > 100 || b4a.byteLength(prefix) > 155) return null;
|
|
1483
|
+
if (opts.linkname && b4a.byteLength(opts.linkname) > 100) return null;
|
|
1484
|
+
b4a.write(buf, name);
|
|
1485
|
+
b4a.write(buf, encodeOct(opts.mode & MASK, 6), 100);
|
|
1486
|
+
b4a.write(buf, encodeOct(opts.uid, 6), 108);
|
|
1487
|
+
b4a.write(buf, encodeOct(opts.gid, 6), 116);
|
|
1488
|
+
encodeSize(opts.size, buf, 124);
|
|
1489
|
+
b4a.write(buf, encodeOct(opts.mtime.getTime() / 1e3 | 0, 11), 136);
|
|
1490
|
+
buf[156] = ZERO_OFFSET + toTypeflag(opts.type);
|
|
1491
|
+
if (opts.linkname) b4a.write(buf, opts.linkname, 157);
|
|
1492
|
+
b4a.copy(USTAR_MAGIC, buf, MAGIC_OFFSET);
|
|
1493
|
+
b4a.copy(USTAR_VER, buf, VERSION_OFFSET);
|
|
1494
|
+
if (opts.uname) b4a.write(buf, opts.uname, 265);
|
|
1495
|
+
if (opts.gname) b4a.write(buf, opts.gname, 297);
|
|
1496
|
+
b4a.write(buf, encodeOct(opts.devmajor || 0, 6), 329);
|
|
1497
|
+
b4a.write(buf, encodeOct(opts.devminor || 0, 6), 337);
|
|
1498
|
+
if (prefix) b4a.write(buf, prefix, 345);
|
|
1499
|
+
b4a.write(buf, encodeOct(cksum(buf), 6), 148);
|
|
1500
|
+
return buf;
|
|
1501
|
+
};
|
|
1502
|
+
exports.decode = function decode(buf, filenameEncoding, allowUnknownFormat) {
|
|
1503
|
+
let typeflag = buf[156] === 0 ? 0 : buf[156] - ZERO_OFFSET;
|
|
1504
|
+
let name = decodeStr(buf, 0, 100, filenameEncoding);
|
|
1505
|
+
const mode = decodeOct(buf, 100, 8);
|
|
1506
|
+
const uid = decodeOct(buf, 108, 8);
|
|
1507
|
+
const gid = decodeOct(buf, 116, 8);
|
|
1508
|
+
const size = decodeOct(buf, 124, 12);
|
|
1509
|
+
const mtime = decodeOct(buf, 136, 12);
|
|
1510
|
+
const type = toType(typeflag);
|
|
1511
|
+
const linkname = buf[157] === 0 ? null : decodeStr(buf, 157, 100, filenameEncoding);
|
|
1512
|
+
const uname = decodeStr(buf, 265, 32);
|
|
1513
|
+
const gname = decodeStr(buf, 297, 32);
|
|
1514
|
+
const devmajor = decodeOct(buf, 329, 8);
|
|
1515
|
+
const devminor = decodeOct(buf, 337, 8);
|
|
1516
|
+
const c = cksum(buf);
|
|
1517
|
+
if (c === 256) return null;
|
|
1518
|
+
if (c !== decodeOct(buf, 148, 8)) throw new Error("Invalid tar header. Maybe the tar is corrupted or it needs to be gunzipped?");
|
|
1519
|
+
if (isUSTAR(buf)) {
|
|
1520
|
+
if (buf[345]) name = decodeStr(buf, 345, 155, filenameEncoding) + "/" + name;
|
|
1521
|
+
} else if (isGNU(buf)) {} else if (!allowUnknownFormat) throw new Error("Invalid tar header: unknown format.");
|
|
1522
|
+
if (typeflag === 0 && name && name[name.length - 1] === "/") typeflag = 5;
|
|
1523
|
+
return {
|
|
1524
|
+
name,
|
|
1525
|
+
mode,
|
|
1526
|
+
uid,
|
|
1527
|
+
gid,
|
|
1528
|
+
size,
|
|
1529
|
+
mtime: /* @__PURE__ */ new Date(1e3 * mtime),
|
|
1530
|
+
type,
|
|
1531
|
+
linkname,
|
|
1532
|
+
uname,
|
|
1533
|
+
gname,
|
|
1534
|
+
devmajor,
|
|
1535
|
+
devminor,
|
|
1536
|
+
pax: null
|
|
1537
|
+
};
|
|
1538
|
+
};
|
|
1539
|
+
function isUSTAR(buf) {
|
|
1540
|
+
return b4a.equals(USTAR_MAGIC, buf.subarray(MAGIC_OFFSET, MAGIC_OFFSET + 6));
|
|
1541
|
+
}
|
|
1542
|
+
function isGNU(buf) {
|
|
1543
|
+
return b4a.equals(GNU_MAGIC, buf.subarray(MAGIC_OFFSET, MAGIC_OFFSET + 6)) && b4a.equals(GNU_VER, buf.subarray(VERSION_OFFSET, VERSION_OFFSET + 2));
|
|
1544
|
+
}
|
|
1545
|
+
function clamp(index, len, defaultValue) {
|
|
1546
|
+
if (typeof index !== "number") return defaultValue;
|
|
1547
|
+
index = ~~index;
|
|
1548
|
+
if (index >= len) return len;
|
|
1549
|
+
if (index >= 0) return index;
|
|
1550
|
+
index += len;
|
|
1551
|
+
if (index >= 0) return index;
|
|
1552
|
+
return 0;
|
|
1553
|
+
}
|
|
1554
|
+
function toType(flag) {
|
|
1555
|
+
switch (flag) {
|
|
1556
|
+
case 0: return "file";
|
|
1557
|
+
case 1: return "link";
|
|
1558
|
+
case 2: return "symlink";
|
|
1559
|
+
case 3: return "character-device";
|
|
1560
|
+
case 4: return "block-device";
|
|
1561
|
+
case 5: return "directory";
|
|
1562
|
+
case 6: return "fifo";
|
|
1563
|
+
case 7: return "contiguous-file";
|
|
1564
|
+
case 72: return "pax-header";
|
|
1565
|
+
case 55: return "pax-global-header";
|
|
1566
|
+
case 27: return "gnu-long-link-path";
|
|
1567
|
+
case 28:
|
|
1568
|
+
case 30: return "gnu-long-path";
|
|
1569
|
+
}
|
|
1570
|
+
return null;
|
|
1571
|
+
}
|
|
1572
|
+
function toTypeflag(flag) {
|
|
1573
|
+
switch (flag) {
|
|
1574
|
+
case "file": return 0;
|
|
1575
|
+
case "link": return 1;
|
|
1576
|
+
case "symlink": return 2;
|
|
1577
|
+
case "character-device": return 3;
|
|
1578
|
+
case "block-device": return 4;
|
|
1579
|
+
case "directory": return 5;
|
|
1580
|
+
case "fifo": return 6;
|
|
1581
|
+
case "contiguous-file": return 7;
|
|
1582
|
+
case "pax-header": return 72;
|
|
1583
|
+
}
|
|
1584
|
+
return 0;
|
|
1585
|
+
}
|
|
1586
|
+
function indexOf(block, num, offset, end) {
|
|
1587
|
+
for (; offset < end; offset++) if (block[offset] === num) return offset;
|
|
1588
|
+
return end;
|
|
1589
|
+
}
|
|
1590
|
+
function cksum(block) {
|
|
1591
|
+
let sum = 256;
|
|
1592
|
+
for (let i = 0; i < 148; i++) sum += block[i];
|
|
1593
|
+
for (let j = 156; j < 512; j++) sum += block[j];
|
|
1594
|
+
return sum;
|
|
1595
|
+
}
|
|
1596
|
+
function encodeOct(val, n) {
|
|
1597
|
+
val = val.toString(8);
|
|
1598
|
+
if (val.length > n) return SEVENS.slice(0, n) + " ";
|
|
1599
|
+
return ZEROS.slice(0, n - val.length) + val + " ";
|
|
1600
|
+
}
|
|
1601
|
+
function encodeSizeBin(num, buf, off) {
|
|
1602
|
+
buf[off] = 128;
|
|
1603
|
+
for (let i = 11; i > 0; i--) {
|
|
1604
|
+
buf[off + i] = num & 255;
|
|
1605
|
+
num = Math.floor(num / 256);
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
function encodeSize(num, buf, off) {
|
|
1609
|
+
if (num.toString(8).length > 11) encodeSizeBin(num, buf, off);
|
|
1610
|
+
else b4a.write(buf, encodeOct(num, 11), off);
|
|
1611
|
+
}
|
|
1612
|
+
function parse256(buf) {
|
|
1613
|
+
let positive;
|
|
1614
|
+
if (buf[0] === 128) positive = true;
|
|
1615
|
+
else if (buf[0] === 255) positive = false;
|
|
1616
|
+
else return null;
|
|
1617
|
+
const tuple = [];
|
|
1618
|
+
let i;
|
|
1619
|
+
for (i = buf.length - 1; i > 0; i--) {
|
|
1620
|
+
const byte = buf[i];
|
|
1621
|
+
if (positive) tuple.push(byte);
|
|
1622
|
+
else tuple.push(255 - byte);
|
|
1623
|
+
}
|
|
1624
|
+
let sum = 0;
|
|
1625
|
+
const l = tuple.length;
|
|
1626
|
+
for (i = 0; i < l; i++) sum += tuple[i] * Math.pow(256, i);
|
|
1627
|
+
return positive ? sum : -1 * sum;
|
|
1628
|
+
}
|
|
1629
|
+
function decodeOct(val, offset, length) {
|
|
1630
|
+
val = val.subarray(offset, offset + length);
|
|
1631
|
+
offset = 0;
|
|
1632
|
+
if (val[offset] & 128) return parse256(val);
|
|
1633
|
+
else {
|
|
1634
|
+
while (offset < val.length && val[offset] === 32) offset++;
|
|
1635
|
+
const end = clamp(indexOf(val, 32, offset, val.length), val.length, val.length);
|
|
1636
|
+
while (offset < end && val[offset] === 0) offset++;
|
|
1637
|
+
if (end === offset) return 0;
|
|
1638
|
+
return parseInt(b4a.toString(val.subarray(offset, end)), 8);
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
function decodeStr(val, offset, length, encoding) {
|
|
1642
|
+
return b4a.toString(val.subarray(offset, indexOf(val, 0, offset, offset + length)), encoding);
|
|
1643
|
+
}
|
|
1644
|
+
function addLength(str) {
|
|
1645
|
+
const len = b4a.byteLength(str);
|
|
1646
|
+
let digits = Math.floor(Math.log(len) / Math.log(10)) + 1;
|
|
1647
|
+
if (len + digits >= Math.pow(10, digits)) digits++;
|
|
1648
|
+
return len + digits + str;
|
|
1649
|
+
}
|
|
1650
|
+
}));
|
|
1651
|
+
//#endregion
|
|
1652
|
+
//#region ../../node_modules/.pnpm/tar-stream@3.1.8/node_modules/tar-stream/extract.js
|
|
1653
|
+
var require_extract = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1654
|
+
const { Writable, Readable, getStreamError } = require_streamx();
|
|
1655
|
+
const FIFO = require_fast_fifo();
|
|
1656
|
+
const b4a = require_b4a();
|
|
1657
|
+
const headers = require_headers();
|
|
1658
|
+
const EMPTY = b4a.alloc(0);
|
|
1659
|
+
var BufferList = class {
|
|
1660
|
+
constructor() {
|
|
1661
|
+
this.buffered = 0;
|
|
1662
|
+
this.shifted = 0;
|
|
1663
|
+
this.queue = new FIFO();
|
|
1664
|
+
this._offset = 0;
|
|
1665
|
+
}
|
|
1666
|
+
push(buffer) {
|
|
1667
|
+
this.buffered += buffer.byteLength;
|
|
1668
|
+
this.queue.push(buffer);
|
|
1669
|
+
}
|
|
1670
|
+
shiftFirst(size) {
|
|
1671
|
+
return this._buffered === 0 ? null : this._next(size);
|
|
1672
|
+
}
|
|
1673
|
+
shift(size) {
|
|
1674
|
+
if (size > this.buffered) return null;
|
|
1675
|
+
if (size === 0) return EMPTY;
|
|
1676
|
+
let chunk = this._next(size);
|
|
1677
|
+
if (size === chunk.byteLength) return chunk;
|
|
1678
|
+
const chunks = [chunk];
|
|
1679
|
+
while ((size -= chunk.byteLength) > 0) {
|
|
1680
|
+
chunk = this._next(size);
|
|
1681
|
+
chunks.push(chunk);
|
|
1682
|
+
}
|
|
1683
|
+
return b4a.concat(chunks);
|
|
1684
|
+
}
|
|
1685
|
+
_next(size) {
|
|
1686
|
+
const buf = this.queue.peek();
|
|
1687
|
+
const rem = buf.byteLength - this._offset;
|
|
1688
|
+
if (size >= rem) {
|
|
1689
|
+
const sub = this._offset ? buf.subarray(this._offset, buf.byteLength) : buf;
|
|
1690
|
+
this.queue.shift();
|
|
1691
|
+
this._offset = 0;
|
|
1692
|
+
this.buffered -= rem;
|
|
1693
|
+
this.shifted += rem;
|
|
1694
|
+
return sub;
|
|
1695
|
+
}
|
|
1696
|
+
this.buffered -= size;
|
|
1697
|
+
this.shifted += size;
|
|
1698
|
+
return buf.subarray(this._offset, this._offset += size);
|
|
1699
|
+
}
|
|
1700
|
+
};
|
|
1701
|
+
var Source = class extends Readable {
|
|
1702
|
+
constructor(self, header, offset) {
|
|
1703
|
+
super();
|
|
1704
|
+
this.header = header;
|
|
1705
|
+
this.offset = offset;
|
|
1706
|
+
this._parent = self;
|
|
1707
|
+
}
|
|
1708
|
+
_read(cb) {
|
|
1709
|
+
if (this.header.size === 0) this.push(null);
|
|
1710
|
+
if (this._parent._stream === this) this._parent._update();
|
|
1711
|
+
cb(null);
|
|
1712
|
+
}
|
|
1713
|
+
_predestroy() {
|
|
1714
|
+
this._parent.destroy(getStreamError(this));
|
|
1715
|
+
}
|
|
1716
|
+
_detach() {
|
|
1717
|
+
if (this._parent._stream === this) {
|
|
1718
|
+
this._parent._stream = null;
|
|
1719
|
+
this._parent._missing = overflow(this.header.size);
|
|
1720
|
+
this._parent._update();
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
_destroy(cb) {
|
|
1724
|
+
this._detach();
|
|
1725
|
+
cb(null);
|
|
1726
|
+
}
|
|
1727
|
+
};
|
|
1728
|
+
var Extract = class extends Writable {
|
|
1729
|
+
constructor(opts) {
|
|
1730
|
+
super(opts);
|
|
1731
|
+
if (!opts) opts = {};
|
|
1732
|
+
this._buffer = new BufferList();
|
|
1733
|
+
this._offset = 0;
|
|
1734
|
+
this._header = null;
|
|
1735
|
+
this._stream = null;
|
|
1736
|
+
this._missing = 0;
|
|
1737
|
+
this._longHeader = false;
|
|
1738
|
+
this._callback = noop;
|
|
1739
|
+
this._locked = false;
|
|
1740
|
+
this._finished = false;
|
|
1741
|
+
this._pax = null;
|
|
1742
|
+
this._paxGlobal = null;
|
|
1743
|
+
this._gnuLongPath = null;
|
|
1744
|
+
this._gnuLongLinkPath = null;
|
|
1745
|
+
this._filenameEncoding = opts.filenameEncoding || "utf-8";
|
|
1746
|
+
this._allowUnknownFormat = !!opts.allowUnknownFormat;
|
|
1747
|
+
this._unlockBound = this._unlock.bind(this);
|
|
1748
|
+
}
|
|
1749
|
+
_unlock(err) {
|
|
1750
|
+
this._locked = false;
|
|
1751
|
+
if (err) {
|
|
1752
|
+
this.destroy(err);
|
|
1753
|
+
this._continueWrite(err);
|
|
1754
|
+
return;
|
|
1755
|
+
}
|
|
1756
|
+
this._update();
|
|
1757
|
+
}
|
|
1758
|
+
_consumeHeader() {
|
|
1759
|
+
if (this._locked) return false;
|
|
1760
|
+
this._offset = this._buffer.shifted;
|
|
1761
|
+
try {
|
|
1762
|
+
this._header = headers.decode(this._buffer.shift(512), this._filenameEncoding, this._allowUnknownFormat);
|
|
1763
|
+
} catch (err) {
|
|
1764
|
+
this._continueWrite(err);
|
|
1765
|
+
return false;
|
|
1766
|
+
}
|
|
1767
|
+
if (!this._header) return true;
|
|
1768
|
+
switch (this._header.type) {
|
|
1769
|
+
case "gnu-long-path":
|
|
1770
|
+
case "gnu-long-link-path":
|
|
1771
|
+
case "pax-global-header":
|
|
1772
|
+
case "pax-header":
|
|
1773
|
+
this._longHeader = true;
|
|
1774
|
+
this._missing = this._header.size;
|
|
1775
|
+
return true;
|
|
1776
|
+
}
|
|
1777
|
+
this._locked = true;
|
|
1778
|
+
this._applyLongHeaders();
|
|
1779
|
+
if (this._header.size === 0 || this._header.type === "directory") {
|
|
1780
|
+
this.emit("entry", this._header, this._createStream(), this._unlockBound);
|
|
1781
|
+
return true;
|
|
1782
|
+
}
|
|
1783
|
+
this._stream = this._createStream();
|
|
1784
|
+
this._missing = this._header.size;
|
|
1785
|
+
this.emit("entry", this._header, this._stream, this._unlockBound);
|
|
1786
|
+
return true;
|
|
1787
|
+
}
|
|
1788
|
+
_applyLongHeaders() {
|
|
1789
|
+
if (this._gnuLongPath) {
|
|
1790
|
+
this._header.name = this._gnuLongPath;
|
|
1791
|
+
this._gnuLongPath = null;
|
|
1792
|
+
}
|
|
1793
|
+
if (this._gnuLongLinkPath) {
|
|
1794
|
+
this._header.linkname = this._gnuLongLinkPath;
|
|
1795
|
+
this._gnuLongLinkPath = null;
|
|
1796
|
+
}
|
|
1797
|
+
if (this._pax) {
|
|
1798
|
+
if (this._pax.path) this._header.name = this._pax.path;
|
|
1799
|
+
if (this._pax.linkpath) this._header.linkname = this._pax.linkpath;
|
|
1800
|
+
if (this._pax.size) this._header.size = parseInt(this._pax.size, 10);
|
|
1801
|
+
this._header.pax = this._pax;
|
|
1802
|
+
this._pax = null;
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
_decodeLongHeader(buf) {
|
|
1806
|
+
switch (this._header.type) {
|
|
1807
|
+
case "gnu-long-path":
|
|
1808
|
+
this._gnuLongPath = headers.decodeLongPath(buf, this._filenameEncoding);
|
|
1809
|
+
break;
|
|
1810
|
+
case "gnu-long-link-path":
|
|
1811
|
+
this._gnuLongLinkPath = headers.decodeLongPath(buf, this._filenameEncoding);
|
|
1812
|
+
break;
|
|
1813
|
+
case "pax-global-header":
|
|
1814
|
+
this._paxGlobal = headers.decodePax(buf);
|
|
1815
|
+
break;
|
|
1816
|
+
case "pax-header":
|
|
1817
|
+
this._pax = this._paxGlobal === null ? headers.decodePax(buf) : Object.assign({}, this._paxGlobal, headers.decodePax(buf));
|
|
1818
|
+
break;
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
_consumeLongHeader() {
|
|
1822
|
+
this._longHeader = false;
|
|
1823
|
+
this._missing = overflow(this._header.size);
|
|
1824
|
+
const buf = this._buffer.shift(this._header.size);
|
|
1825
|
+
try {
|
|
1826
|
+
this._decodeLongHeader(buf);
|
|
1827
|
+
} catch (err) {
|
|
1828
|
+
this._continueWrite(err);
|
|
1829
|
+
return false;
|
|
1830
|
+
}
|
|
1831
|
+
return true;
|
|
1832
|
+
}
|
|
1833
|
+
_consumeStream() {
|
|
1834
|
+
const buf = this._buffer.shiftFirst(this._missing);
|
|
1835
|
+
if (buf === null) return false;
|
|
1836
|
+
this._missing -= buf.byteLength;
|
|
1837
|
+
const drained = this._stream.push(buf);
|
|
1838
|
+
if (this._missing === 0) {
|
|
1839
|
+
this._stream.push(null);
|
|
1840
|
+
if (drained) this._stream._detach();
|
|
1841
|
+
return drained && this._locked === false;
|
|
1842
|
+
}
|
|
1843
|
+
return drained;
|
|
1844
|
+
}
|
|
1845
|
+
_createStream() {
|
|
1846
|
+
return new Source(this, this._header, this._offset);
|
|
1847
|
+
}
|
|
1848
|
+
_update() {
|
|
1849
|
+
while (this._buffer.buffered > 0 && !this.destroying) {
|
|
1850
|
+
if (this._missing > 0) {
|
|
1851
|
+
if (this._stream !== null) {
|
|
1852
|
+
if (this._consumeStream() === false) return;
|
|
1853
|
+
continue;
|
|
1854
|
+
}
|
|
1855
|
+
if (this._longHeader === true) {
|
|
1856
|
+
if (this._missing > this._buffer.buffered) break;
|
|
1857
|
+
if (this._consumeLongHeader() === false) return false;
|
|
1858
|
+
continue;
|
|
1859
|
+
}
|
|
1860
|
+
const ignore = this._buffer.shiftFirst(this._missing);
|
|
1861
|
+
if (ignore !== null) this._missing -= ignore.byteLength;
|
|
1862
|
+
continue;
|
|
1863
|
+
}
|
|
1864
|
+
if (this._buffer.buffered < 512) break;
|
|
1865
|
+
if (this._stream !== null || this._consumeHeader() === false) return;
|
|
1866
|
+
}
|
|
1867
|
+
this._continueWrite(null);
|
|
1868
|
+
}
|
|
1869
|
+
_continueWrite(err) {
|
|
1870
|
+
const cb = this._callback;
|
|
1871
|
+
this._callback = noop;
|
|
1872
|
+
cb(err);
|
|
1873
|
+
}
|
|
1874
|
+
_write(data, cb) {
|
|
1875
|
+
this._callback = cb;
|
|
1876
|
+
this._buffer.push(data);
|
|
1877
|
+
this._update();
|
|
1878
|
+
}
|
|
1879
|
+
_final(cb) {
|
|
1880
|
+
this._finished = this._missing === 0 && this._buffer.buffered === 0;
|
|
1881
|
+
cb(this._finished ? null : /* @__PURE__ */ new Error("Unexpected end of data"));
|
|
1882
|
+
}
|
|
1883
|
+
_predestroy() {
|
|
1884
|
+
this._continueWrite(null);
|
|
1885
|
+
}
|
|
1886
|
+
_destroy(cb) {
|
|
1887
|
+
if (this._stream) this._stream.destroy(getStreamError(this));
|
|
1888
|
+
cb(null);
|
|
1889
|
+
}
|
|
1890
|
+
[Symbol.asyncIterator]() {
|
|
1891
|
+
let error = null;
|
|
1892
|
+
let promiseResolve = null;
|
|
1893
|
+
let promiseReject = null;
|
|
1894
|
+
let entryStream = null;
|
|
1895
|
+
let entryCallback = null;
|
|
1896
|
+
const extract = this;
|
|
1897
|
+
this.on("entry", onentry);
|
|
1898
|
+
this.on("error", (err) => {
|
|
1899
|
+
error = err;
|
|
1900
|
+
});
|
|
1901
|
+
this.on("close", onclose);
|
|
1902
|
+
return {
|
|
1903
|
+
[Symbol.asyncIterator]() {
|
|
1904
|
+
return this;
|
|
1905
|
+
},
|
|
1906
|
+
next() {
|
|
1907
|
+
return new Promise(onnext);
|
|
1908
|
+
},
|
|
1909
|
+
return() {
|
|
1910
|
+
return destroy(null);
|
|
1911
|
+
},
|
|
1912
|
+
throw(err) {
|
|
1913
|
+
return destroy(err);
|
|
1914
|
+
}
|
|
1915
|
+
};
|
|
1916
|
+
function consumeCallback(err) {
|
|
1917
|
+
if (!entryCallback) return;
|
|
1918
|
+
const cb = entryCallback;
|
|
1919
|
+
entryCallback = null;
|
|
1920
|
+
cb(err);
|
|
1921
|
+
}
|
|
1922
|
+
function onnext(resolve, reject) {
|
|
1923
|
+
if (error) return reject(error);
|
|
1924
|
+
if (entryStream) {
|
|
1925
|
+
resolve({
|
|
1926
|
+
value: entryStream,
|
|
1927
|
+
done: false
|
|
1928
|
+
});
|
|
1929
|
+
entryStream = null;
|
|
1930
|
+
return;
|
|
1931
|
+
}
|
|
1932
|
+
promiseResolve = resolve;
|
|
1933
|
+
promiseReject = reject;
|
|
1934
|
+
consumeCallback(null);
|
|
1935
|
+
if (extract._finished && promiseResolve) {
|
|
1936
|
+
promiseResolve({
|
|
1937
|
+
value: void 0,
|
|
1938
|
+
done: true
|
|
1939
|
+
});
|
|
1940
|
+
promiseResolve = promiseReject = null;
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
function onentry(header, stream, callback) {
|
|
1944
|
+
entryCallback = callback;
|
|
1945
|
+
stream.on("error", noop);
|
|
1946
|
+
if (promiseResolve) {
|
|
1947
|
+
promiseResolve({
|
|
1948
|
+
value: stream,
|
|
1949
|
+
done: false
|
|
1950
|
+
});
|
|
1951
|
+
promiseResolve = promiseReject = null;
|
|
1952
|
+
} else entryStream = stream;
|
|
1953
|
+
}
|
|
1954
|
+
function onclose() {
|
|
1955
|
+
consumeCallback(error);
|
|
1956
|
+
if (!promiseResolve) return;
|
|
1957
|
+
if (error) promiseReject(error);
|
|
1958
|
+
else promiseResolve({
|
|
1959
|
+
value: void 0,
|
|
1960
|
+
done: true
|
|
1961
|
+
});
|
|
1962
|
+
promiseResolve = promiseReject = null;
|
|
1963
|
+
}
|
|
1964
|
+
function destroy(err) {
|
|
1965
|
+
extract.destroy(err);
|
|
1966
|
+
consumeCallback(err);
|
|
1967
|
+
return new Promise((resolve, reject) => {
|
|
1968
|
+
if (extract.destroyed) return resolve({
|
|
1969
|
+
value: void 0,
|
|
1970
|
+
done: true
|
|
1971
|
+
});
|
|
1972
|
+
extract.once("close", function() {
|
|
1973
|
+
if (err) reject(err);
|
|
1974
|
+
else resolve({
|
|
1975
|
+
value: void 0,
|
|
1976
|
+
done: true
|
|
1977
|
+
});
|
|
1978
|
+
});
|
|
1979
|
+
});
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
};
|
|
1983
|
+
module.exports = function extract(opts) {
|
|
1984
|
+
return new Extract(opts);
|
|
1985
|
+
};
|
|
1986
|
+
function noop() {}
|
|
1987
|
+
function overflow(size) {
|
|
1988
|
+
size &= 511;
|
|
1989
|
+
return size && 512 - size;
|
|
1990
|
+
}
|
|
1991
|
+
}));
|
|
1992
|
+
//#endregion
|
|
1993
|
+
//#region ../../node_modules/.pnpm/tar-stream@3.1.8/node_modules/tar-stream/constants.js
|
|
1994
|
+
var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1995
|
+
const constants = {
|
|
1996
|
+
S_IFMT: 61440,
|
|
1997
|
+
S_IFDIR: 16384,
|
|
1998
|
+
S_IFCHR: 8192,
|
|
1999
|
+
S_IFBLK: 24576,
|
|
2000
|
+
S_IFIFO: 4096,
|
|
2001
|
+
S_IFLNK: 40960
|
|
2002
|
+
};
|
|
2003
|
+
try {
|
|
2004
|
+
module.exports = __require("fs").constants || constants;
|
|
2005
|
+
} catch {
|
|
2006
|
+
module.exports = constants;
|
|
2007
|
+
}
|
|
2008
|
+
}));
|
|
2009
|
+
//#endregion
|
|
2010
|
+
//#region ../../node_modules/.pnpm/tar-stream@3.1.8/node_modules/tar-stream/pack.js
|
|
2011
|
+
var require_pack = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2012
|
+
const { Readable, Writable, getStreamError } = require_streamx();
|
|
2013
|
+
const b4a = require_b4a();
|
|
2014
|
+
const constants = require_constants();
|
|
2015
|
+
const headers = require_headers();
|
|
2016
|
+
const DMODE = 493;
|
|
2017
|
+
const FMODE = 420;
|
|
2018
|
+
const END_OF_TAR = b4a.alloc(1024);
|
|
2019
|
+
var Sink = class extends Writable {
|
|
2020
|
+
constructor(pack, header, callback) {
|
|
2021
|
+
super({
|
|
2022
|
+
mapWritable,
|
|
2023
|
+
eagerOpen: true
|
|
2024
|
+
});
|
|
2025
|
+
this.written = 0;
|
|
2026
|
+
this.header = header;
|
|
2027
|
+
this._callback = callback;
|
|
2028
|
+
this._linkname = null;
|
|
2029
|
+
this._isLinkname = header.type === "symlink" && !header.linkname;
|
|
2030
|
+
this._isVoid = header.type !== "file" && header.type !== "contiguous-file";
|
|
2031
|
+
this._finished = false;
|
|
2032
|
+
this._pack = pack;
|
|
2033
|
+
this._openCallback = null;
|
|
2034
|
+
if (this._pack._stream === null) this._pack._stream = this;
|
|
2035
|
+
else this._pack._pending.push(this);
|
|
2036
|
+
}
|
|
2037
|
+
_open(cb) {
|
|
2038
|
+
this._openCallback = cb;
|
|
2039
|
+
if (this._pack._stream === this) this._continueOpen();
|
|
2040
|
+
}
|
|
2041
|
+
_continuePack(err) {
|
|
2042
|
+
if (this._callback === null) return;
|
|
2043
|
+
const callback = this._callback;
|
|
2044
|
+
this._callback = null;
|
|
2045
|
+
callback(err);
|
|
2046
|
+
}
|
|
2047
|
+
_continueOpen() {
|
|
2048
|
+
if (this._pack._stream === null) this._pack._stream = this;
|
|
2049
|
+
const cb = this._openCallback;
|
|
2050
|
+
this._openCallback = null;
|
|
2051
|
+
if (cb === null) return;
|
|
2052
|
+
if (this._pack.destroying) return cb(/* @__PURE__ */ new Error("pack stream destroyed"));
|
|
2053
|
+
if (this._pack._finalized) return cb(/* @__PURE__ */ new Error("pack stream is already finalized"));
|
|
2054
|
+
this._pack._stream = this;
|
|
2055
|
+
if (!this._isLinkname) this._pack._encode(this.header);
|
|
2056
|
+
if (this._isVoid) {
|
|
2057
|
+
this._finish();
|
|
2058
|
+
this._continuePack(null);
|
|
2059
|
+
}
|
|
2060
|
+
cb(null);
|
|
2061
|
+
}
|
|
2062
|
+
_write(data, cb) {
|
|
2063
|
+
if (this._isLinkname) {
|
|
2064
|
+
this._linkname = this._linkname ? b4a.concat([this._linkname, data]) : data;
|
|
2065
|
+
return cb(null);
|
|
2066
|
+
}
|
|
2067
|
+
if (this._isVoid) {
|
|
2068
|
+
if (data.byteLength > 0) return cb(/* @__PURE__ */ new Error("No body allowed for this entry"));
|
|
2069
|
+
return cb();
|
|
2070
|
+
}
|
|
2071
|
+
this.written += data.byteLength;
|
|
2072
|
+
if (this._pack.push(data)) return cb();
|
|
2073
|
+
this._pack._drain = cb;
|
|
2074
|
+
}
|
|
2075
|
+
_finish() {
|
|
2076
|
+
if (this._finished) return;
|
|
2077
|
+
this._finished = true;
|
|
2078
|
+
if (this._isLinkname) {
|
|
2079
|
+
this.header.linkname = this._linkname ? b4a.toString(this._linkname, "utf-8") : "";
|
|
2080
|
+
this._pack._encode(this.header);
|
|
2081
|
+
}
|
|
2082
|
+
overflow(this._pack, this.header.size);
|
|
2083
|
+
this._pack._done(this);
|
|
2084
|
+
}
|
|
2085
|
+
_final(cb) {
|
|
2086
|
+
if (this.written !== this.header.size) return cb(/* @__PURE__ */ new Error("Size mismatch"));
|
|
2087
|
+
this._finish();
|
|
2088
|
+
cb(null);
|
|
2089
|
+
}
|
|
2090
|
+
_getError() {
|
|
2091
|
+
return getStreamError(this) || /* @__PURE__ */ new Error("tar entry destroyed");
|
|
2092
|
+
}
|
|
2093
|
+
_predestroy() {
|
|
2094
|
+
this._pack.destroy(this._getError());
|
|
2095
|
+
}
|
|
2096
|
+
_destroy(cb) {
|
|
2097
|
+
this._pack._done(this);
|
|
2098
|
+
this._continuePack(this._finished ? null : this._getError());
|
|
2099
|
+
cb();
|
|
2100
|
+
}
|
|
2101
|
+
};
|
|
2102
|
+
var Pack = class extends Readable {
|
|
2103
|
+
constructor(opts) {
|
|
2104
|
+
super(opts);
|
|
2105
|
+
this._drain = noop;
|
|
2106
|
+
this._finalized = false;
|
|
2107
|
+
this._finalizing = false;
|
|
2108
|
+
this._pending = [];
|
|
2109
|
+
this._stream = null;
|
|
2110
|
+
}
|
|
2111
|
+
entry(header, buffer, callback) {
|
|
2112
|
+
if (this._finalized || this.destroying) throw new Error("already finalized or destroyed");
|
|
2113
|
+
if (typeof buffer === "function") {
|
|
2114
|
+
callback = buffer;
|
|
2115
|
+
buffer = null;
|
|
2116
|
+
}
|
|
2117
|
+
if (!callback) callback = noop;
|
|
2118
|
+
if (!header.size || header.type === "symlink") header.size = 0;
|
|
2119
|
+
if (!header.type) header.type = modeToType(header.mode);
|
|
2120
|
+
if (!header.mode) header.mode = header.type === "directory" ? DMODE : FMODE;
|
|
2121
|
+
if (!header.uid) header.uid = 0;
|
|
2122
|
+
if (!header.gid) header.gid = 0;
|
|
2123
|
+
if (!header.mtime) header.mtime = /* @__PURE__ */ new Date();
|
|
2124
|
+
if (typeof buffer === "string") buffer = b4a.from(buffer);
|
|
2125
|
+
const sink = new Sink(this, header, callback);
|
|
2126
|
+
if (b4a.isBuffer(buffer)) {
|
|
2127
|
+
header.size = buffer.byteLength;
|
|
2128
|
+
sink.write(buffer);
|
|
2129
|
+
sink.end();
|
|
2130
|
+
return sink;
|
|
2131
|
+
}
|
|
2132
|
+
if (sink._isVoid) return sink;
|
|
2133
|
+
return sink;
|
|
2134
|
+
}
|
|
2135
|
+
finalize() {
|
|
2136
|
+
if (this._stream || this._pending.length > 0) {
|
|
2137
|
+
this._finalizing = true;
|
|
2138
|
+
return;
|
|
2139
|
+
}
|
|
2140
|
+
if (this._finalized) return;
|
|
2141
|
+
this._finalized = true;
|
|
2142
|
+
this.push(END_OF_TAR);
|
|
2143
|
+
this.push(null);
|
|
2144
|
+
}
|
|
2145
|
+
_done(stream) {
|
|
2146
|
+
if (stream !== this._stream) return;
|
|
2147
|
+
this._stream = null;
|
|
2148
|
+
if (this._finalizing) this.finalize();
|
|
2149
|
+
if (this._pending.length) this._pending.shift()._continueOpen();
|
|
2150
|
+
}
|
|
2151
|
+
_encode(header) {
|
|
2152
|
+
if (!header.pax) {
|
|
2153
|
+
const buf = headers.encode(header);
|
|
2154
|
+
if (buf) {
|
|
2155
|
+
this.push(buf);
|
|
2156
|
+
return;
|
|
2157
|
+
}
|
|
2158
|
+
}
|
|
2159
|
+
this._encodePax(header);
|
|
2160
|
+
}
|
|
2161
|
+
_encodePax(header) {
|
|
2162
|
+
const paxHeader = headers.encodePax({
|
|
2163
|
+
name: header.name,
|
|
2164
|
+
linkname: header.linkname,
|
|
2165
|
+
pax: header.pax
|
|
2166
|
+
});
|
|
2167
|
+
const newHeader = {
|
|
2168
|
+
name: "PaxHeader",
|
|
2169
|
+
mode: header.mode,
|
|
2170
|
+
uid: header.uid,
|
|
2171
|
+
gid: header.gid,
|
|
2172
|
+
size: paxHeader.byteLength,
|
|
2173
|
+
mtime: header.mtime,
|
|
2174
|
+
type: "pax-header",
|
|
2175
|
+
linkname: header.linkname && "PaxHeader",
|
|
2176
|
+
uname: header.uname,
|
|
2177
|
+
gname: header.gname,
|
|
2178
|
+
devmajor: header.devmajor,
|
|
2179
|
+
devminor: header.devminor
|
|
2180
|
+
};
|
|
2181
|
+
this.push(headers.encode(newHeader));
|
|
2182
|
+
this.push(paxHeader);
|
|
2183
|
+
overflow(this, paxHeader.byteLength);
|
|
2184
|
+
newHeader.size = header.size;
|
|
2185
|
+
newHeader.type = header.type;
|
|
2186
|
+
this.push(headers.encode(newHeader));
|
|
2187
|
+
}
|
|
2188
|
+
_doDrain() {
|
|
2189
|
+
const drain = this._drain;
|
|
2190
|
+
this._drain = noop;
|
|
2191
|
+
drain();
|
|
2192
|
+
}
|
|
2193
|
+
_predestroy() {
|
|
2194
|
+
const err = getStreamError(this);
|
|
2195
|
+
if (this._stream) this._stream.destroy(err);
|
|
2196
|
+
while (this._pending.length) {
|
|
2197
|
+
const stream = this._pending.shift();
|
|
2198
|
+
stream.destroy(err);
|
|
2199
|
+
stream._continueOpen();
|
|
2200
|
+
}
|
|
2201
|
+
this._doDrain();
|
|
2202
|
+
}
|
|
2203
|
+
_read(cb) {
|
|
2204
|
+
this._doDrain();
|
|
2205
|
+
cb();
|
|
2206
|
+
}
|
|
2207
|
+
};
|
|
2208
|
+
module.exports = function pack(opts) {
|
|
2209
|
+
return new Pack(opts);
|
|
2210
|
+
};
|
|
2211
|
+
function modeToType(mode) {
|
|
2212
|
+
switch (mode & constants.S_IFMT) {
|
|
2213
|
+
case constants.S_IFBLK: return "block-device";
|
|
2214
|
+
case constants.S_IFCHR: return "character-device";
|
|
2215
|
+
case constants.S_IFDIR: return "directory";
|
|
2216
|
+
case constants.S_IFIFO: return "fifo";
|
|
2217
|
+
case constants.S_IFLNK: return "symlink";
|
|
2218
|
+
}
|
|
2219
|
+
return "file";
|
|
2220
|
+
}
|
|
2221
|
+
function noop() {}
|
|
2222
|
+
function overflow(self, size) {
|
|
2223
|
+
size &= 511;
|
|
2224
|
+
if (size) self.push(END_OF_TAR.subarray(0, 512 - size));
|
|
2225
|
+
}
|
|
2226
|
+
function mapWritable(buf) {
|
|
2227
|
+
return b4a.isBuffer(buf) ? buf : b4a.from(buf);
|
|
2228
|
+
}
|
|
2229
|
+
}));
|
|
2230
|
+
//#endregion
|
|
2231
|
+
//#region ../../packages/workflow-builder/dist/agent-bundle-package-DWV6B_5q.mjs
|
|
2232
|
+
var import_tar_stream = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports) => {
|
|
2233
|
+
exports.extract = require_extract();
|
|
2234
|
+
exports.pack = require_pack();
|
|
2235
|
+
})))(), 1);
|
|
2236
|
+
const AGENT_SANDBOX_PACKAGE_MANIFEST_PATH = ".keystroke/sandbox-package.json";
|
|
2237
|
+
const AGENT_VM_TOOLS_RUNTIME_RELATIVE_PATH = "build/tools.js";
|
|
2238
|
+
const AGENT_VM_HOST_CALL_RELATIVE_PATH = "build/host-call.js";
|
|
2239
|
+
const AGENT_VM_PI_SKILLS_ROOT = "/home/user/.pi/skills";
|
|
2240
|
+
const AgentBundleEntrySchema = z.object({
|
|
2241
|
+
archivePath: z.string().min(1),
|
|
2242
|
+
path: z.string().min(1),
|
|
2243
|
+
mode: z.number().int().positive().optional(),
|
|
2244
|
+
restoreBehavior: z.enum(["overwrite", "preserve"]).default("overwrite")
|
|
2245
|
+
});
|
|
2246
|
+
const AgentBundleManifestSchema = z.object({
|
|
2247
|
+
format: z.literal("keystroke-agent-sandbox-package-v1"),
|
|
2248
|
+
version: z.literal(1),
|
|
2249
|
+
entries: z.array(AgentBundleEntrySchema)
|
|
2250
|
+
});
|
|
2251
|
+
function toBuffer(content) {
|
|
2252
|
+
return Buffer.isBuffer(content) ? content : Buffer.from(content, "utf8");
|
|
2253
|
+
}
|
|
2254
|
+
function streamToBuffer(stream) {
|
|
2255
|
+
return new Promise((resolve, reject) => {
|
|
2256
|
+
const chunks = [];
|
|
2257
|
+
stream.on("data", (chunk) => {
|
|
2258
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
2259
|
+
});
|
|
2260
|
+
stream.on("end", () => resolve(Buffer.concat(chunks)));
|
|
2261
|
+
stream.on("error", reject);
|
|
2262
|
+
});
|
|
2263
|
+
}
|
|
2264
|
+
function addTarEntry(pack, header, content) {
|
|
2265
|
+
return new Promise((resolve, reject) => {
|
|
2266
|
+
pack.entry(header, content, (error) => {
|
|
2267
|
+
if (error) {
|
|
2268
|
+
reject(error);
|
|
2269
|
+
return;
|
|
2270
|
+
}
|
|
2271
|
+
resolve();
|
|
2272
|
+
});
|
|
2273
|
+
});
|
|
2274
|
+
}
|
|
2275
|
+
async function createAgentSandboxPackage(files) {
|
|
2276
|
+
const pack = import_tar_stream.pack();
|
|
2277
|
+
const gzip = createGzip();
|
|
2278
|
+
pack.pipe(gzip);
|
|
2279
|
+
const outputPromise = streamToBuffer(gzip);
|
|
2280
|
+
const manifest = AgentBundleManifestSchema.parse({
|
|
2281
|
+
format: "keystroke-agent-sandbox-package-v1",
|
|
2282
|
+
version: 1,
|
|
2283
|
+
entries: files.map((file, index) => ({
|
|
2284
|
+
archivePath: `files/${index.toString().padStart(4, "0")}`,
|
|
2285
|
+
path: file.path,
|
|
2286
|
+
mode: file.mode,
|
|
2287
|
+
restoreBehavior: file.restoreBehavior ?? "overwrite"
|
|
2288
|
+
}))
|
|
2289
|
+
});
|
|
2290
|
+
await addTarEntry(pack, {
|
|
2291
|
+
name: AGENT_SANDBOX_PACKAGE_MANIFEST_PATH,
|
|
2292
|
+
type: "file",
|
|
2293
|
+
mode: 420
|
|
2294
|
+
}, `${JSON.stringify(manifest, null, 2)}\n`);
|
|
2295
|
+
for (const [index, file] of files.entries()) await addTarEntry(pack, {
|
|
2296
|
+
name: `files/${index.toString().padStart(4, "0")}`,
|
|
2297
|
+
type: "file",
|
|
2298
|
+
mode: file.mode ?? 420
|
|
2299
|
+
}, toBuffer(file.content));
|
|
2300
|
+
pack.finalize();
|
|
2301
|
+
return outputPromise;
|
|
2302
|
+
}
|
|
2303
|
+
async function readPackageStream(input) {
|
|
2304
|
+
const extract = import_tar_stream.extract();
|
|
2305
|
+
const gunzip = createGunzip();
|
|
2306
|
+
const archiveEntries = /* @__PURE__ */ new Map();
|
|
2307
|
+
let manifestBuffer;
|
|
2308
|
+
const done = new Promise((resolve, reject) => {
|
|
2309
|
+
extract.on("entry", (header, stream, next) => {
|
|
2310
|
+
const chunks = [];
|
|
2311
|
+
stream.on("data", (chunk) => {
|
|
2312
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
2313
|
+
});
|
|
2314
|
+
stream.on("error", reject);
|
|
2315
|
+
stream.on("end", () => {
|
|
2316
|
+
const content = Buffer.concat(chunks);
|
|
2317
|
+
if (header.name === AGENT_SANDBOX_PACKAGE_MANIFEST_PATH) manifestBuffer = content;
|
|
2318
|
+
else archiveEntries.set(header.name, content);
|
|
2319
|
+
next();
|
|
2320
|
+
});
|
|
2321
|
+
});
|
|
2322
|
+
extract.on("finish", () => resolve());
|
|
2323
|
+
extract.on("error", reject);
|
|
2324
|
+
gunzip.on("error", reject);
|
|
2325
|
+
});
|
|
2326
|
+
Readable.from(input).pipe(gunzip).pipe(extract);
|
|
2327
|
+
await done;
|
|
2328
|
+
if (!manifestBuffer) throw new Error("Agent sandbox package is missing its manifest");
|
|
2329
|
+
return AgentBundleManifestSchema.parse(JSON.parse(manifestBuffer.toString("utf8"))).entries.map((entry) => {
|
|
2330
|
+
const blob = archiveEntries.get(entry.archivePath);
|
|
2331
|
+
if (!blob) throw new Error(`Agent sandbox package is missing archive entry ${entry.archivePath}`);
|
|
2332
|
+
return {
|
|
2333
|
+
path: entry.path,
|
|
2334
|
+
content: blob,
|
|
2335
|
+
mode: entry.mode,
|
|
2336
|
+
restoreBehavior: entry.restoreBehavior
|
|
2337
|
+
};
|
|
2338
|
+
});
|
|
2339
|
+
}
|
|
2340
|
+
async function readAgentSandboxPackage(buffer) {
|
|
2341
|
+
return readPackageStream(buffer);
|
|
2342
|
+
}
|
|
2343
|
+
//#endregion
|
|
2344
|
+
export { readAgentSandboxPackage as a, createAgentSandboxPackage as i, AGENT_VM_PI_SKILLS_ROOT as n, AGENT_VM_TOOLS_RUNTIME_RELATIVE_PATH as r, AGENT_VM_HOST_CALL_RELATIVE_PATH as t };
|