@poe-platform/safe-bash 0.1.755 → 0.1.757
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/dist/image-ast/index.browser.js +30 -6
- package/dist/image-ast/index.js +30 -6
- package/dist/pdf-ast/canvas.d.ts +1 -0
- package/dist/pdf-ast/index.js +26 -2
- package/dist/safe-bash/chunks/{chunk-LESPJ3OG.js → chunk-WNWIBBJZ.js} +15 -2
- package/dist/safe-bash/command-chunks/{chunk-S4J6MSLY.js → chunk-444OTXM7.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-6AIOGLZO.js → chunk-CE6Z2ULX.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-5VSGEE6J.js → chunk-F4IQCXZG.js} +5 -5
- package/dist/safe-bash/command-chunks/{chunk-F5MORDSU.js → chunk-FDNCPZQS.js} +32 -1
- package/dist/safe-bash/command-chunks/{chunk-SG3ZDZCX.js → chunk-FLMLM7Y4.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-XRVNFK7Z.js → chunk-H2FQA4OU.js} +26 -2
- package/dist/safe-bash/command-chunks/{chunk-CT3FB722.js → chunk-J7UMKBRK.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-KB2LQ4HG.js → chunk-KBBI4CSU.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-QQOAK7JQ.js → chunk-KKJCKPTA.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-7KS6PX4U.js → chunk-KSIGF4AG.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-4HQ7WYSI.js → chunk-MED2BOOW.js} +30 -5
- package/dist/safe-bash/command-chunks/{chunk-JRNLDPLI.js → chunk-OZSWW23M.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-DKQ5REXF.js → chunk-QDPRSPHQ.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-WOPU2VWF.js → chunk-RID3B5RE.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-DVZCHNB5.js → chunk-S4MLIYSN.js} +7 -7
- package/dist/safe-bash/command-chunks/{chunk-REYTQLLB.js → chunk-TT2DMDBY.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-UGX6MXDD.js → chunk-UIIT4ULR.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-MENC7RPR.js → chunk-WI35236J.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-A6NFLWZI.js → chunk-WKPOGTZY.js} +22 -6
- package/dist/safe-bash/command-chunks/{chunk-3DOHQQJR.js → chunk-Y64PA6IA.js} +8 -8
- package/dist/safe-bash/command-chunks/{chunk-6Z7OS3TZ.js → chunk-ZP5KDHB4.js} +7 -7
- package/dist/safe-bash/commands/pandoc/index.d.ts +1 -1
- package/dist/safe-bash/commands/pandoc/index.js +5 -3
- package/dist/safe-bash/commands/python/index.browser.js +1 -1
- package/dist/safe-bash/commands/python/index.js +6 -0
- package/dist/safe-bash/commands/python/jspi.js +11 -2
- package/dist/safe-bash/core.browser.js +6 -4
- package/dist/safe-bash-command-csvkit/index.js +8 -8
- package/dist/safe-bash-command-ffmpeg/index.js +20 -2
- package/dist/safe-bash-command-imagemagick/index.js +2 -2
- package/dist/safe-bash-command-pandoc/command.js +3 -3
- package/dist/safe-bash-command-pandoc/index.js +3 -3
- package/dist/safe-bash-command-pdfimages/index.js +26 -2
- package/dist/safe-bash-command-pdfinfo/index.js +26 -2
- package/dist/safe-bash-command-pdftk/index.js +26 -2
- package/dist/safe-bash-command-pdftoppm/index.js +26 -2
- package/dist/safe-bash-command-pdftotext/index.js +26 -2
- package/dist/safe-bash-command-qpdf/index.js +26 -2
- package/dist/safe-bash-command-sips/index.js +2 -2
- package/dist/safe-bash-command-soffice/index.js +17 -17
- package/dist/safe-bash-command-ssconvert/core.js +8 -8
- package/dist/safe-bash-command-ssconvert/formats/csv.js +9 -9
- package/dist/safe-bash-command-ssconvert/formats/ods.js +8 -8
- package/dist/safe-bash-command-ssconvert/formats/spreadsheetml.js +1 -1
- package/dist/safe-bash-command-ssconvert/formats/xls.js +9 -8
- package/dist/safe-bash-command-ssconvert/formats/xlsx.js +8 -8
- package/dist/safe-bash-command-ssconvert/index.js +133 -29
- package/dist/safe-bash-command-wkhtmltopdf/index.js +26 -2
- package/dist/safe-bash-contracts/filesystem-descriptor.js +1 -1
- package/dist/safe-bash-contracts/filesystem-output.js +1 -1
- package/dist/safe-bash-mcp/index.js +4 -4
- package/dist/spreadsheet-engine/formulas/ast.d.ts +13 -0
- package/dist/spreadsheet-engine/formulas/conventions.js +1 -1
- package/dist/spreadsheet-engine/formulas/dependencies.js +2 -2
- package/dist/spreadsheet-engine/formulas/evaluator.js +2 -2
- package/dist/spreadsheet-engine/formulas/named-expressions.d.ts +2 -2
- package/dist/spreadsheet-engine/formulas/named-expressions.js +31 -5
- package/dist/spreadsheet-engine/formulas/parser.js +34 -0
- package/dist/spreadsheet-engine/formulas/rewriting.js +19 -1
- package/dist/spreadsheet-engine/formulas/serialization.js +6 -0
- package/dist/spreadsheet-format-xls/biff-write-formulas.js +2 -0
- package/dist/xlsx-ast/formula-semantics.js +2 -0
- package/package.json +2 -2
- package/third-party/pdf-ast/THIRD_PARTY_NOTICES.md +1 -1
- package/dist/safe-bash/chunks/browser-ECQX6GMK.js +0 -6766
- package/dist/safe-bash/chunks/bz2-4OP3OWW3.js +0 -8
- package/dist/safe-bash/chunks/chunk-22XPAAOI.js +0 -173
- package/dist/safe-bash/chunks/chunk-44WUNUPV.js +0 -649
- package/dist/safe-bash/chunks/chunk-4E3SGG37.js +0 -876
- package/dist/safe-bash/chunks/chunk-4QTSSQKP.js +0 -898
- package/dist/safe-bash/chunks/chunk-5UVGPVXP.js +0 -410
- package/dist/safe-bash/chunks/chunk-64OE6Q6X.js +0 -3487
- package/dist/safe-bash/chunks/chunk-6IIFUPN2.js +0 -1526
- package/dist/safe-bash/chunks/chunk-6XDKK63A.js +0 -38959
- package/dist/safe-bash/chunks/chunk-BENDLTQD.js +0 -7065
- package/dist/safe-bash/chunks/chunk-BMO5LWEX.js +0 -534
- package/dist/safe-bash/chunks/chunk-BPMCPTNP.js +0 -1920
- package/dist/safe-bash/chunks/chunk-BRJTAWP5.js +0 -2955
- package/dist/safe-bash/chunks/chunk-C3GEIN7Q.js +0 -20054
- package/dist/safe-bash/chunks/chunk-CEWCRI6H.js +0 -2813
- package/dist/safe-bash/chunks/chunk-CGL53DQQ.js +0 -37
- package/dist/safe-bash/chunks/chunk-CTYJJD4O.js +0 -869
- package/dist/safe-bash/chunks/chunk-CWSS4MQA.js +0 -7
- package/dist/safe-bash/chunks/chunk-DLIGMTCP.js +0 -3266
- package/dist/safe-bash/chunks/chunk-EMAJ7WUW.js +0 -1031
- package/dist/safe-bash/chunks/chunk-FDKIZ2IJ.js +0 -1950
- package/dist/safe-bash/chunks/chunk-FZWJ2A7V.js +0 -3093
- package/dist/safe-bash/chunks/chunk-G2VCIF2J.js +0 -22
- package/dist/safe-bash/chunks/chunk-GVKBUQDX.js +0 -2649
- package/dist/safe-bash/chunks/chunk-IO2OGW3E.js +0 -28051
- package/dist/safe-bash/chunks/chunk-ISCZG7WA.js +0 -2648
- package/dist/safe-bash/chunks/chunk-JEFBTRY7.js +0 -174814
- package/dist/safe-bash/chunks/chunk-KJHDD4A2.js +0 -759
- package/dist/safe-bash/chunks/chunk-LB6HVRXS.js +0 -857
- package/dist/safe-bash/chunks/chunk-LLWAJOZH.js +0 -15
- package/dist/safe-bash/chunks/chunk-LMUKYZIJ.js +0 -708
- package/dist/safe-bash/chunks/chunk-M5SCNKIK.js +0 -2012
- package/dist/safe-bash/chunks/chunk-MJPFHANT.js +0 -3350
- package/dist/safe-bash/chunks/chunk-MZQW2DOL.js +0 -82
- package/dist/safe-bash/chunks/chunk-NB2V7EOY.js +0 -1348
- package/dist/safe-bash/chunks/chunk-NJVGOIYN.js +0 -17
- package/dist/safe-bash/chunks/chunk-OLNZHDIQ.js +0 -5141
- package/dist/safe-bash/chunks/chunk-OUUVROTM.js +0 -38
- package/dist/safe-bash/chunks/chunk-PA6GYKBQ.js +0 -151
- package/dist/safe-bash/chunks/chunk-PEFHZ226.js +0 -6957
- package/dist/safe-bash/chunks/chunk-QBB5P5KW.js +0 -4839
- package/dist/safe-bash/chunks/chunk-QHB7HBLA.js +0 -2317
- package/dist/safe-bash/chunks/chunk-RSAWYAEH.js +0 -973
- package/dist/safe-bash/chunks/chunk-UWLYRWT4.js +0 -739
- package/dist/safe-bash/chunks/chunk-V463NBQH.js +0 -13
- package/dist/safe-bash/chunks/chunk-WPUALYUS.js +0 -843
- package/dist/safe-bash/chunks/chunk-XHKFSRGU.js +0 -5747
- package/dist/safe-bash/chunks/chunk-XHRCLZ3N.js +0 -13391
- package/dist/safe-bash/chunks/chunk-XPF5XHLY.js +0 -15
- package/dist/safe-bash/chunks/chunk-ZBFOWARG.js +0 -305
- package/dist/safe-bash/chunks/chunk-ZG7GWQ5P.js +0 -1859
- package/dist/safe-bash/chunks/model-store-EIY3ZQLZ.js +0 -10
- package/dist/safe-bash/chunks/pdf-renderer-XIFUTX34.js +0 -22
- package/dist/safe-bash/chunks/pptx-ZL6L7KP2-O425BFIU.js +0 -30658
- package/dist/safe-bash/chunks/src-HHEPGR7U.js +0 -18969
- package/dist/safe-bash/chunks/src-V4VCM5OX.js +0 -187
- package/dist/safe-bash/chunks/usage-6TGVA2OM.js +0 -35
- package/dist/safe-bash/chunks/xz-EGQGQUEI.js +0 -8
- package/dist/safe-bash/chunks/xz-K2E2WLM6.js +0 -9
- package/dist/safe-bash/chunks/zstd-6JBLP5EF.js +0 -8
- package/dist/safe-bash/git_rust-C3QYOAZL.wasm +0 -0
|
@@ -1,876 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
builtInDirectContextExecutors
|
|
3
|
-
} from "./chunk-ISCZG7WA.js";
|
|
4
|
-
import {
|
|
5
|
-
init_platform
|
|
6
|
-
} from "./chunk-ZG7GWQ5P.js";
|
|
7
|
-
|
|
8
|
-
// packages/safe-bash/src/commands/hexdump/index.ts
|
|
9
|
-
init_platform();
|
|
10
|
-
|
|
11
|
-
// packages/safe-bash-command-hexdump/src/index.ts
|
|
12
|
-
init_platform();
|
|
13
|
-
|
|
14
|
-
// packages/safe-bash-command-hexdump/src/command.ts
|
|
15
|
-
init_platform();
|
|
16
|
-
import { FsError as FsError2 } from "../../safe-bash-contracts/index.js";
|
|
17
|
-
import { createOutputOperation } from "../../safe-bash-contracts/output.js";
|
|
18
|
-
import { outputFailure } from "../../safe-bash-contracts/io.js";
|
|
19
|
-
|
|
20
|
-
// packages/safe-bash-command-hexdump/src/internal.ts
|
|
21
|
-
init_platform();
|
|
22
|
-
import { getCommandArguments } from "../../safe-bash-contracts/index.js";
|
|
23
|
-
import { shellValueByteLength, shellValueBytes } from "../../safe-bash-contracts/value.js";
|
|
24
|
-
import { yieldTurn } from "../../safe-bash-contracts/yield.js";
|
|
25
|
-
import { PublicDiagnostic } from "../../safe-bash-contracts/diagnostics.js";
|
|
26
|
-
function settings(options) {
|
|
27
|
-
if (options.dialect !== void 0 && options.dialect !== "bsd" && options.dialect !== "util-linux") throw new RangeError("Invalid hexdump dialect");
|
|
28
|
-
const limits = {
|
|
29
|
-
maxArguments: Infinity,
|
|
30
|
-
maxArgumentBytes: Infinity,
|
|
31
|
-
maxInputBytes: Infinity,
|
|
32
|
-
maxBufferedBytes: Infinity,
|
|
33
|
-
maxOutputBytes: Infinity,
|
|
34
|
-
maxDiagnosticBytes: Infinity,
|
|
35
|
-
maxFormats: Infinity,
|
|
36
|
-
maxWork: Infinity,
|
|
37
|
-
maxEmptyChunks: Infinity,
|
|
38
|
-
...options.limits
|
|
39
|
-
};
|
|
40
|
-
for (const [name, value] of Object.entries(options.limits ?? {})) {
|
|
41
|
-
if (value !== Infinity && (!Number.isSafeInteger(value) || value < 1)) throw new RangeError(`Invalid hexdump limit: ${name}`);
|
|
42
|
-
}
|
|
43
|
-
return Object.freeze(limits);
|
|
44
|
-
}
|
|
45
|
-
var HexdumpError = class extends PublicDiagnostic {
|
|
46
|
-
constructor(message, bare = false) {
|
|
47
|
-
super(message);
|
|
48
|
-
this.bare = bare;
|
|
49
|
-
}
|
|
50
|
-
bare;
|
|
51
|
-
};
|
|
52
|
-
function raw(value) {
|
|
53
|
-
let result = "";
|
|
54
|
-
for (let offset = 0; offset < value.length; offset += 4096) result += String.fromCharCode(...value.subarray(offset, offset + 4096));
|
|
55
|
-
return result;
|
|
56
|
-
}
|
|
57
|
-
function bytes(value) {
|
|
58
|
-
const out = new Uint8Array(value.length);
|
|
59
|
-
for (let i = 0; i < value.length; i++) out[i] = value.charCodeAt(i);
|
|
60
|
-
return out;
|
|
61
|
-
}
|
|
62
|
-
function pathText(value) {
|
|
63
|
-
try {
|
|
64
|
-
return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes(value));
|
|
65
|
-
} catch {
|
|
66
|
-
throw new HexdumpError("filesystem paths must be valid UTF-8");
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
var Budget = class {
|
|
70
|
-
constructor(context, limits, signal, callerSignal, admission) {
|
|
71
|
-
this.context = context;
|
|
72
|
-
this.limits = limits;
|
|
73
|
-
this.signal = signal;
|
|
74
|
-
this.callerSignal = callerSignal;
|
|
75
|
-
this.admission = admission;
|
|
76
|
-
this.pollSignal = typeof signal.addEventListener !== "function" || Object.prototype.hasOwnProperty.call(signal, "aborted");
|
|
77
|
-
if (signal.aborted) this.aborted = true;
|
|
78
|
-
else if (!this.pollSignal) signal.addEventListener("abort", () => {
|
|
79
|
-
this.aborted = true;
|
|
80
|
-
}, { once: true });
|
|
81
|
-
}
|
|
82
|
-
context;
|
|
83
|
-
limits;
|
|
84
|
-
signal;
|
|
85
|
-
callerSignal;
|
|
86
|
-
admission;
|
|
87
|
-
work = 0;
|
|
88
|
-
checkpoint = 0;
|
|
89
|
-
retained = 0;
|
|
90
|
-
input = 0;
|
|
91
|
-
output = 0;
|
|
92
|
-
diagnostics = 0;
|
|
93
|
-
aborted = false;
|
|
94
|
-
pollSignal;
|
|
95
|
-
assertOpen() {
|
|
96
|
-
if (this.aborted || this.pollSignal && this.signal.aborted) {
|
|
97
|
-
this.aborted = true;
|
|
98
|
-
this.signal.throwIfAborted();
|
|
99
|
-
}
|
|
100
|
-
if (this.admission.closed) throw new HexdumpError("command is closed");
|
|
101
|
-
}
|
|
102
|
-
check(value, maximum, label) {
|
|
103
|
-
if (!Number.isSafeInteger(value) || value < 0 || value > maximum) throw new HexdumpError(`${label} limit exceeded`);
|
|
104
|
-
}
|
|
105
|
-
charge(amount = 1) {
|
|
106
|
-
this.assertOpen();
|
|
107
|
-
this.check(this.work + amount, this.limits.maxWork, "work");
|
|
108
|
-
this.work += amount;
|
|
109
|
-
}
|
|
110
|
-
canChargeWithoutCheckpoint(amount) {
|
|
111
|
-
if (this.aborted || this.pollSignal && this.signal.aborted || this.admission.closed) return false;
|
|
112
|
-
if (this.work + amount > this.limits.maxWork) return false;
|
|
113
|
-
return this.work + amount - this.checkpoint < 4096;
|
|
114
|
-
}
|
|
115
|
-
checkpointWork() {
|
|
116
|
-
this.assertOpen();
|
|
117
|
-
if (this.work - this.checkpoint < 4096) return;
|
|
118
|
-
this.checkpoint = this.work;
|
|
119
|
-
return yieldTurn(this.callerSignal).then(() => {
|
|
120
|
-
this.assertOpen();
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
retain(amount) {
|
|
124
|
-
this.check(this.retained + amount, this.limits.maxBufferedBytes, "buffered bytes");
|
|
125
|
-
this.retained += amount;
|
|
126
|
-
}
|
|
127
|
-
inputBytes(amount) {
|
|
128
|
-
this.check(this.input + amount, this.limits.maxInputBytes, "input bytes");
|
|
129
|
-
this.input += amount;
|
|
130
|
-
}
|
|
131
|
-
emitted(amount, diagnostic) {
|
|
132
|
-
if (diagnostic) {
|
|
133
|
-
this.check(this.diagnostics + amount, this.limits.maxDiagnosticBytes, "diagnostic bytes");
|
|
134
|
-
this.diagnostics += amount;
|
|
135
|
-
} else {
|
|
136
|
-
this.check(this.output + amount, this.limits.maxOutputBytes, "output bytes");
|
|
137
|
-
this.charge(amount);
|
|
138
|
-
this.output += amount;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
arguments() {
|
|
142
|
-
this.assertOpen();
|
|
143
|
-
const args = this.context.args;
|
|
144
|
-
this.assertOpen();
|
|
145
|
-
const count = args.length;
|
|
146
|
-
this.assertOpen();
|
|
147
|
-
this.check(count, this.limits.maxArguments, "argument count");
|
|
148
|
-
const argumentValues = this.context.argumentValues;
|
|
149
|
-
this.assertOpen();
|
|
150
|
-
const carrier = argumentValues === void 0 ? void 0 : getCommandArguments({ args, argumentValues });
|
|
151
|
-
this.assertOpen();
|
|
152
|
-
this.retain(count * 64 + 128);
|
|
153
|
-
const snapshot = [];
|
|
154
|
-
let units = 0, total = 0;
|
|
155
|
-
for (let index = 0; index < count; index++) {
|
|
156
|
-
const argument = args[index];
|
|
157
|
-
this.assertOpen();
|
|
158
|
-
if (typeof argument !== "string") throw new HexdumpError("arguments must be strings");
|
|
159
|
-
units += argument.length;
|
|
160
|
-
this.check(units, this.limits.maxArgumentBytes, "argument bytes");
|
|
161
|
-
this.charge(argument.length + 1);
|
|
162
|
-
for (let offset = 0; offset < argument.length; offset++) {
|
|
163
|
-
const unit = argument.charCodeAt(offset);
|
|
164
|
-
if (unit >= 55296 && unit <= 56319) {
|
|
165
|
-
const next = argument.charCodeAt(++offset);
|
|
166
|
-
if (!(next >= 56320 && next <= 57343)) throw new HexdumpError("arguments must contain well-formed Unicode");
|
|
167
|
-
} else if (unit >= 56320 && unit <= 57343) throw new HexdumpError("arguments must contain well-formed Unicode");
|
|
168
|
-
}
|
|
169
|
-
const size = shellValueByteLength(carrier ? carrier.values[index] : argument);
|
|
170
|
-
total += size;
|
|
171
|
-
this.check(total, this.limits.maxArgumentBytes, "argument bytes");
|
|
172
|
-
this.charge(size);
|
|
173
|
-
this.retain(size * 8);
|
|
174
|
-
snapshot.push(argument);
|
|
175
|
-
}
|
|
176
|
-
return (carrier ?? getCommandArguments({ args: snapshot })).values.map((argument) => {
|
|
177
|
-
this.charge(shellValueByteLength(argument));
|
|
178
|
-
const value = shellValueBytes(argument);
|
|
179
|
-
if (value.includes(0)) throw new HexdumpError("NUL is not supported in arguments");
|
|
180
|
-
return raw(value);
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
// packages/safe-bash-command-hexdump/src/io.ts
|
|
186
|
-
init_platform();
|
|
187
|
-
import { FsError, resolvePath } from "../../safe-bash-contracts/index.js";
|
|
188
|
-
var typedArrayPrototype = Object.getPrototypeOf(Uint8Array.prototype);
|
|
189
|
-
var viewBuffer = Object.getOwnPropertyDescriptor(typedArrayPrototype, "buffer").get;
|
|
190
|
-
var viewOffset = Object.getOwnPropertyDescriptor(typedArrayPrototype, "byteOffset").get;
|
|
191
|
-
var viewLength = Object.getOwnPropertyDescriptor(typedArrayPrototype, "byteLength").get;
|
|
192
|
-
var Lifecycle = class {
|
|
193
|
-
constructor(budget, output, stdout, caller) {
|
|
194
|
-
this.budget = budget;
|
|
195
|
-
this.stdout = stdout;
|
|
196
|
-
this.caller = caller;
|
|
197
|
-
output.registerCleanup(() => this.close());
|
|
198
|
-
}
|
|
199
|
-
budget;
|
|
200
|
-
stdout;
|
|
201
|
-
caller;
|
|
202
|
-
pending = /* @__PURE__ */ new Set();
|
|
203
|
-
cleanups = /* @__PURE__ */ new Set();
|
|
204
|
-
closing;
|
|
205
|
-
diagnostic;
|
|
206
|
-
diagnosticCancellation;
|
|
207
|
-
cleanup(action) {
|
|
208
|
-
this.assertOpen();
|
|
209
|
-
this.cleanups.add(action);
|
|
210
|
-
}
|
|
211
|
-
forget(action) {
|
|
212
|
-
this.cleanups.delete(action);
|
|
213
|
-
}
|
|
214
|
-
assertOpen() {
|
|
215
|
-
this.budget.assertOpen();
|
|
216
|
-
if (this.closing) throw new HexdumpError("command is closed");
|
|
217
|
-
}
|
|
218
|
-
assertDiagnosticOpen() {
|
|
219
|
-
this.caller.throwIfAborted();
|
|
220
|
-
const consumer = this.diagnostic?.consumer;
|
|
221
|
-
if (consumer?.aborted) {
|
|
222
|
-
this.diagnosticCancellation = { reason: consumer.reason };
|
|
223
|
-
consumer.throwIfAborted();
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
async operation(action, diagnostic = false) {
|
|
227
|
-
if (diagnostic) this.assertDiagnosticOpen();
|
|
228
|
-
else this.assertOpen();
|
|
229
|
-
if (this.closing || this.budget.admission.closed) throw new HexdumpError("command is closed");
|
|
230
|
-
if (!diagnostic) this.budget.charge();
|
|
231
|
-
const pending = Promise.resolve().then(() => {
|
|
232
|
-
if (diagnostic) this.assertDiagnosticOpen();
|
|
233
|
-
else this.assertOpen();
|
|
234
|
-
return action();
|
|
235
|
-
});
|
|
236
|
-
this.pending.add(pending);
|
|
237
|
-
try {
|
|
238
|
-
const value = await pending;
|
|
239
|
-
if (diagnostic) this.assertDiagnosticOpen();
|
|
240
|
-
else this.assertOpen();
|
|
241
|
-
return value;
|
|
242
|
-
} finally {
|
|
243
|
-
this.pending.delete(pending);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
close() {
|
|
247
|
-
return this.closing ??= Promise.resolve().then(async () => {
|
|
248
|
-
while (this.pending.size) await Promise.allSettled([...this.pending]);
|
|
249
|
-
const failures = [];
|
|
250
|
-
for (const cleanup of this.cleanups) {
|
|
251
|
-
try {
|
|
252
|
-
await cleanup();
|
|
253
|
-
} catch (error) {
|
|
254
|
-
failures.push(error);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
if (failures.length === 1) throw failures[0];
|
|
258
|
-
if (failures.length > 1) throw new AggregateError(failures, "hexdump cleanup failed");
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
async write(value, diagnostic = false) {
|
|
262
|
-
this.budget.emitted(value.length, diagnostic);
|
|
263
|
-
await this.operation(async () => {
|
|
264
|
-
if (!diagnostic) this.budget.retain(value.length * 3);
|
|
265
|
-
try {
|
|
266
|
-
let destination;
|
|
267
|
-
if (diagnostic) {
|
|
268
|
-
if (!this.diagnostic) {
|
|
269
|
-
const sink = this.budget.context.stderr;
|
|
270
|
-
this.assertDiagnosticOpen();
|
|
271
|
-
const capability = sink.ownedOutput;
|
|
272
|
-
this.assertDiagnosticOpen();
|
|
273
|
-
const consumer = capability?.consumerClosed;
|
|
274
|
-
this.diagnostic = { destination: capability ?? sink, consumer };
|
|
275
|
-
}
|
|
276
|
-
this.assertDiagnosticOpen();
|
|
277
|
-
destination = this.diagnostic.destination;
|
|
278
|
-
} else {
|
|
279
|
-
destination = this.stdout;
|
|
280
|
-
this.assertOpen();
|
|
281
|
-
}
|
|
282
|
-
const write = destination.write;
|
|
283
|
-
if (diagnostic) this.assertDiagnosticOpen();
|
|
284
|
-
else this.assertOpen();
|
|
285
|
-
await Reflect.apply(write, destination, [bytes(value)]);
|
|
286
|
-
} finally {
|
|
287
|
-
if (!diagnostic) this.budget.retain(-value.length * 3);
|
|
288
|
-
}
|
|
289
|
-
}, diagnostic);
|
|
290
|
-
}
|
|
291
|
-
};
|
|
292
|
-
var Reader = class {
|
|
293
|
-
constructor(name, lifecycle) {
|
|
294
|
-
this.name = name;
|
|
295
|
-
this.lifecycle = lifecycle;
|
|
296
|
-
lifecycle.budget.retain(256);
|
|
297
|
-
lifecycle.cleanup(this.close);
|
|
298
|
-
}
|
|
299
|
-
name;
|
|
300
|
-
lifecycle;
|
|
301
|
-
iterator;
|
|
302
|
-
chunk = new Uint8Array();
|
|
303
|
-
offset = 0;
|
|
304
|
-
ended = false;
|
|
305
|
-
empties = 0;
|
|
306
|
-
snapshotBytes = 0;
|
|
307
|
-
closed;
|
|
308
|
-
close = () => this.closed ??= Promise.resolve().then(async () => {
|
|
309
|
-
try {
|
|
310
|
-
if (!this.ended) await this.iterator?.return?.();
|
|
311
|
-
} finally {
|
|
312
|
-
this.iterator = void 0;
|
|
313
|
-
this.releaseSnapshot();
|
|
314
|
-
this.lifecycle.budget.retain(-this.chunk.length - 256);
|
|
315
|
-
this.chunk = new Uint8Array();
|
|
316
|
-
this.lifecycle.forget(this.close);
|
|
317
|
-
}
|
|
318
|
-
});
|
|
319
|
-
releaseSnapshot = () => {
|
|
320
|
-
this.lifecycle.budget.retain(-this.snapshotBytes);
|
|
321
|
-
this.snapshotBytes = 0;
|
|
322
|
-
};
|
|
323
|
-
async open() {
|
|
324
|
-
const { budget } = this.lifecycle;
|
|
325
|
-
await this.lifecycle.operation(async () => {
|
|
326
|
-
let source;
|
|
327
|
-
let needsAcquisitionCleanup = false;
|
|
328
|
-
if (this.name === void 0) source = budget.context.stdin;
|
|
329
|
-
else {
|
|
330
|
-
if (this.name === "") throw new FsError("ENOENT", { path: this.name });
|
|
331
|
-
const cwd = budget.context.cwd;
|
|
332
|
-
this.lifecycle.assertOpen();
|
|
333
|
-
const path = resolvePath(cwd, pathText(this.name));
|
|
334
|
-
const fs = budget.context.fs;
|
|
335
|
-
this.lifecycle.assertOpen();
|
|
336
|
-
const statMethod = fs.stat;
|
|
337
|
-
this.lifecycle.assertOpen();
|
|
338
|
-
const stat = await Reflect.apply(statMethod, fs, [path, { signal: budget.signal }]);
|
|
339
|
-
this.lifecycle.assertOpen();
|
|
340
|
-
const type = stat.type;
|
|
341
|
-
this.lifecycle.assertOpen();
|
|
342
|
-
if (this.name.endsWith("/") && type !== "directory") throw new FsError("ENOTDIR", { path });
|
|
343
|
-
if (type === "directory") throw new FsError("EISDIR", { path });
|
|
344
|
-
if (type !== "file" && type !== "character") throw new FsError("ENOTSUP", { path });
|
|
345
|
-
const capabilitiesFor = fs.capabilitiesFor;
|
|
346
|
-
this.lifecycle.assertOpen();
|
|
347
|
-
const selected = capabilitiesFor ? await Reflect.apply(capabilitiesFor, fs, [path, { signal: budget.signal }]) : void 0;
|
|
348
|
-
this.lifecycle.assertOpen();
|
|
349
|
-
const capabilities = selected ?? fs.capabilities;
|
|
350
|
-
this.lifecycle.assertOpen();
|
|
351
|
-
const readStream = fs.readStream;
|
|
352
|
-
this.lifecycle.assertOpen();
|
|
353
|
-
const streamingRead = readStream && capabilities.streamingRead !== false;
|
|
354
|
-
this.lifecycle.assertOpen();
|
|
355
|
-
if (readStream && streamingRead) {
|
|
356
|
-
source = Reflect.apply(readStream, fs, [path, { signal: budget.signal, chunkSize: 16384 }]);
|
|
357
|
-
needsAcquisitionCleanup = budget.signal.aborted || budget.admission.closed;
|
|
358
|
-
} else {
|
|
359
|
-
const maximum = Math.min(budget.limits.maxInputBytes, Math.floor(budget.limits.maxBufferedBytes / 2));
|
|
360
|
-
const size = stat.size;
|
|
361
|
-
this.lifecycle.assertOpen();
|
|
362
|
-
budget.check(size, maximum, "buffered input bytes");
|
|
363
|
-
budget.retain(Number.isFinite(maximum) ? maximum : size);
|
|
364
|
-
this.snapshotBytes = Number.isFinite(maximum) ? maximum : size;
|
|
365
|
-
const readFile = fs.readFile;
|
|
366
|
-
this.lifecycle.assertOpen();
|
|
367
|
-
const content = await Reflect.apply(readFile, fs, [path, { signal: budget.signal, ...Number.isFinite(maximum) ? { maxBytes: maximum } : {} }]);
|
|
368
|
-
this.lifecycle.assertOpen();
|
|
369
|
-
if (!(content instanceof Uint8Array)) throw new TypeError("hexdump input requires bytes");
|
|
370
|
-
const length = viewLength.call(content);
|
|
371
|
-
budget.check(length, maximum, "buffered input bytes");
|
|
372
|
-
budget.retain(length - this.snapshotBytes);
|
|
373
|
-
this.snapshotBytes = length;
|
|
374
|
-
const { releaseSnapshot } = this;
|
|
375
|
-
source = { async *[Symbol.asyncIterator]() {
|
|
376
|
-
try {
|
|
377
|
-
yield content;
|
|
378
|
-
} finally {
|
|
379
|
-
releaseSnapshot();
|
|
380
|
-
}
|
|
381
|
-
} };
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
if (!needsAcquisitionCleanup) this.lifecycle.assertOpen();
|
|
385
|
-
const factory = source[Symbol.asyncIterator];
|
|
386
|
-
if (!needsAcquisitionCleanup) this.lifecycle.assertOpen();
|
|
387
|
-
this.iterator = Reflect.apply(factory, source, []);
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
hasBufferedBytes() {
|
|
391
|
-
return this.offset < this.chunk.length;
|
|
392
|
-
}
|
|
393
|
-
canReadBlockSync(size) {
|
|
394
|
-
const { budget } = this.lifecycle;
|
|
395
|
-
return this.offset + size <= this.chunk.length && budget.canChargeWithoutCheckpoint(size);
|
|
396
|
-
}
|
|
397
|
-
readBlockSync(target, size) {
|
|
398
|
-
const { budget } = this.lifecycle;
|
|
399
|
-
budget.charge(size);
|
|
400
|
-
for (let i = 0; i < size; i++) target[i] = this.chunk[this.offset + i];
|
|
401
|
-
this.offset += size;
|
|
402
|
-
}
|
|
403
|
-
get() {
|
|
404
|
-
const { budget } = this.lifecycle;
|
|
405
|
-
budget.charge();
|
|
406
|
-
const cp = budget.checkpointWork();
|
|
407
|
-
if (!cp && this.offset < this.chunk.length) {
|
|
408
|
-
return this.chunk[this.offset++];
|
|
409
|
-
}
|
|
410
|
-
return this.getSlow(cp);
|
|
411
|
-
}
|
|
412
|
-
async getSlow(cp) {
|
|
413
|
-
const { budget } = this.lifecycle;
|
|
414
|
-
if (cp) await cp;
|
|
415
|
-
while (this.offset === this.chunk.length) {
|
|
416
|
-
if (this.ended) return -1;
|
|
417
|
-
const cp2 = budget.checkpointWork();
|
|
418
|
-
if (cp2) await cp2;
|
|
419
|
-
const next = await this.lifecycle.operation(() => {
|
|
420
|
-
const iterator = this.iterator;
|
|
421
|
-
const advance = iterator.next;
|
|
422
|
-
this.lifecycle.assertOpen();
|
|
423
|
-
return Reflect.apply(advance, iterator, []);
|
|
424
|
-
});
|
|
425
|
-
budget.retain(-this.chunk.length);
|
|
426
|
-
this.chunk = new Uint8Array();
|
|
427
|
-
this.offset = 0;
|
|
428
|
-
const done = next.done;
|
|
429
|
-
this.lifecycle.assertOpen();
|
|
430
|
-
if (done) {
|
|
431
|
-
this.ended = true;
|
|
432
|
-
this.iterator = void 0;
|
|
433
|
-
return -1;
|
|
434
|
-
}
|
|
435
|
-
const value = next.value;
|
|
436
|
-
this.lifecycle.assertOpen();
|
|
437
|
-
if (!(value instanceof Uint8Array)) throw new TypeError("hexdump input requires bytes");
|
|
438
|
-
const buffer = viewBuffer.call(value);
|
|
439
|
-
const offset = viewOffset.call(value);
|
|
440
|
-
const length = viewLength.call(value);
|
|
441
|
-
this.lifecycle.assertOpen();
|
|
442
|
-
budget.inputBytes(length);
|
|
443
|
-
budget.charge(length);
|
|
444
|
-
budget.retain(length);
|
|
445
|
-
try {
|
|
446
|
-
if (viewOffset.call(value) !== offset || viewLength.call(value) < length) throw new TypeError("hexdump input extent changed during admission");
|
|
447
|
-
this.chunk = new Uint8Array(new Uint8Array(buffer, offset, length));
|
|
448
|
-
} catch (error) {
|
|
449
|
-
budget.retain(-length);
|
|
450
|
-
throw error;
|
|
451
|
-
}
|
|
452
|
-
if (!this.chunk.length) budget.check(++this.empties, budget.limits.maxEmptyChunks, "empty input chunks");
|
|
453
|
-
}
|
|
454
|
-
return this.chunk[this.offset++];
|
|
455
|
-
}
|
|
456
|
-
};
|
|
457
|
-
function fsDetail(error) {
|
|
458
|
-
const details = {
|
|
459
|
-
EACCES: "Permission denied",
|
|
460
|
-
EPERM: "Operation not permitted",
|
|
461
|
-
ENOENT: "No such file or directory",
|
|
462
|
-
EISDIR: "Is a directory",
|
|
463
|
-
ENOTDIR: "Not a directory",
|
|
464
|
-
EIO: "Input/output error",
|
|
465
|
-
ELOOP: "Too many levels of symbolic links",
|
|
466
|
-
ENAMETOOLONG: "File name too long",
|
|
467
|
-
ENOTSUP: "Operation not supported"
|
|
468
|
-
};
|
|
469
|
-
return details[error.code] ?? error.message;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
// packages/safe-bash-command-hexdump/src/options.ts
|
|
473
|
-
init_platform();
|
|
474
|
-
var usage = "usage: hexdump [-bcCdovx] [-e fmt] [-f fmt_file] [-n length]\n [-s skip] [file ...]\n hd [-bcdovx] [-e fmt] [-f fmt_file] [-n length]\n [-s skip] [file ...]";
|
|
475
|
-
function number(text, skip, dialect) {
|
|
476
|
-
let offset = 0;
|
|
477
|
-
while (offset < text.length && " \n\r\v\f".includes(text[offset])) offset++;
|
|
478
|
-
const negative = text[offset] === "-";
|
|
479
|
-
if (negative || text[offset] === "+") offset++;
|
|
480
|
-
let base = 10;
|
|
481
|
-
if ((skip || dialect === "util-linux") && text[offset] === "0") {
|
|
482
|
-
base = 8;
|
|
483
|
-
if ((text[offset + 1] === "x" || text[offset + 1] === "X") && "0123456789abcdef".includes((text[offset + 2] ?? "!").toLowerCase())) {
|
|
484
|
-
base = 16;
|
|
485
|
-
offset += 2;
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
let value = 0;
|
|
489
|
-
const start = offset;
|
|
490
|
-
for (; offset < text.length; offset++) {
|
|
491
|
-
const digit = "0123456789abcdef".indexOf(text[offset].toLowerCase());
|
|
492
|
-
if (digit < 0 || digit >= base) break;
|
|
493
|
-
value = value * base + digit;
|
|
494
|
-
if (!Number.isSafeInteger(value)) throw new HexdumpError(`${text}: numeric value exceeds safe integer range`);
|
|
495
|
-
}
|
|
496
|
-
if (negative && value !== 0) throw new HexdumpError(`${text}: bad ${skip ? "skip" : "length"} value`);
|
|
497
|
-
if (dialect === "util-linux") {
|
|
498
|
-
const suffix = text.slice(offset);
|
|
499
|
-
let multiplier = suffix === "b" ? 512 : 1;
|
|
500
|
-
if (suffix !== "" && suffix !== "b") {
|
|
501
|
-
const power = "KMGTPEZY".indexOf(suffix[0] === "k" ? "K" : suffix[0]) + 1;
|
|
502
|
-
const tail = suffix.slice(1);
|
|
503
|
-
if (!power || tail !== "" && tail !== "B" && tail !== "iB") throw new HexdumpError(`${text}: bad ${skip ? "skip" : "length"} value`);
|
|
504
|
-
multiplier = (tail === "B" ? 1e3 : 1024) ** power;
|
|
505
|
-
}
|
|
506
|
-
if (offset === start || negative) throw new HexdumpError(`${text}: bad ${skip ? "skip" : "length"} value`);
|
|
507
|
-
value *= multiplier;
|
|
508
|
-
} else if (skip) value *= { b: 512, k: 1024, m: 1048576 }[text[offset] ?? ""] ?? 1;
|
|
509
|
-
if (!Number.isSafeInteger(value)) throw new HexdumpError(`${text}: numeric value exceeds safe integer range`);
|
|
510
|
-
return value;
|
|
511
|
-
}
|
|
512
|
-
function parse(budget, name, dialect) {
|
|
513
|
-
const args = budget.arguments();
|
|
514
|
-
const files = [];
|
|
515
|
-
const formats = name === "hd" ? ["C"] : [];
|
|
516
|
-
let verbose = false, ended = false, skip = 0, count = Infinity;
|
|
517
|
-
for (let index = 0; index < args.length; index++) {
|
|
518
|
-
const argument = args[index];
|
|
519
|
-
if (!ended && argument === "--") {
|
|
520
|
-
ended = true;
|
|
521
|
-
continue;
|
|
522
|
-
}
|
|
523
|
-
if (ended || argument === "-" || !argument.startsWith("-")) {
|
|
524
|
-
files.push(argument);
|
|
525
|
-
if (budget.context.env.POSIXLY_CORRECT !== void 0) ended = true;
|
|
526
|
-
continue;
|
|
527
|
-
}
|
|
528
|
-
for (let offset = 1; offset < argument.length; offset++) {
|
|
529
|
-
budget.charge();
|
|
530
|
-
const flag = argument[offset];
|
|
531
|
-
if (flag === "v") verbose = true;
|
|
532
|
-
else if (flag === "C" || flag === "b" || flag === "c" || flag === "d" || flag === "o" || flag === "x") {
|
|
533
|
-
if (name === "hd" && flag === "C") throw new HexdumpError(usage, true);
|
|
534
|
-
budget.check(formats.length + 1, budget.limits.maxFormats, "format count");
|
|
535
|
-
formats.push(flag);
|
|
536
|
-
} else if (flag === "n" || flag === "s") {
|
|
537
|
-
const parameter = argument.slice(offset + 1) || args[++index];
|
|
538
|
-
if (parameter === void 0) throw new HexdumpError(`${name}: option requires an argument -- '${flag}'
|
|
539
|
-
${usage}`, true);
|
|
540
|
-
if (flag === "n") count = number(parameter, false, dialect);
|
|
541
|
-
else skip = number(parameter, true, dialect);
|
|
542
|
-
break;
|
|
543
|
-
} else if (flag === "e" || flag === "f") throw new HexdumpError(`-${flag}: custom formats are not supported`);
|
|
544
|
-
else throw new HexdumpError(`unsupported option -- '${flag}'`);
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
return { files, formats: formats.length ? formats : ["default"], verbose, skip, count, dialect };
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
// packages/safe-bash-command-hexdump/src/format.ts
|
|
551
|
-
init_platform();
|
|
552
|
-
var HEX_BYTE = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
|
553
|
-
var ASCII_CHAR = Array.from({ length: 256 }, (_, i) => i >= 32 && i <= 126 ? String.fromCharCode(i) : ".");
|
|
554
|
-
function formatBlock(block, used, address, format) {
|
|
555
|
-
const canonical = format === "C";
|
|
556
|
-
if (canonical && used === 16) {
|
|
557
|
-
const b0 = block[0], b1 = block[1], b2 = block[2], b3 = block[3];
|
|
558
|
-
const b4 = block[4], b5 = block[5], b6 = block[6], b7 = block[7];
|
|
559
|
-
const b8 = block[8], b9 = block[9], b10 = block[10], b11 = block[11];
|
|
560
|
-
const b12 = block[12], b13 = block[13], b14 = block[14], b15 = block[15];
|
|
561
|
-
return `${address.toString(16).padStart(8, "0")} ${HEX_BYTE[b0]} ${HEX_BYTE[b1]} ${HEX_BYTE[b2]} ${HEX_BYTE[b3]} ${HEX_BYTE[b4]} ${HEX_BYTE[b5]} ${HEX_BYTE[b6]} ${HEX_BYTE[b7]} ${HEX_BYTE[b8]} ${HEX_BYTE[b9]} ${HEX_BYTE[b10]} ${HEX_BYTE[b11]} ${HEX_BYTE[b12]} ${HEX_BYTE[b13]} ${HEX_BYTE[b14]} ${HEX_BYTE[b15]} |${ASCII_CHAR[b0]}${ASCII_CHAR[b1]}${ASCII_CHAR[b2]}${ASCII_CHAR[b3]}${ASCII_CHAR[b4]}${ASCII_CHAR[b5]}${ASCII_CHAR[b6]}${ASCII_CHAR[b7]}${ASCII_CHAR[b8]}${ASCII_CHAR[b9]}${ASCII_CHAR[b10]}${ASCII_CHAR[b11]}${ASCII_CHAR[b12]}${ASCII_CHAR[b13]}${ASCII_CHAR[b14]}${ASCII_CHAR[b15]}|
|
|
562
|
-
`;
|
|
563
|
-
}
|
|
564
|
-
let result = address.toString(16).padStart(canonical ? 8 : 7, "0") + (canonical ? " " : " ");
|
|
565
|
-
if (canonical) {
|
|
566
|
-
for (let index = 0; index < 16; index++) {
|
|
567
|
-
if (index === 8) result += " ";
|
|
568
|
-
result += index < used ? HEX_BYTE[block[index]] : " ";
|
|
569
|
-
if (index !== 15) result += " ";
|
|
570
|
-
}
|
|
571
|
-
result += " |";
|
|
572
|
-
for (let index = 0; index < used; index++) {
|
|
573
|
-
result += ASCII_CHAR[block[index]];
|
|
574
|
-
}
|
|
575
|
-
return result + "|\n";
|
|
576
|
-
}
|
|
577
|
-
if (format !== "default") {
|
|
578
|
-
const byteFormat = format === "b" || format === "c";
|
|
579
|
-
const stride = byteFormat ? 1 : 2;
|
|
580
|
-
const width = byteFormat ? 3 : 7;
|
|
581
|
-
const escapes = { 0: "\\0", 7: "\\a", 8: "\\b", 9: "\\t", 10: "\\n", 11: "\\v", 12: "\\f", 13: "\\r" };
|
|
582
|
-
for (let index = 0; index < 16; index += stride) {
|
|
583
|
-
let field = "";
|
|
584
|
-
if (index < used) {
|
|
585
|
-
const byte = block[index];
|
|
586
|
-
if (format === "c") field = escapes[byte] ?? (byte >= 32 && byte <= 126 ? String.fromCharCode(byte) : byte.toString(8).padStart(3, "0"));
|
|
587
|
-
else if (format === "b") field = byte.toString(8).padStart(3, "0");
|
|
588
|
-
else {
|
|
589
|
-
const word = byte + (index + 1 < used ? block[index + 1] * 256 : 0);
|
|
590
|
-
field = word.toString(format === "d" ? 10 : format === "o" ? 8 : 16).padStart(format === "d" ? 5 : format === "o" ? 6 : 4, "0");
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
result += field.padStart(width, " ") + (index + stride < 16 ? " " : "");
|
|
594
|
-
}
|
|
595
|
-
return result + "\n";
|
|
596
|
-
}
|
|
597
|
-
for (let index = 0; index < 16; index += 2) {
|
|
598
|
-
result += index < used ? (block[index] + (index + 1 < used ? block[index + 1] * 256 : 0)).toString(16).padStart(4, "0") : " ";
|
|
599
|
-
if (index !== 14) result += " ";
|
|
600
|
-
}
|
|
601
|
-
return result + "\n";
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
// packages/safe-bash-command-hexdump/src/command.ts
|
|
605
|
-
async function dump(options, lifecycle, name) {
|
|
606
|
-
if (options.count === 0) return 0;
|
|
607
|
-
const { budget } = lifecycle;
|
|
608
|
-
budget.retain(32);
|
|
609
|
-
const block = new Uint8Array(16), previous = new Uint8Array(16);
|
|
610
|
-
let address = 0, used = 0, skip = options.skip, count = options.count;
|
|
611
|
-
let hasPrevious = false, squeezed = false, exitCode = 0;
|
|
612
|
-
let firstWrite = true, outBuf = "";
|
|
613
|
-
let currentReader;
|
|
614
|
-
const unlimitedFast = budget.limits.maxOutputBytes === Infinity && budget.limits.maxBufferedBytes === Infinity && budget.limits.maxWork === Infinity;
|
|
615
|
-
const flushOut = async () => {
|
|
616
|
-
if (outBuf) {
|
|
617
|
-
const chunk = outBuf;
|
|
618
|
-
outBuf = "";
|
|
619
|
-
await lifecycle.write(chunk);
|
|
620
|
-
}
|
|
621
|
-
};
|
|
622
|
-
const writeOut = (text) => {
|
|
623
|
-
if (!unlimitedFast || firstWrite || !currentReader?.hasBufferedBytes()) {
|
|
624
|
-
firstWrite = false;
|
|
625
|
-
return flushOut().then(() => lifecycle.write(text));
|
|
626
|
-
}
|
|
627
|
-
outBuf += text;
|
|
628
|
-
if (outBuf.length >= 16384) return flushOut();
|
|
629
|
-
};
|
|
630
|
-
const emitAsync = async () => {
|
|
631
|
-
for (const format of options.formats) {
|
|
632
|
-
budget.charge(16);
|
|
633
|
-
const cp = budget.checkpointWork();
|
|
634
|
-
if (cp) {
|
|
635
|
-
await flushOut();
|
|
636
|
-
await cp;
|
|
637
|
-
}
|
|
638
|
-
const w = writeOut(formatBlock(block, used, address, format));
|
|
639
|
-
if (w) await w;
|
|
640
|
-
}
|
|
641
|
-
previous.set(block);
|
|
642
|
-
hasPrevious = true;
|
|
643
|
-
squeezed = false;
|
|
644
|
-
address += used;
|
|
645
|
-
used = 0;
|
|
646
|
-
};
|
|
647
|
-
const emit = () => {
|
|
648
|
-
let same = hasPrevious && (options.dialect !== "util-linux" || used === 16);
|
|
649
|
-
for (let index = 0; same && index < used; index++) if (block[index] !== previous[index]) same = false;
|
|
650
|
-
budget.charge(used);
|
|
651
|
-
if (!options.verbose && same) {
|
|
652
|
-
let p = void 0;
|
|
653
|
-
if (!squeezed) p = writeOut("*\n");
|
|
654
|
-
squeezed = true;
|
|
655
|
-
address += used;
|
|
656
|
-
used = 0;
|
|
657
|
-
return p;
|
|
658
|
-
}
|
|
659
|
-
if (options.formats.length === 1 && unlimitedFast && !firstWrite && currentReader?.hasBufferedBytes()) {
|
|
660
|
-
budget.charge(16);
|
|
661
|
-
const cp = budget.checkpointWork();
|
|
662
|
-
if (!cp) {
|
|
663
|
-
outBuf += formatBlock(block, used, address, options.formats[0]);
|
|
664
|
-
previous.set(block);
|
|
665
|
-
hasPrevious = true;
|
|
666
|
-
squeezed = false;
|
|
667
|
-
address += used;
|
|
668
|
-
used = 0;
|
|
669
|
-
if (outBuf.length >= 16384) return flushOut();
|
|
670
|
-
return;
|
|
671
|
-
}
|
|
672
|
-
return flushOut().then(() => cp).then(() => {
|
|
673
|
-
const w = writeOut(formatBlock(block, used, address, options.formats[0]));
|
|
674
|
-
previous.set(block);
|
|
675
|
-
hasPrevious = true;
|
|
676
|
-
squeezed = false;
|
|
677
|
-
address += used;
|
|
678
|
-
used = 0;
|
|
679
|
-
return w;
|
|
680
|
-
});
|
|
681
|
-
}
|
|
682
|
-
return emitAsync();
|
|
683
|
-
};
|
|
684
|
-
for (const file of options.files.length ? options.files : [void 0]) {
|
|
685
|
-
if (count === 0) break;
|
|
686
|
-
const reader = new Reader(file, lifecycle);
|
|
687
|
-
currentReader = reader;
|
|
688
|
-
let opened = true;
|
|
689
|
-
try {
|
|
690
|
-
await reader.open();
|
|
691
|
-
} catch (error) {
|
|
692
|
-
budget.signal.throwIfAborted();
|
|
693
|
-
if (!(error instanceof FsError2)) throw error;
|
|
694
|
-
opened = false;
|
|
695
|
-
if (error.code !== "EISDIR") exitCode = 1;
|
|
696
|
-
await lifecycle.write(`${name}: ${file ?? "stdin"}: ${fsDetail(error)}
|
|
697
|
-
`, true);
|
|
698
|
-
}
|
|
699
|
-
if (opened) {
|
|
700
|
-
while (count > 0) {
|
|
701
|
-
if (skip === 0 && used === 0 && count >= 16 && reader.hasBufferedBytes()) {
|
|
702
|
-
const cp = budget.checkpointWork();
|
|
703
|
-
if (cp) await cp;
|
|
704
|
-
if (reader.canReadBlockSync(16)) {
|
|
705
|
-
reader.readBlockSync(block, 16);
|
|
706
|
-
used = 16;
|
|
707
|
-
count -= 16;
|
|
708
|
-
const p = emit();
|
|
709
|
-
if (p) await p;
|
|
710
|
-
continue;
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
if (skip === 0 && used === 0 && count >= 16 && reader.canReadBlockSync(16)) {
|
|
714
|
-
reader.readBlockSync(block, 16);
|
|
715
|
-
used = 16;
|
|
716
|
-
count -= 16;
|
|
717
|
-
const p = emit();
|
|
718
|
-
if (p) await p;
|
|
719
|
-
continue;
|
|
720
|
-
}
|
|
721
|
-
let byte;
|
|
722
|
-
try {
|
|
723
|
-
const b = reader.get();
|
|
724
|
-
byte = typeof b === "number" ? b : await b;
|
|
725
|
-
} catch (error) {
|
|
726
|
-
budget.signal.throwIfAborted();
|
|
727
|
-
if (!(error instanceof FsError2)) throw error;
|
|
728
|
-
if (error.code !== "EISDIR") exitCode = 1;
|
|
729
|
-
await lifecycle.write(`${name}: ${file ?? "stdin"}: ${fsDetail(error)}
|
|
730
|
-
`, true);
|
|
731
|
-
break;
|
|
732
|
-
}
|
|
733
|
-
if (byte < 0) break;
|
|
734
|
-
if (skip > 0) {
|
|
735
|
-
skip--;
|
|
736
|
-
address++;
|
|
737
|
-
continue;
|
|
738
|
-
}
|
|
739
|
-
block[used++] = byte;
|
|
740
|
-
count--;
|
|
741
|
-
if (used === 16) {
|
|
742
|
-
const p = emit();
|
|
743
|
-
if (p) await p;
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
await flushOut();
|
|
748
|
-
currentReader = void 0;
|
|
749
|
-
await lifecycle.operation(() => reader.close());
|
|
750
|
-
}
|
|
751
|
-
if (used) {
|
|
752
|
-
const p = emit();
|
|
753
|
-
if (p) await p;
|
|
754
|
-
}
|
|
755
|
-
await flushOut();
|
|
756
|
-
if (address > 0) await lifecycle.write(address.toString(16).padStart(options.formats.at(-1) === "C" ? 8 : 7, "0") + "\n");
|
|
757
|
-
return exitCode;
|
|
758
|
-
}
|
|
759
|
-
async function execute(context, name, limits, dialect) {
|
|
760
|
-
let lifecycle;
|
|
761
|
-
const caller = context.signal;
|
|
762
|
-
caller.throwIfAborted();
|
|
763
|
-
const stdout = context.stdout;
|
|
764
|
-
caller.throwIfAborted();
|
|
765
|
-
const capability = stdout.ownedOutput;
|
|
766
|
-
caller.throwIfAborted();
|
|
767
|
-
const consumer = capability?.consumerClosed;
|
|
768
|
-
caller.throwIfAborted();
|
|
769
|
-
consumer?.throwIfAborted();
|
|
770
|
-
const failureHandler = stdout[outputFailure];
|
|
771
|
-
caller.throwIfAborted();
|
|
772
|
-
consumer?.throwIfAborted();
|
|
773
|
-
const registerCleanup = context.registerCleanup;
|
|
774
|
-
caller.throwIfAborted();
|
|
775
|
-
consumer?.throwIfAborted();
|
|
776
|
-
const destination = capability ?? stdout;
|
|
777
|
-
const write = async (value) => {
|
|
778
|
-
lifecycle.assertOpen();
|
|
779
|
-
const method = destination.write;
|
|
780
|
-
lifecycle.assertOpen();
|
|
781
|
-
await Reflect.apply(method, destination, [value]);
|
|
782
|
-
};
|
|
783
|
-
const captured = {
|
|
784
|
-
write,
|
|
785
|
-
...capability ? { ownedOutput: { consumerClosed: consumer, write } } : {},
|
|
786
|
-
...failureHandler ? { [outputFailure]: failureHandler } : {}
|
|
787
|
-
};
|
|
788
|
-
const admission = { closed: false };
|
|
789
|
-
const output = createOutputOperation({ signal: caller, ...registerCleanup ? { registerCleanup(cleanup) {
|
|
790
|
-
caller.throwIfAborted();
|
|
791
|
-
Reflect.apply(registerCleanup, context, [() => {
|
|
792
|
-
admission.closed = true;
|
|
793
|
-
return cleanup();
|
|
794
|
-
}]);
|
|
795
|
-
} } : {} }, captured);
|
|
796
|
-
const budget = new Budget(context, limits, output.signal, caller, admission);
|
|
797
|
-
let failure;
|
|
798
|
-
let primary;
|
|
799
|
-
let exitCode = 0;
|
|
800
|
-
try {
|
|
801
|
-
lifecycle = new Lifecycle(budget, output, captured, caller);
|
|
802
|
-
exitCode = await dump(parse(budget, name, dialect), lifecycle, name);
|
|
803
|
-
} catch (error) {
|
|
804
|
-
primary = { reason: error };
|
|
805
|
-
if (error instanceof HexdumpError && !output.signal.aborted && lifecycle) {
|
|
806
|
-
exitCode = 1;
|
|
807
|
-
try {
|
|
808
|
-
await lifecycle.write(`${error.bare ? "" : name + ": "}${error.message}
|
|
809
|
-
`, true);
|
|
810
|
-
} catch (reporting) {
|
|
811
|
-
failure = { reason: new AggregateError([error, reporting], "hexdump failure reporting failed") };
|
|
812
|
-
}
|
|
813
|
-
} else failure = { reason: error };
|
|
814
|
-
}
|
|
815
|
-
try {
|
|
816
|
-
await output.close();
|
|
817
|
-
} catch (cleanup) {
|
|
818
|
-
const previous = failure ?? primary;
|
|
819
|
-
failure = { reason: previous ? new AggregateError([previous.reason, cleanup], "hexdump execution and cleanup failed") : cleanup };
|
|
820
|
-
}
|
|
821
|
-
caller.throwIfAborted();
|
|
822
|
-
output.signal.throwIfAborted();
|
|
823
|
-
if (lifecycle?.diagnosticCancellation) throw lifecycle.diagnosticCancellation.reason;
|
|
824
|
-
if (failure) throw failure.reason;
|
|
825
|
-
return { exitCode };
|
|
826
|
-
}
|
|
827
|
-
function createHexdumpCommand(options = {}) {
|
|
828
|
-
const limits = settings(options);
|
|
829
|
-
const dialect = options.dialect;
|
|
830
|
-
return {
|
|
831
|
-
name: "hexdump",
|
|
832
|
-
description: "Display bytes as hexadecimal words or canonical hex and ASCII",
|
|
833
|
-
execute: (context) => execute(context, "hexdump", limits, dialect)
|
|
834
|
-
};
|
|
835
|
-
}
|
|
836
|
-
function createHdCommand(options = {}) {
|
|
837
|
-
const limits = settings(options);
|
|
838
|
-
const dialect = options.dialect;
|
|
839
|
-
return {
|
|
840
|
-
name: "hd",
|
|
841
|
-
description: "Display canonical hexadecimal and ASCII bytes",
|
|
842
|
-
execute: (context) => execute(context, "hd", limits, dialect)
|
|
843
|
-
};
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
// packages/safe-bash-command-hexdump/src/index.ts
|
|
847
|
-
function createHexdumpCommand2(options = {}) {
|
|
848
|
-
const def = createHexdumpCommand(options);
|
|
849
|
-
builtInDirectContextExecutors.add(def.execute);
|
|
850
|
-
return def;
|
|
851
|
-
}
|
|
852
|
-
function createHdCommand2(options = {}) {
|
|
853
|
-
const def = createHdCommand(options);
|
|
854
|
-
builtInDirectContextExecutors.add(def.execute);
|
|
855
|
-
return def;
|
|
856
|
-
}
|
|
857
|
-
function createHexdumpCommands(options = {}) {
|
|
858
|
-
return [createHexdumpCommand2(options), createHdCommand2(options)];
|
|
859
|
-
}
|
|
860
|
-
function hexdumpCommands(options = {}) {
|
|
861
|
-
const commands = createHexdumpCommands(options);
|
|
862
|
-
return { name: "hexdump-commands", setup(host) {
|
|
863
|
-
if (!options.replace) {
|
|
864
|
-
for (const command of commands) if (host.commands.has(command.name)) throw new Error(`Command already registered: ${command.name}`);
|
|
865
|
-
}
|
|
866
|
-
for (const command of commands) host.commands.register(command, { replace: options.replace ?? false });
|
|
867
|
-
} };
|
|
868
|
-
}
|
|
869
|
-
|
|
870
|
-
export {
|
|
871
|
-
createHexdumpCommand2 as createHexdumpCommand,
|
|
872
|
-
createHdCommand2 as createHdCommand,
|
|
873
|
-
createHexdumpCommands,
|
|
874
|
-
hexdumpCommands
|
|
875
|
-
};
|
|
876
|
-
//# sourceMappingURL=chunk-4E3SGG37.js.map
|