poe-code 15.0.14 → 15.0.16
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/metafile.json +1 -1
- package/package.json +13 -1
- package/packages/safe-bash/dist/chunks/{chunk-GZKLXMBM.js → chunk-5VBLSPNM.js} +6 -1
- package/packages/safe-bash/dist/chunks/{chunk-GZKLXMBM.js.map → chunk-5VBLSPNM.js.map} +2 -2
- package/packages/safe-bash/dist/chunks/{chunk-DJHZJAB7.js → chunk-66VSWIUC.js} +3 -3
- package/packages/safe-bash/dist/chunks/{chunk-PPPN3OME.js → chunk-6PSMEBVP.js} +2 -2
- package/packages/safe-bash/dist/chunks/chunk-A4UXQKWZ.js +2609 -0
- package/packages/safe-bash/dist/chunks/chunk-A4UXQKWZ.js.map +7 -0
- package/packages/safe-bash/dist/chunks/{chunk-32GGX4AS.js → chunk-AZNI263O.js} +3 -3
- package/packages/safe-bash/dist/chunks/{chunk-LRVRQIG5.js → chunk-EZLQA6ON.js} +3 -3
- package/packages/safe-bash/dist/chunks/{chunk-ZQEL7DYC.js → chunk-HFEU5SBQ.js} +4 -4
- package/packages/safe-bash/dist/chunks/{chunk-EYJTLUBJ.js → chunk-PZMJ4EC3.js} +2 -2
- package/packages/safe-bash/dist/chunks/chunk-R3QJL5HH.js +698 -0
- package/packages/safe-bash/dist/chunks/chunk-R3QJL5HH.js.map +7 -0
- package/packages/safe-bash/dist/chunks/{chunk-J4CKSMJV.js → chunk-T5BV7HPD.js} +2 -2
- package/packages/safe-bash/dist/chunks/{chunk-IIWXPQB3.js → chunk-TPD45VUZ.js} +5 -5
- package/packages/safe-bash/dist/chunks/{chunk-UGMO7OO5.js → chunk-VNDFKT6F.js} +3 -3
- package/packages/safe-bash/dist/chunks/{chunk-LZUOZVGJ.js → chunk-WF4P7XKI.js} +3 -3
- package/packages/safe-bash/dist/chunks/{chunk-Z75O7XWR.js → chunk-WODV2DVM.js} +3 -3
- package/packages/safe-bash/dist/chunks/{chunk-QKQNBJOU.js → chunk-YEJBZLE5.js} +5 -5
- package/packages/safe-bash/dist/commands/bytes/compression/file-operation.d.ts +16 -0
- package/packages/safe-bash/dist/commands/bytes/compression/file-operation.d.ts.map +1 -0
- package/packages/safe-bash/dist/commands/bytes/compression/file-operation.js +134 -0
- package/packages/safe-bash/dist/commands/bytes/compression/file-operation.js.map +1 -0
- package/packages/safe-bash/dist/commands/bytes/compression/files.d.ts.map +1 -1
- package/packages/safe-bash/dist/commands/bytes/compression/files.js +126 -67
- package/packages/safe-bash/dist/commands/bytes/compression/files.js.map +1 -1
- package/packages/safe-bash/dist/commands/bytes/compression/stream.d.ts.map +1 -1
- package/packages/safe-bash/dist/commands/bytes/compression/stream.js +2 -1
- package/packages/safe-bash/dist/commands/bytes/compression/stream.js.map +1 -1
- package/packages/safe-bash/dist/commands/csplit/index.browser.js +4 -4
- package/packages/safe-bash/dist/commands/factor/index.browser.js +3 -3
- package/packages/safe-bash/dist/commands/getopt/index.browser.js +3 -3
- package/packages/safe-bash/dist/commands/hexdump/command.d.ts +5 -0
- package/packages/safe-bash/dist/commands/hexdump/command.d.ts.map +1 -0
- package/packages/safe-bash/dist/commands/hexdump/command.js +174 -0
- package/packages/safe-bash/dist/commands/hexdump/command.js.map +1 -0
- package/packages/safe-bash/dist/commands/hexdump/format.d.ts +2 -0
- package/packages/safe-bash/dist/commands/hexdump/format.d.ts.map +1 -0
- package/packages/safe-bash/dist/commands/hexdump/format.js +25 -0
- package/packages/safe-bash/dist/commands/hexdump/format.js.map +1 -0
- package/packages/safe-bash/dist/commands/hexdump/index.browser.js +17 -0
- package/packages/safe-bash/dist/commands/hexdump/index.browser.js.map +7 -0
- package/packages/safe-bash/dist/commands/hexdump/index.d.ts +7 -0
- package/packages/safe-bash/dist/commands/hexdump/index.d.ts.map +1 -0
- package/packages/safe-bash/dist/commands/hexdump/index.js +17 -0
- package/packages/safe-bash/dist/commands/hexdump/index.js.map +1 -0
- package/packages/safe-bash/dist/commands/hexdump/internal.d.ts +52 -0
- package/packages/safe-bash/dist/commands/hexdump/internal.d.ts.map +1 -0
- package/packages/safe-bash/dist/commands/hexdump/internal.js +150 -0
- package/packages/safe-bash/dist/commands/hexdump/internal.js.map +1 -0
- package/packages/safe-bash/dist/commands/hexdump/io.d.ts +41 -0
- package/packages/safe-bash/dist/commands/hexdump/io.d.ts.map +1 -0
- package/packages/safe-bash/dist/commands/hexdump/io.js +288 -0
- package/packages/safe-bash/dist/commands/hexdump/io.js.map +1 -0
- package/packages/safe-bash/dist/commands/hexdump/options.d.ts +10 -0
- package/packages/safe-bash/dist/commands/hexdump/options.d.ts.map +1 -0
- package/packages/safe-bash/dist/commands/hexdump/options.js +80 -0
- package/packages/safe-bash/dist/commands/hexdump/options.js.map +1 -0
- package/packages/safe-bash/dist/commands/iconv/codec.d.ts +10 -0
- package/packages/safe-bash/dist/commands/iconv/codec.d.ts.map +1 -0
- package/packages/safe-bash/dist/commands/iconv/codec.js +200 -0
- package/packages/safe-bash/dist/commands/iconv/codec.js.map +1 -0
- package/packages/safe-bash/dist/commands/iconv/command.d.ts +4 -0
- package/packages/safe-bash/dist/commands/iconv/command.d.ts.map +1 -0
- package/packages/safe-bash/dist/commands/iconv/command.js +116 -0
- package/packages/safe-bash/dist/commands/iconv/command.js.map +1 -0
- package/packages/safe-bash/dist/commands/iconv/index.browser.js +15 -0
- package/packages/safe-bash/dist/commands/iconv/index.browser.js.map +7 -0
- package/packages/safe-bash/dist/commands/iconv/index.d.ts +7 -0
- package/packages/safe-bash/dist/commands/iconv/index.d.ts.map +1 -0
- package/packages/safe-bash/dist/commands/iconv/index.js +11 -0
- package/packages/safe-bash/dist/commands/iconv/index.js.map +1 -0
- package/packages/safe-bash/dist/commands/iconv/internal.d.ts +54 -0
- package/packages/safe-bash/dist/commands/iconv/internal.d.ts.map +1 -0
- package/packages/safe-bash/dist/commands/iconv/internal.js +154 -0
- package/packages/safe-bash/dist/commands/iconv/internal.js.map +1 -0
- package/packages/safe-bash/dist/commands/iconv/lifecycle.d.ts +24 -0
- package/packages/safe-bash/dist/commands/iconv/lifecycle.d.ts.map +1 -0
- package/packages/safe-bash/dist/commands/iconv/lifecycle.js +111 -0
- package/packages/safe-bash/dist/commands/iconv/lifecycle.js.map +1 -0
- package/packages/safe-bash/dist/commands/iconv/options.d.ts +11 -0
- package/packages/safe-bash/dist/commands/iconv/options.d.ts.map +1 -0
- package/packages/safe-bash/dist/commands/iconv/options.js +82 -0
- package/packages/safe-bash/dist/commands/iconv/options.js.map +1 -0
- package/packages/safe-bash/dist/commands/iconv/reader.d.ts +21 -0
- package/packages/safe-bash/dist/commands/iconv/reader.d.ts.map +1 -0
- package/packages/safe-bash/dist/commands/iconv/reader.js +192 -0
- package/packages/safe-bash/dist/commands/iconv/reader.js.map +1 -0
- package/packages/safe-bash/dist/commands/iconv/transliterations.d.ts +2 -0
- package/packages/safe-bash/dist/commands/iconv/transliterations.d.ts.map +1 -0
- package/packages/safe-bash/dist/commands/iconv/transliterations.js +1785 -0
- package/packages/safe-bash/dist/commands/iconv/transliterations.js.map +1 -0
- package/packages/safe-bash/dist/commands/network/index.browser.js +5 -5
- package/packages/safe-bash/dist/commands/pr/index.browser.js +3 -3
- package/packages/safe-bash/dist/commands/tsort/index.browser.js +3 -3
- package/packages/safe-bash/dist/commands/xml/index.browser.js +4 -4
- package/packages/safe-bash/dist/commands/yq/index.browser.js +5 -5
- package/packages/safe-bash/dist/contracts/yield.d.ts +1 -0
- package/packages/safe-bash/dist/contracts/yield.d.ts.map +1 -1
- package/packages/safe-bash/dist/contracts/yield.js +5 -0
- package/packages/safe-bash/dist/contracts/yield.js.map +1 -1
- package/packages/safe-bash/dist/core.browser.js +297 -79
- package/packages/safe-bash/dist/core.browser.js.map +4 -4
- package/packages/safe-bash/dist/core.d.ts +2 -0
- package/packages/safe-bash/dist/core.d.ts.map +1 -1
- package/packages/safe-bash/dist/core.js +2 -0
- package/packages/safe-bash/dist/core.js.map +1 -1
- package/packages/safe-bash/dist/plugins/composition.d.ts +4 -0
- package/packages/safe-bash/dist/plugins/composition.d.ts.map +1 -1
- package/packages/safe-bash/dist/plugins/composition.js +5 -1
- package/packages/safe-bash/dist/plugins/composition.js.map +1 -1
- /package/packages/safe-bash/dist/chunks/{chunk-DJHZJAB7.js.map → chunk-66VSWIUC.js.map} +0 -0
- /package/packages/safe-bash/dist/chunks/{chunk-PPPN3OME.js.map → chunk-6PSMEBVP.js.map} +0 -0
- /package/packages/safe-bash/dist/chunks/{chunk-32GGX4AS.js.map → chunk-AZNI263O.js.map} +0 -0
- /package/packages/safe-bash/dist/chunks/{chunk-LRVRQIG5.js.map → chunk-EZLQA6ON.js.map} +0 -0
- /package/packages/safe-bash/dist/chunks/{chunk-ZQEL7DYC.js.map → chunk-HFEU5SBQ.js.map} +0 -0
- /package/packages/safe-bash/dist/chunks/{chunk-EYJTLUBJ.js.map → chunk-PZMJ4EC3.js.map} +0 -0
- /package/packages/safe-bash/dist/chunks/{chunk-J4CKSMJV.js.map → chunk-T5BV7HPD.js.map} +0 -0
- /package/packages/safe-bash/dist/chunks/{chunk-IIWXPQB3.js.map → chunk-TPD45VUZ.js.map} +0 -0
- /package/packages/safe-bash/dist/chunks/{chunk-UGMO7OO5.js.map → chunk-VNDFKT6F.js.map} +0 -0
- /package/packages/safe-bash/dist/chunks/{chunk-LZUOZVGJ.js.map → chunk-WF4P7XKI.js.map} +0 -0
- /package/packages/safe-bash/dist/chunks/{chunk-Z75O7XWR.js.map → chunk-WODV2DVM.js.map} +0 -0
- /package/packages/safe-bash/dist/chunks/{chunk-QKQNBJOU.js.map → chunk-YEJBZLE5.js.map} +0 -0
|
@@ -0,0 +1,698 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolvePath
|
|
3
|
+
} from "./chunk-DPJWEGIX.js";
|
|
4
|
+
import {
|
|
5
|
+
createOutputOperation
|
|
6
|
+
} from "./chunk-PZMJ4EC3.js";
|
|
7
|
+
import {
|
|
8
|
+
FsError,
|
|
9
|
+
PublicDiagnostic,
|
|
10
|
+
getCommandArguments,
|
|
11
|
+
outputFailure,
|
|
12
|
+
shellValueByteLength,
|
|
13
|
+
shellValueBytes,
|
|
14
|
+
yieldTurn
|
|
15
|
+
} from "./chunk-5VBLSPNM.js";
|
|
16
|
+
import {
|
|
17
|
+
init_platform
|
|
18
|
+
} from "./chunk-2KL6W6NB.js";
|
|
19
|
+
|
|
20
|
+
// packages/safe-bash/src/commands/hexdump/index.ts
|
|
21
|
+
init_platform();
|
|
22
|
+
|
|
23
|
+
// packages/safe-bash/src/commands/hexdump/command.ts
|
|
24
|
+
init_platform();
|
|
25
|
+
|
|
26
|
+
// packages/safe-bash/src/commands/hexdump/internal.ts
|
|
27
|
+
init_platform();
|
|
28
|
+
function settings(options) {
|
|
29
|
+
const limits = {
|
|
30
|
+
maxArguments: 4096,
|
|
31
|
+
maxArgumentBytes: 65536,
|
|
32
|
+
maxInputBytes: 33554432,
|
|
33
|
+
maxBufferedBytes: 8388608,
|
|
34
|
+
maxOutputBytes: 134217728,
|
|
35
|
+
maxDiagnosticBytes: 65536,
|
|
36
|
+
maxFormats: 64,
|
|
37
|
+
maxWork: 536870912,
|
|
38
|
+
maxEmptyChunks: 4096,
|
|
39
|
+
...options.limits
|
|
40
|
+
};
|
|
41
|
+
for (const [name, value] of Object.entries(limits)) {
|
|
42
|
+
if (!Number.isSafeInteger(value) || value < 1) throw new RangeError(`Invalid hexdump limit: ${name}`);
|
|
43
|
+
}
|
|
44
|
+
return Object.freeze(limits);
|
|
45
|
+
}
|
|
46
|
+
var HexdumpError = class extends PublicDiagnostic {
|
|
47
|
+
constructor(message, bare = false) {
|
|
48
|
+
super(message);
|
|
49
|
+
this.bare = bare;
|
|
50
|
+
}
|
|
51
|
+
bare;
|
|
52
|
+
};
|
|
53
|
+
function raw(value) {
|
|
54
|
+
let result = "";
|
|
55
|
+
for (let offset = 0; offset < value.length; offset += 4096) result += String.fromCharCode(...value.subarray(offset, offset + 4096));
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
function bytes(value) {
|
|
59
|
+
return Uint8Array.from(value, (character) => character.charCodeAt(0));
|
|
60
|
+
}
|
|
61
|
+
function pathText(value) {
|
|
62
|
+
try {
|
|
63
|
+
return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes(value));
|
|
64
|
+
} catch {
|
|
65
|
+
throw new HexdumpError("filesystem paths must be valid UTF-8");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
var Budget = class {
|
|
69
|
+
constructor(context, limits, signal, callerSignal, admission) {
|
|
70
|
+
this.context = context;
|
|
71
|
+
this.limits = limits;
|
|
72
|
+
this.signal = signal;
|
|
73
|
+
this.callerSignal = callerSignal;
|
|
74
|
+
this.admission = admission;
|
|
75
|
+
}
|
|
76
|
+
context;
|
|
77
|
+
limits;
|
|
78
|
+
signal;
|
|
79
|
+
callerSignal;
|
|
80
|
+
admission;
|
|
81
|
+
work = 0;
|
|
82
|
+
checkpoint = 0;
|
|
83
|
+
retained = 0;
|
|
84
|
+
input = 0;
|
|
85
|
+
output = 0;
|
|
86
|
+
diagnostics = 0;
|
|
87
|
+
assertOpen() {
|
|
88
|
+
this.signal.throwIfAborted();
|
|
89
|
+
if (this.admission.closed) throw new HexdumpError("command is closed");
|
|
90
|
+
}
|
|
91
|
+
check(value, maximum, label) {
|
|
92
|
+
if (!Number.isSafeInteger(value) || value < 0 || value > maximum) throw new HexdumpError(`${label} limit exceeded`);
|
|
93
|
+
}
|
|
94
|
+
charge(amount = 1) {
|
|
95
|
+
this.assertOpen();
|
|
96
|
+
this.check(this.work + amount, this.limits.maxWork, "work");
|
|
97
|
+
this.work += amount;
|
|
98
|
+
}
|
|
99
|
+
async checkpointWork() {
|
|
100
|
+
this.assertOpen();
|
|
101
|
+
if (this.work - this.checkpoint >= 4096) {
|
|
102
|
+
this.checkpoint = this.work;
|
|
103
|
+
await yieldTurn(this.callerSignal);
|
|
104
|
+
this.assertOpen();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
retain(amount) {
|
|
108
|
+
this.check(this.retained + amount, this.limits.maxBufferedBytes, "buffered bytes");
|
|
109
|
+
this.retained += amount;
|
|
110
|
+
}
|
|
111
|
+
inputBytes(amount) {
|
|
112
|
+
this.check(this.input + amount, this.limits.maxInputBytes, "input bytes");
|
|
113
|
+
this.input += amount;
|
|
114
|
+
}
|
|
115
|
+
emitted(amount, diagnostic) {
|
|
116
|
+
if (diagnostic) {
|
|
117
|
+
this.check(this.diagnostics + amount, this.limits.maxDiagnosticBytes, "diagnostic bytes");
|
|
118
|
+
this.diagnostics += amount;
|
|
119
|
+
} else {
|
|
120
|
+
this.check(this.output + amount, this.limits.maxOutputBytes, "output bytes");
|
|
121
|
+
this.charge(amount);
|
|
122
|
+
this.output += amount;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
arguments() {
|
|
126
|
+
this.assertOpen();
|
|
127
|
+
const args = this.context.args;
|
|
128
|
+
this.assertOpen();
|
|
129
|
+
const count = args.length;
|
|
130
|
+
this.assertOpen();
|
|
131
|
+
this.check(count, this.limits.maxArguments, "argument count");
|
|
132
|
+
const argumentValues = this.context.argumentValues;
|
|
133
|
+
this.assertOpen();
|
|
134
|
+
const carrier = argumentValues === void 0 ? void 0 : getCommandArguments({ args, argumentValues });
|
|
135
|
+
this.assertOpen();
|
|
136
|
+
this.retain(count * 64 + 128);
|
|
137
|
+
const snapshot = [];
|
|
138
|
+
let units = 0, total = 0;
|
|
139
|
+
for (let index = 0; index < count; index++) {
|
|
140
|
+
const argument = args[index];
|
|
141
|
+
this.assertOpen();
|
|
142
|
+
if (typeof argument !== "string") throw new HexdumpError("arguments must be strings");
|
|
143
|
+
units += argument.length;
|
|
144
|
+
this.check(units, this.limits.maxArgumentBytes, "argument bytes");
|
|
145
|
+
this.charge(argument.length + 1);
|
|
146
|
+
for (let offset = 0; offset < argument.length; offset++) {
|
|
147
|
+
const unit = argument.charCodeAt(offset);
|
|
148
|
+
if (unit >= 55296 && unit <= 56319) {
|
|
149
|
+
const next = argument.charCodeAt(++offset);
|
|
150
|
+
if (!(next >= 56320 && next <= 57343)) throw new HexdumpError("arguments must contain well-formed Unicode");
|
|
151
|
+
} else if (unit >= 56320 && unit <= 57343) throw new HexdumpError("arguments must contain well-formed Unicode");
|
|
152
|
+
}
|
|
153
|
+
const size = shellValueByteLength(carrier ? carrier.values[index] : argument);
|
|
154
|
+
total += size;
|
|
155
|
+
this.check(total, this.limits.maxArgumentBytes, "argument bytes");
|
|
156
|
+
this.charge(size);
|
|
157
|
+
this.retain(size * 8);
|
|
158
|
+
snapshot.push(argument);
|
|
159
|
+
}
|
|
160
|
+
return (carrier ?? getCommandArguments({ args: snapshot })).values.map((argument) => {
|
|
161
|
+
this.charge(shellValueByteLength(argument));
|
|
162
|
+
const value = shellValueBytes(argument);
|
|
163
|
+
if (value.includes(0)) throw new HexdumpError("NUL is not supported in arguments");
|
|
164
|
+
return raw(value);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
// packages/safe-bash/src/commands/hexdump/io.ts
|
|
170
|
+
init_platform();
|
|
171
|
+
var typedArrayPrototype = Object.getPrototypeOf(Uint8Array.prototype);
|
|
172
|
+
var viewBuffer = Object.getOwnPropertyDescriptor(typedArrayPrototype, "buffer").get;
|
|
173
|
+
var viewOffset = Object.getOwnPropertyDescriptor(typedArrayPrototype, "byteOffset").get;
|
|
174
|
+
var viewLength = Object.getOwnPropertyDescriptor(typedArrayPrototype, "byteLength").get;
|
|
175
|
+
var Lifecycle = class {
|
|
176
|
+
constructor(budget, output, stdout, caller) {
|
|
177
|
+
this.budget = budget;
|
|
178
|
+
this.stdout = stdout;
|
|
179
|
+
this.caller = caller;
|
|
180
|
+
output.registerCleanup(() => this.close());
|
|
181
|
+
}
|
|
182
|
+
budget;
|
|
183
|
+
stdout;
|
|
184
|
+
caller;
|
|
185
|
+
pending = /* @__PURE__ */ new Set();
|
|
186
|
+
cleanups = /* @__PURE__ */ new Set();
|
|
187
|
+
closing;
|
|
188
|
+
diagnostic;
|
|
189
|
+
diagnosticCancellation;
|
|
190
|
+
cleanup(action) {
|
|
191
|
+
this.assertOpen();
|
|
192
|
+
this.cleanups.add(action);
|
|
193
|
+
}
|
|
194
|
+
forget(action) {
|
|
195
|
+
this.cleanups.delete(action);
|
|
196
|
+
}
|
|
197
|
+
assertOpen() {
|
|
198
|
+
this.budget.assertOpen();
|
|
199
|
+
if (this.closing) throw new HexdumpError("command is closed");
|
|
200
|
+
}
|
|
201
|
+
assertDiagnosticOpen() {
|
|
202
|
+
this.caller.throwIfAborted();
|
|
203
|
+
const consumer = this.diagnostic?.consumer;
|
|
204
|
+
if (consumer?.aborted) {
|
|
205
|
+
this.diagnosticCancellation = { reason: consumer.reason };
|
|
206
|
+
consumer.throwIfAborted();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
async operation(action, diagnostic = false) {
|
|
210
|
+
if (diagnostic) this.assertDiagnosticOpen();
|
|
211
|
+
else this.assertOpen();
|
|
212
|
+
if (this.closing || this.budget.admission.closed) throw new HexdumpError("command is closed");
|
|
213
|
+
if (!diagnostic) this.budget.charge();
|
|
214
|
+
const pending = Promise.resolve().then(() => {
|
|
215
|
+
if (diagnostic) this.assertDiagnosticOpen();
|
|
216
|
+
else this.assertOpen();
|
|
217
|
+
return action();
|
|
218
|
+
});
|
|
219
|
+
this.pending.add(pending);
|
|
220
|
+
try {
|
|
221
|
+
const value = await pending;
|
|
222
|
+
if (diagnostic) this.assertDiagnosticOpen();
|
|
223
|
+
else this.assertOpen();
|
|
224
|
+
return value;
|
|
225
|
+
} finally {
|
|
226
|
+
this.pending.delete(pending);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
close() {
|
|
230
|
+
return this.closing ??= Promise.resolve().then(async () => {
|
|
231
|
+
while (this.pending.size) await Promise.allSettled([...this.pending]);
|
|
232
|
+
const failures = [];
|
|
233
|
+
for (const cleanup of this.cleanups) {
|
|
234
|
+
try {
|
|
235
|
+
await cleanup();
|
|
236
|
+
} catch (error) {
|
|
237
|
+
failures.push(error);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (failures.length === 1) throw failures[0];
|
|
241
|
+
if (failures.length > 1) throw new AggregateError(failures, "hexdump cleanup failed");
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
async write(value, diagnostic = false) {
|
|
245
|
+
this.budget.emitted(value.length, diagnostic);
|
|
246
|
+
await this.operation(async () => {
|
|
247
|
+
if (!diagnostic) this.budget.retain(value.length * 3);
|
|
248
|
+
try {
|
|
249
|
+
let destination;
|
|
250
|
+
if (diagnostic) {
|
|
251
|
+
if (!this.diagnostic) {
|
|
252
|
+
const sink = this.budget.context.stderr;
|
|
253
|
+
this.assertDiagnosticOpen();
|
|
254
|
+
const capability = sink.ownedOutput;
|
|
255
|
+
this.assertDiagnosticOpen();
|
|
256
|
+
const consumer = capability?.consumerClosed;
|
|
257
|
+
this.diagnostic = { destination: capability ?? sink, consumer };
|
|
258
|
+
}
|
|
259
|
+
this.assertDiagnosticOpen();
|
|
260
|
+
destination = this.diagnostic.destination;
|
|
261
|
+
} else {
|
|
262
|
+
destination = this.stdout;
|
|
263
|
+
this.assertOpen();
|
|
264
|
+
}
|
|
265
|
+
const write = destination.write;
|
|
266
|
+
if (diagnostic) this.assertDiagnosticOpen();
|
|
267
|
+
else this.assertOpen();
|
|
268
|
+
await Reflect.apply(write, destination, [bytes(value)]);
|
|
269
|
+
} finally {
|
|
270
|
+
if (!diagnostic) this.budget.retain(-value.length * 3);
|
|
271
|
+
}
|
|
272
|
+
}, diagnostic);
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
var Reader = class {
|
|
276
|
+
constructor(name, lifecycle) {
|
|
277
|
+
this.name = name;
|
|
278
|
+
this.lifecycle = lifecycle;
|
|
279
|
+
lifecycle.budget.retain(256);
|
|
280
|
+
lifecycle.cleanup(this.close);
|
|
281
|
+
}
|
|
282
|
+
name;
|
|
283
|
+
lifecycle;
|
|
284
|
+
iterator;
|
|
285
|
+
chunk = new Uint8Array();
|
|
286
|
+
offset = 0;
|
|
287
|
+
ended = false;
|
|
288
|
+
empties = 0;
|
|
289
|
+
snapshotBytes = 0;
|
|
290
|
+
closed;
|
|
291
|
+
close = () => this.closed ??= Promise.resolve().then(async () => {
|
|
292
|
+
try {
|
|
293
|
+
if (!this.ended) await this.iterator?.return?.();
|
|
294
|
+
} finally {
|
|
295
|
+
this.iterator = void 0;
|
|
296
|
+
this.releaseSnapshot();
|
|
297
|
+
this.lifecycle.budget.retain(-this.chunk.length - 256);
|
|
298
|
+
this.chunk = new Uint8Array();
|
|
299
|
+
this.lifecycle.forget(this.close);
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
releaseSnapshot = () => {
|
|
303
|
+
this.lifecycle.budget.retain(-this.snapshotBytes);
|
|
304
|
+
this.snapshotBytes = 0;
|
|
305
|
+
};
|
|
306
|
+
async open() {
|
|
307
|
+
const { budget } = this.lifecycle;
|
|
308
|
+
await this.lifecycle.operation(async () => {
|
|
309
|
+
let source;
|
|
310
|
+
let needsAcquisitionCleanup = false;
|
|
311
|
+
if (this.name === void 0) source = budget.context.stdin;
|
|
312
|
+
else {
|
|
313
|
+
if (this.name === "") throw new FsError("ENOENT", { path: this.name });
|
|
314
|
+
const cwd = budget.context.cwd;
|
|
315
|
+
this.lifecycle.assertOpen();
|
|
316
|
+
const path = resolvePath(cwd, pathText(this.name));
|
|
317
|
+
const fs = budget.context.fs;
|
|
318
|
+
this.lifecycle.assertOpen();
|
|
319
|
+
const statMethod = fs.stat;
|
|
320
|
+
this.lifecycle.assertOpen();
|
|
321
|
+
const stat = await Reflect.apply(statMethod, fs, [path, { signal: budget.signal }]);
|
|
322
|
+
this.lifecycle.assertOpen();
|
|
323
|
+
const type = stat.type;
|
|
324
|
+
this.lifecycle.assertOpen();
|
|
325
|
+
if (this.name.endsWith("/") && type !== "directory") throw new FsError("ENOTDIR", { path });
|
|
326
|
+
if (type === "directory") throw new FsError("EISDIR", { path });
|
|
327
|
+
if (type !== "file" && type !== "character") throw new FsError("ENOTSUP", { path });
|
|
328
|
+
const capabilitiesFor = fs.capabilitiesFor;
|
|
329
|
+
this.lifecycle.assertOpen();
|
|
330
|
+
const selected = capabilitiesFor ? await Reflect.apply(capabilitiesFor, fs, [path, { signal: budget.signal }]) : void 0;
|
|
331
|
+
this.lifecycle.assertOpen();
|
|
332
|
+
const capabilities = selected ?? fs.capabilities;
|
|
333
|
+
this.lifecycle.assertOpen();
|
|
334
|
+
const readStream = fs.readStream;
|
|
335
|
+
this.lifecycle.assertOpen();
|
|
336
|
+
const streamingRead = readStream && capabilities.streamingRead !== false;
|
|
337
|
+
this.lifecycle.assertOpen();
|
|
338
|
+
if (readStream && streamingRead) {
|
|
339
|
+
source = Reflect.apply(readStream, fs, [path, { signal: budget.signal, chunkSize: 16384 }]);
|
|
340
|
+
needsAcquisitionCleanup = budget.signal.aborted || budget.admission.closed;
|
|
341
|
+
} else {
|
|
342
|
+
const maximum = Math.min(budget.limits.maxInputBytes, Math.floor(budget.limits.maxBufferedBytes / 2));
|
|
343
|
+
const size = stat.size;
|
|
344
|
+
this.lifecycle.assertOpen();
|
|
345
|
+
budget.check(size, maximum, "buffered input bytes");
|
|
346
|
+
budget.retain(maximum);
|
|
347
|
+
this.snapshotBytes = maximum;
|
|
348
|
+
const readFile = fs.readFile;
|
|
349
|
+
this.lifecycle.assertOpen();
|
|
350
|
+
const content = await Reflect.apply(readFile, fs, [path, { signal: budget.signal, maxBytes: maximum }]);
|
|
351
|
+
this.lifecycle.assertOpen();
|
|
352
|
+
if (!(content instanceof Uint8Array)) throw new TypeError("hexdump input requires bytes");
|
|
353
|
+
const length = viewLength.call(content);
|
|
354
|
+
budget.check(length, maximum, "buffered input bytes");
|
|
355
|
+
budget.retain(length - maximum);
|
|
356
|
+
this.snapshotBytes = length;
|
|
357
|
+
const { releaseSnapshot } = this;
|
|
358
|
+
source = { async *[Symbol.asyncIterator]() {
|
|
359
|
+
try {
|
|
360
|
+
yield content;
|
|
361
|
+
} finally {
|
|
362
|
+
releaseSnapshot();
|
|
363
|
+
}
|
|
364
|
+
} };
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
if (!needsAcquisitionCleanup) this.lifecycle.assertOpen();
|
|
368
|
+
const factory = source[Symbol.asyncIterator];
|
|
369
|
+
if (!needsAcquisitionCleanup) this.lifecycle.assertOpen();
|
|
370
|
+
this.iterator = Reflect.apply(factory, source, []);
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
async get() {
|
|
374
|
+
const { budget } = this.lifecycle;
|
|
375
|
+
budget.charge();
|
|
376
|
+
await budget.checkpointWork();
|
|
377
|
+
while (this.offset === this.chunk.length) {
|
|
378
|
+
if (this.ended) return -1;
|
|
379
|
+
await budget.checkpointWork();
|
|
380
|
+
const next = await this.lifecycle.operation(() => {
|
|
381
|
+
const iterator = this.iterator;
|
|
382
|
+
const advance = iterator.next;
|
|
383
|
+
this.lifecycle.assertOpen();
|
|
384
|
+
return Reflect.apply(advance, iterator, []);
|
|
385
|
+
});
|
|
386
|
+
budget.retain(-this.chunk.length);
|
|
387
|
+
this.chunk = new Uint8Array();
|
|
388
|
+
this.offset = 0;
|
|
389
|
+
const done = next.done;
|
|
390
|
+
this.lifecycle.assertOpen();
|
|
391
|
+
if (done) {
|
|
392
|
+
this.ended = true;
|
|
393
|
+
this.iterator = void 0;
|
|
394
|
+
return -1;
|
|
395
|
+
}
|
|
396
|
+
const value = next.value;
|
|
397
|
+
this.lifecycle.assertOpen();
|
|
398
|
+
if (!(value instanceof Uint8Array)) throw new TypeError("hexdump input requires bytes");
|
|
399
|
+
const buffer = viewBuffer.call(value);
|
|
400
|
+
const offset = viewOffset.call(value);
|
|
401
|
+
const length = viewLength.call(value);
|
|
402
|
+
this.lifecycle.assertOpen();
|
|
403
|
+
budget.inputBytes(length);
|
|
404
|
+
budget.charge(length);
|
|
405
|
+
budget.retain(length);
|
|
406
|
+
try {
|
|
407
|
+
if (viewOffset.call(value) !== offset || viewLength.call(value) < length) throw new TypeError("hexdump input extent changed during admission");
|
|
408
|
+
this.chunk = new Uint8Array(new Uint8Array(buffer, offset, length));
|
|
409
|
+
} catch (error) {
|
|
410
|
+
budget.retain(-length);
|
|
411
|
+
throw error;
|
|
412
|
+
}
|
|
413
|
+
if (!this.chunk.length) budget.check(++this.empties, budget.limits.maxEmptyChunks, "empty input chunks");
|
|
414
|
+
}
|
|
415
|
+
return this.chunk[this.offset++];
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
function fsDetail(error) {
|
|
419
|
+
const details = {
|
|
420
|
+
EACCES: "Permission denied",
|
|
421
|
+
EPERM: "Operation not permitted",
|
|
422
|
+
ENOENT: "No such file or directory",
|
|
423
|
+
EISDIR: "Is a directory",
|
|
424
|
+
ENOTDIR: "Not a directory",
|
|
425
|
+
EIO: "Input/output error",
|
|
426
|
+
ELOOP: "Too many levels of symbolic links",
|
|
427
|
+
ENAMETOOLONG: "File name too long",
|
|
428
|
+
ENOTSUP: "Operation not supported"
|
|
429
|
+
};
|
|
430
|
+
return details[error.code] ?? error.message;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// packages/safe-bash/src/commands/hexdump/options.ts
|
|
434
|
+
init_platform();
|
|
435
|
+
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 ...]";
|
|
436
|
+
function number(text, skip) {
|
|
437
|
+
let offset = 0;
|
|
438
|
+
while (offset < text.length && " \n\r\v\f".includes(text[offset])) offset++;
|
|
439
|
+
const negative = text[offset] === "-";
|
|
440
|
+
if (negative || text[offset] === "+") offset++;
|
|
441
|
+
let base = 10;
|
|
442
|
+
if (skip && text[offset] === "0") {
|
|
443
|
+
base = 8;
|
|
444
|
+
if ((text[offset + 1] === "x" || text[offset + 1] === "X") && "0123456789abcdef".includes((text[offset + 2] ?? "!").toLowerCase())) {
|
|
445
|
+
base = 16;
|
|
446
|
+
offset += 2;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
let value = 0;
|
|
450
|
+
for (; offset < text.length; offset++) {
|
|
451
|
+
const digit = "0123456789abcdef".indexOf(text[offset].toLowerCase());
|
|
452
|
+
if (digit < 0 || digit >= base) break;
|
|
453
|
+
value = value * base + digit;
|
|
454
|
+
if (!Number.isSafeInteger(value)) throw new HexdumpError(`${text}: numeric value exceeds safe integer range`);
|
|
455
|
+
}
|
|
456
|
+
if (negative && value !== 0) throw new HexdumpError(`${text}: bad ${skip ? "skip" : "length"} value`);
|
|
457
|
+
if (skip) value *= { b: 512, k: 1024, m: 1048576 }[text[offset] ?? ""] ?? 1;
|
|
458
|
+
if (!Number.isSafeInteger(value)) throw new HexdumpError(`${text}: numeric value exceeds safe integer range`);
|
|
459
|
+
return value;
|
|
460
|
+
}
|
|
461
|
+
function parse(budget, name) {
|
|
462
|
+
const args = budget.arguments();
|
|
463
|
+
const files = [];
|
|
464
|
+
let canonical = name === "hd" ? 1 : 0;
|
|
465
|
+
let verbose = false, ended = false, skip = 0, count = Infinity;
|
|
466
|
+
for (let index = 0; index < args.length; index++) {
|
|
467
|
+
const argument = args[index];
|
|
468
|
+
if (!ended && argument === "--") {
|
|
469
|
+
ended = true;
|
|
470
|
+
continue;
|
|
471
|
+
}
|
|
472
|
+
if (ended || argument === "-" || !argument.startsWith("-")) {
|
|
473
|
+
files.push(argument);
|
|
474
|
+
if (budget.context.env.POSIXLY_CORRECT !== void 0) ended = true;
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
477
|
+
for (let offset = 1; offset < argument.length; offset++) {
|
|
478
|
+
budget.charge();
|
|
479
|
+
const flag = argument[offset];
|
|
480
|
+
if (flag === "v") verbose = true;
|
|
481
|
+
else if (flag === "C") {
|
|
482
|
+
if (name === "hd") throw new HexdumpError(usage, true);
|
|
483
|
+
budget.check(++canonical, budget.limits.maxFormats, "format count");
|
|
484
|
+
} else if (flag === "n" || flag === "s") {
|
|
485
|
+
const parameter = argument.slice(offset + 1) || args[++index];
|
|
486
|
+
if (parameter === void 0) throw new HexdumpError(`${name}: option requires an argument -- '${flag}'
|
|
487
|
+
${usage}`, true);
|
|
488
|
+
if (flag === "n") count = number(parameter, false);
|
|
489
|
+
else skip = number(parameter, true);
|
|
490
|
+
break;
|
|
491
|
+
} else if (flag === "e" || flag === "f") throw new HexdumpError(`-${flag}: custom formats are not supported`);
|
|
492
|
+
else throw new HexdumpError(`unsupported option -- '${flag}'`);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
return { files, canonical, verbose, skip, count };
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// packages/safe-bash/src/commands/hexdump/format.ts
|
|
499
|
+
init_platform();
|
|
500
|
+
function formatBlock(block, used, address, canonical) {
|
|
501
|
+
let result = address.toString(16).padStart(canonical ? 8 : 7, "0") + (canonical ? " " : " ");
|
|
502
|
+
if (canonical) {
|
|
503
|
+
for (let index = 0; index < 16; index++) {
|
|
504
|
+
if (index === 8) result += " ";
|
|
505
|
+
result += index < used ? block[index].toString(16).padStart(2, "0") : " ";
|
|
506
|
+
if (index !== 15) result += " ";
|
|
507
|
+
}
|
|
508
|
+
result += " |";
|
|
509
|
+
for (let index = 0; index < used; index++) {
|
|
510
|
+
const byte = block[index];
|
|
511
|
+
result += byte >= 32 && byte <= 126 ? String.fromCharCode(byte) : ".";
|
|
512
|
+
}
|
|
513
|
+
return result + "|\n";
|
|
514
|
+
}
|
|
515
|
+
for (let index = 0; index < 16; index += 2) {
|
|
516
|
+
result += index < used ? (block[index] + (index + 1 < used ? block[index + 1] * 256 : 0)).toString(16).padStart(4, "0") : " ";
|
|
517
|
+
if (index !== 14) result += " ";
|
|
518
|
+
}
|
|
519
|
+
return result + "\n";
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// packages/safe-bash/src/commands/hexdump/command.ts
|
|
523
|
+
async function dump(options, lifecycle, name) {
|
|
524
|
+
if (options.count === 0) return 0;
|
|
525
|
+
const { budget } = lifecycle;
|
|
526
|
+
budget.retain(32);
|
|
527
|
+
const block = new Uint8Array(16), previous = new Uint8Array(16);
|
|
528
|
+
let address = 0, used = 0, skip = options.skip, count = options.count;
|
|
529
|
+
let hasPrevious = false, squeezed = false, exitCode = 0;
|
|
530
|
+
const emit = async () => {
|
|
531
|
+
let same = hasPrevious;
|
|
532
|
+
for (let index = 0; same && index < used; index++) if (block[index] !== previous[index]) same = false;
|
|
533
|
+
budget.charge(used);
|
|
534
|
+
if (!options.verbose && same) {
|
|
535
|
+
if (!squeezed) await lifecycle.write("*\n");
|
|
536
|
+
squeezed = true;
|
|
537
|
+
} else {
|
|
538
|
+
for (let index = 0; index < Math.max(1, options.canonical); index++) {
|
|
539
|
+
budget.charge(16);
|
|
540
|
+
await budget.checkpointWork();
|
|
541
|
+
await lifecycle.write(formatBlock(block, used, address, options.canonical > 0));
|
|
542
|
+
}
|
|
543
|
+
previous.set(block);
|
|
544
|
+
hasPrevious = true;
|
|
545
|
+
squeezed = false;
|
|
546
|
+
}
|
|
547
|
+
address += used;
|
|
548
|
+
used = 0;
|
|
549
|
+
};
|
|
550
|
+
for (const file of options.files.length ? options.files : [void 0]) {
|
|
551
|
+
if (count === 0) break;
|
|
552
|
+
const reader = new Reader(file, lifecycle);
|
|
553
|
+
let opened = true;
|
|
554
|
+
try {
|
|
555
|
+
await reader.open();
|
|
556
|
+
} catch (error) {
|
|
557
|
+
budget.signal.throwIfAborted();
|
|
558
|
+
if (!(error instanceof FsError)) throw error;
|
|
559
|
+
opened = false;
|
|
560
|
+
if (error.code !== "EISDIR") exitCode = 1;
|
|
561
|
+
await lifecycle.write(`${name}: ${file ?? "stdin"}: ${fsDetail(error)}
|
|
562
|
+
`, true);
|
|
563
|
+
}
|
|
564
|
+
if (opened) {
|
|
565
|
+
while (count > 0) {
|
|
566
|
+
let byte;
|
|
567
|
+
try {
|
|
568
|
+
byte = await reader.get();
|
|
569
|
+
} catch (error) {
|
|
570
|
+
budget.signal.throwIfAborted();
|
|
571
|
+
if (!(error instanceof FsError)) throw error;
|
|
572
|
+
await lifecycle.write(`${name}: ${file ?? "stdin"}: ${fsDetail(error)}
|
|
573
|
+
`, true);
|
|
574
|
+
break;
|
|
575
|
+
}
|
|
576
|
+
if (byte < 0) break;
|
|
577
|
+
if (skip > 0) {
|
|
578
|
+
skip--;
|
|
579
|
+
address++;
|
|
580
|
+
continue;
|
|
581
|
+
}
|
|
582
|
+
block[used++] = byte;
|
|
583
|
+
count--;
|
|
584
|
+
if (used === 16) await emit();
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
await lifecycle.operation(() => reader.close());
|
|
588
|
+
}
|
|
589
|
+
if (used) await emit();
|
|
590
|
+
if (address > 0) await lifecycle.write(address.toString(16).padStart(options.canonical ? 8 : 7, "0") + "\n");
|
|
591
|
+
return exitCode;
|
|
592
|
+
}
|
|
593
|
+
async function execute(context, name, limits) {
|
|
594
|
+
let lifecycle;
|
|
595
|
+
const caller = context.signal;
|
|
596
|
+
caller.throwIfAborted();
|
|
597
|
+
const stdout = context.stdout;
|
|
598
|
+
caller.throwIfAborted();
|
|
599
|
+
const capability = stdout.ownedOutput;
|
|
600
|
+
caller.throwIfAborted();
|
|
601
|
+
const consumer = capability?.consumerClosed;
|
|
602
|
+
caller.throwIfAborted();
|
|
603
|
+
consumer?.throwIfAborted();
|
|
604
|
+
const failureHandler = stdout[outputFailure];
|
|
605
|
+
caller.throwIfAborted();
|
|
606
|
+
consumer?.throwIfAborted();
|
|
607
|
+
const registerCleanup = context.registerCleanup;
|
|
608
|
+
caller.throwIfAborted();
|
|
609
|
+
consumer?.throwIfAborted();
|
|
610
|
+
const destination = capability ?? stdout;
|
|
611
|
+
const write = async (value) => {
|
|
612
|
+
lifecycle.assertOpen();
|
|
613
|
+
const method = destination.write;
|
|
614
|
+
lifecycle.assertOpen();
|
|
615
|
+
await Reflect.apply(method, destination, [value]);
|
|
616
|
+
};
|
|
617
|
+
const captured = {
|
|
618
|
+
write,
|
|
619
|
+
...capability ? { ownedOutput: { consumerClosed: consumer, write } } : {},
|
|
620
|
+
...failureHandler ? { [outputFailure]: failureHandler } : {}
|
|
621
|
+
};
|
|
622
|
+
const admission = { closed: false };
|
|
623
|
+
const output = createOutputOperation({ signal: caller, ...registerCleanup ? { registerCleanup(cleanup) {
|
|
624
|
+
caller.throwIfAborted();
|
|
625
|
+
Reflect.apply(registerCleanup, context, [() => {
|
|
626
|
+
admission.closed = true;
|
|
627
|
+
return cleanup();
|
|
628
|
+
}]);
|
|
629
|
+
} } : {} }, captured);
|
|
630
|
+
const budget = new Budget(context, limits, output.signal, caller, admission);
|
|
631
|
+
let failure;
|
|
632
|
+
let primary;
|
|
633
|
+
let exitCode = 0;
|
|
634
|
+
try {
|
|
635
|
+
lifecycle = new Lifecycle(budget, output, captured, caller);
|
|
636
|
+
exitCode = await dump(parse(budget, name), lifecycle, name);
|
|
637
|
+
} catch (error) {
|
|
638
|
+
primary = { reason: error };
|
|
639
|
+
if (error instanceof HexdumpError && !output.signal.aborted && lifecycle) {
|
|
640
|
+
exitCode = 1;
|
|
641
|
+
try {
|
|
642
|
+
await lifecycle.write(`${error.bare ? "" : name + ": "}${error.message}
|
|
643
|
+
`, true);
|
|
644
|
+
} catch (reporting) {
|
|
645
|
+
failure = { reason: new AggregateError([error, reporting], "hexdump failure reporting failed") };
|
|
646
|
+
}
|
|
647
|
+
} else failure = { reason: error };
|
|
648
|
+
}
|
|
649
|
+
try {
|
|
650
|
+
await output.close();
|
|
651
|
+
} catch (cleanup) {
|
|
652
|
+
const previous = failure ?? primary;
|
|
653
|
+
failure = { reason: previous ? new AggregateError([previous.reason, cleanup], "hexdump execution and cleanup failed") : cleanup };
|
|
654
|
+
}
|
|
655
|
+
caller.throwIfAborted();
|
|
656
|
+
output.signal.throwIfAborted();
|
|
657
|
+
if (lifecycle?.diagnosticCancellation) throw lifecycle.diagnosticCancellation.reason;
|
|
658
|
+
if (failure) throw failure.reason;
|
|
659
|
+
return { exitCode };
|
|
660
|
+
}
|
|
661
|
+
function createHexdumpCommand(options = {}) {
|
|
662
|
+
const limits = settings(options);
|
|
663
|
+
return {
|
|
664
|
+
name: "hexdump",
|
|
665
|
+
description: "Display bytes as hexadecimal words or canonical hex and ASCII",
|
|
666
|
+
execute: (context) => execute(context, "hexdump", limits)
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
function createHdCommand(options = {}) {
|
|
670
|
+
const limits = settings(options);
|
|
671
|
+
return {
|
|
672
|
+
name: "hd",
|
|
673
|
+
description: "Display canonical hexadecimal and ASCII bytes",
|
|
674
|
+
execute: (context) => execute(context, "hd", limits)
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
// packages/safe-bash/src/commands/hexdump/index.ts
|
|
679
|
+
function createHexdumpCommands(options = {}) {
|
|
680
|
+
return [createHexdumpCommand(options), createHdCommand(options)];
|
|
681
|
+
}
|
|
682
|
+
function hexdumpCommands(options = {}) {
|
|
683
|
+
const commands = createHexdumpCommands(options);
|
|
684
|
+
return { name: "hexdump-commands", setup(host) {
|
|
685
|
+
if (!options.replace) {
|
|
686
|
+
for (const command of commands) if (host.commands.has(command.name)) throw new Error(`Command already registered: ${command.name}`);
|
|
687
|
+
}
|
|
688
|
+
for (const command of commands) host.commands.register(command, { replace: options.replace ?? false });
|
|
689
|
+
} };
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
export {
|
|
693
|
+
createHexdumpCommand,
|
|
694
|
+
createHdCommand,
|
|
695
|
+
createHexdumpCommands,
|
|
696
|
+
hexdumpCommands
|
|
697
|
+
};
|
|
698
|
+
//# sourceMappingURL=chunk-R3QJL5HH.js.map
|