@poe-platform/safe-bash 0.1.802 → 0.1.803
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/README.md +4 -2
- package/dist/image-ast/index.browser.js +13 -4
- package/dist/image-ast/index.js +13 -4
- package/dist/safe-bash/chunks/{chunk-KDNSPLII.js → chunk-2LSAMQER.js} +1 -0
- package/dist/safe-bash/chunks/{chunk-NZQXYWA3.js → chunk-5OHX7C2V.js} +0 -1
- package/dist/safe-bash/chunks/{chunk-SHEMU2Z7.js → chunk-B7PIL77G.js} +82 -63
- package/dist/safe-bash/chunks/{chunk-WDLGKIHD.js → chunk-EEEWOYEG.js} +4 -4
- package/dist/safe-bash/chunks/{chunk-GETUOD5D.js → chunk-GDYNCWRV.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-RSTHLAF3.js → chunk-JMMEIDPF.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-44ALJ4QG.js → chunk-PNBBUWSM.js} +71 -55
- package/dist/safe-bash/chunks/{chunk-NQCM3TYR.js → chunk-RYFQ3LZG.js} +73 -44
- package/dist/safe-bash/chunks/chunk-VBTDHOWC.js +55 -0
- package/dist/safe-bash/command-chunks/{chunk-ORYGZYKW.js → chunk-4FEVBOL5.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-VXSLJH7G.js → chunk-6JSIFWYT.js} +26 -6
- package/dist/safe-bash/command-chunks/chunk-A7MU7762.js +200 -0
- package/dist/safe-bash/command-chunks/{chunk-KJIMDLBB.js → chunk-BXCXRYVU.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-F4TEEZTL.js → chunk-CQHP3I66.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-PEF7K3UQ.js → chunk-EARHPPPJ.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-QKFSRZGQ.js → chunk-GFC2NTDG.js} +2 -2
- package/dist/safe-bash/command-chunks/chunk-GIRNFXP3.js +466 -0
- package/dist/safe-bash/command-chunks/{chunk-FPVUD6TH.js → chunk-HDCNKOIX.js} +9 -7
- package/dist/safe-bash/command-chunks/{chunk-MQFIPHIQ.js → chunk-ILX2NOLF.js} +18 -15
- package/dist/safe-bash/command-chunks/{chunk-5E4WAO4O.js → chunk-JD5QNRNO.js} +3 -3
- package/dist/safe-bash/command-chunks/{chunk-I237SNW5.js → chunk-LFJJQQND.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-W5DNF4JH.js → chunk-LOICUCHG.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-7U7EXOXX.js → chunk-NASVPT6F.js} +2 -1
- package/dist/safe-bash/command-chunks/{chunk-OQKC5ZU2.js → chunk-NKIELG7Y.js} +22 -1
- package/dist/safe-bash/command-chunks/{chunk-WPYIOKE3.js → chunk-PICVQ6B5.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-YOFC45RK.js → chunk-QVOS4YXL.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-VGG2DL5Q.js → chunk-TRR4MYWF.js} +4 -0
- package/dist/safe-bash/command-chunks/{chunk-2JRBIDAD.js → chunk-V4K2JDYU.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-6GWJUQAV.js → chunk-WWIBP2ET.js} +38 -111
- package/dist/safe-bash/command-chunks/chunk-ZDN7MJE6.js +168 -0
- package/dist/safe-bash/commands/bytes/compression/index.js +54 -51
- package/dist/safe-bash/commands/chmod/index.browser.js +14 -0
- package/dist/safe-bash/commands/chmod/index.d.ts +2 -0
- package/dist/safe-bash/commands/chmod/index.js +2 -0
- package/dist/safe-bash/commands/metadata/chmod.d.ts +1 -7
- package/dist/safe-bash/commands/metadata/chmod.js +1 -204
- package/dist/safe-bash/commands/metadata/index.browser.js +1 -5
- package/dist/safe-bash/commands/metadata/internal.d.ts +1 -30
- package/dist/safe-bash/commands/metadata/internal.js +1 -76
- package/dist/safe-bash/commands/metadata/mktemp.d.ts +1 -3
- package/dist/safe-bash/commands/metadata/mktemp.js +1 -202
- package/dist/safe-bash/commands/metadata/stat.d.ts +1 -7
- package/dist/safe-bash/commands/metadata/stat.js +1 -530
- package/dist/safe-bash/commands/mktemp/index.browser.js +13 -0
- package/dist/safe-bash/commands/mktemp/index.d.ts +2 -0
- package/dist/safe-bash/commands/mktemp/index.js +2 -0
- package/dist/safe-bash/commands/node/index.browser.js +2 -2
- package/dist/safe-bash/commands/portable-random.d.ts +1 -1
- package/dist/safe-bash/commands/portable-random.js +1 -12
- package/dist/safe-bash/commands/python/index.browser.js +3 -3
- package/dist/safe-bash/commands/stat/index.browser.js +13 -0
- package/dist/safe-bash/commands/stat/index.d.ts +2 -0
- package/dist/safe-bash/commands/stat/index.js +2 -0
- package/dist/safe-bash/commands/text.js +46 -10
- package/dist/safe-bash/full-core.browser.js +86 -86
- package/dist/safe-bash/jobs.browser.js +2 -2
- package/dist/safe-bash/opt-in/commands/yq/native-work.js +1 -0
- package/dist/safe-bash/optional-host.browser.js +10 -10
- package/dist/safe-bash/plugins/index.browser.js +13 -13
- package/dist/safe-bash/registry-entry.browser.js +16 -16
- package/dist/safe-bash/search.browser.js +14 -14
- package/dist/safe-bash/shell/runtime.d.ts +3 -0
- package/dist/safe-bash/shell/runtime.js +20 -3
- package/dist/safe-bash/shell/types.d.ts +2 -0
- package/dist/safe-bash/shell/worker-limits.js +1 -0
- package/dist/safe-bash/shell-entry.browser.js +12 -12
- package/dist/safe-bash/worker/host.js +1 -1
- package/dist/safe-bash-command-bc/index.js +12 -5
- package/dist/safe-bash-command-bzip2/index.js +4 -3
- package/dist/safe-bash-command-chmod/LICENSE +21 -0
- package/dist/safe-bash-command-chmod/command.d.ts +7 -0
- package/dist/safe-bash-command-chmod/command.js +11 -0
- package/dist/safe-bash-command-chmod/index.d.ts +6 -0
- package/dist/safe-bash-command-chmod/index.js +27 -0
- package/dist/safe-bash-command-exiftool/index.js +5 -5
- package/dist/safe-bash-command-find/find.js +1 -1
- package/dist/safe-bash-command-find/index.js +1 -1
- package/dist/safe-bash-command-fmt/index.js +9 -2
- package/dist/safe-bash-command-gzip/index.js +45 -42
- package/dist/safe-bash-command-imagemagick/index.js +3 -1
- package/dist/safe-bash-command-jq/index.js +1 -1
- package/dist/safe-bash-command-jq/jq.js +1 -1
- package/dist/safe-bash-command-less/index.js +12 -3
- package/dist/safe-bash-command-mktemp/LICENSE +21 -0
- package/dist/safe-bash-command-mktemp/command.d.ts +3 -0
- package/dist/safe-bash-command-mktemp/command.js +9 -0
- package/dist/safe-bash-command-mktemp/index.d.ts +6 -0
- package/dist/safe-bash-command-mktemp/index.js +25 -0
- package/dist/safe-bash-command-od/index.js +6 -2
- package/dist/safe-bash-command-op/index.js +25 -6
- package/dist/safe-bash-command-rg/index.js +1 -1
- package/dist/safe-bash-command-rg/rg-command.js +1 -1
- package/dist/safe-bash-command-sed/index.js +1 -1
- package/dist/safe-bash-command-sed/sed.js +1 -1
- package/dist/safe-bash-command-sips/index.js +13 -5
- package/dist/safe-bash-command-sponge/index.js +10 -3
- package/dist/safe-bash-command-stat/LICENSE +21 -0
- package/dist/safe-bash-command-stat/command.d.ts +7 -0
- package/dist/safe-bash-command-stat/command.js +9 -0
- package/dist/safe-bash-command-stat/index.d.ts +6 -0
- package/dist/safe-bash-command-stat/index.js +25 -0
- package/dist/safe-bash-command-unrtf/index.js +11 -1
- package/dist/safe-bash-command-xxd/index.js +6 -2
- package/dist/safe-bash-command-xz/command.d.ts +1 -1
- package/dist/safe-bash-command-xz/index.js +3 -2
- package/dist/safe-bash-command-yq/index.js +1 -0
- package/dist/safe-bash-command-yq/native-work.js +1 -0
- package/dist/safe-bash-command-yq/query.js +3 -0
- package/dist/safe-bash-compression-engine/bounded-codec.js +3 -3
- package/dist/safe-bash-compression-engine/codec-loader.js +2 -2
- package/dist/safe-bash-compression-engine/files.js +6 -6
- package/dist/safe-bash-compression-engine/index.js +5 -5
- package/dist/safe-bash-compression-engine/operand.js +6 -6
- package/dist/safe-bash-compression-engine/options.js +1 -1
- package/dist/safe-bash-compression-engine/stream.js +5 -5
- package/dist/safe-bash-compression-engine/zstd-decode.js +4 -4
- package/dist/safe-bash-contracts/escaping.js +2 -2
- package/dist/safe-bash-contracts/filesystem-output.js +2 -2
- package/dist/safe-bash-contracts/index.js +2 -2
- package/dist/safe-bash-contracts/io.d.ts +2 -0
- package/dist/safe-bash-contracts/io.js +1 -1
- package/dist/safe-bash-contracts/output.js +2 -2
- package/dist/safe-bash-io-engine/commands/search/requirements.js +1 -1
- package/dist/safe-bash-io-engine/commands/text-programs/shared.js +1 -1
- package/dist/safe-bash-mcp/index.browser.js +11 -1
- package/dist/safe-bash-mcp/index.js +35 -16
- package/dist/safe-bash-metadata-engine/LICENSE +21 -0
- package/dist/safe-bash-metadata-engine/index.d.ts +30 -0
- package/dist/safe-bash-metadata-engine/index.js +82 -0
- package/dist/safe-bash-metadata-engine/random.d.ts +1 -0
- package/dist/safe-bash-metadata-engine/random.js +21 -0
- package/dist/safe-bash-regex-engine/index.js +1 -1
- package/dist/safe-bash-regex-engine/text/regex.js +1 -1
- package/dist/safe-bash-search-engine/ergonomic-regex.js +2 -2
- package/dist/safe-bash-search-engine/glob.js +2 -2
- package/dist/safe-bash-search-engine/grep.js +2 -2
- package/dist/safe-bash-search-engine/matcher.js +2 -2
- package/dist/safe-bash-search-engine/options.d.ts +2 -0
- package/dist/safe-bash-search-engine/options.js +1 -1
- package/dist/safe-bash-search-engine/output.js +1 -1
- package/dist/safe-bash-search-engine/shared.js +2 -2
- package/dist/safe-bash-search-engine/walk.js +3 -3
- package/dist/safe-playwright-cloudflare/browser-snapshot-json.js +2 -2
- package/dist/safe-playwright-cloudflare/browser-snapshot-references.js +1 -1
- package/package.json +31 -5
- package/dist/safe-bash/chunks/chunk-VSAJ4OTM.js +0 -962
- package/dist/safe-bash/chunks/{chunk-BJA5XNP6.js → chunk-A7XEHALN.js} +3 -3
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
import {
|
|
2
|
+
init_buffer
|
|
3
|
+
} from "./chunk-HX3SHTCE.js";
|
|
4
|
+
|
|
5
|
+
// packages/safe-bash-command-stat/src/command.ts
|
|
6
|
+
init_buffer();
|
|
7
|
+
import { FsError } from "../../safe-bash-contracts/index.js";
|
|
8
|
+
import { codeOf, diagnostic, pathOf, requireOperands, UsageError } from "../../safe-bash-io-engine/internal.js";
|
|
9
|
+
import { MetadataBudget, metadataCommand, permissionString, settings } from "../../safe-bash-metadata-engine/index.js";
|
|
10
|
+
var syncStatEncoder = new TextEncoder();
|
|
11
|
+
function concatBytes(chunks) {
|
|
12
|
+
if (chunks.length === 0) return new Uint8Array(0);
|
|
13
|
+
if (chunks.length === 1) return chunks[0];
|
|
14
|
+
let total = 0;
|
|
15
|
+
for (let i = 0; i < chunks.length; i++) total += chunks[i].byteLength;
|
|
16
|
+
const out = new Uint8Array(total);
|
|
17
|
+
let offset = 0;
|
|
18
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
19
|
+
const c = chunks[i];
|
|
20
|
+
out.set(c, offset);
|
|
21
|
+
offset += c.byteLength;
|
|
22
|
+
}
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
function allocSpaces(length) {
|
|
26
|
+
const out = new Uint8Array(length);
|
|
27
|
+
out.fill(32);
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
function parse(args) {
|
|
31
|
+
let follow = false;
|
|
32
|
+
let filesystem = false;
|
|
33
|
+
let terse = false;
|
|
34
|
+
let format;
|
|
35
|
+
let printf = false;
|
|
36
|
+
let literal = false;
|
|
37
|
+
const paths = [];
|
|
38
|
+
for (let index = 0; index < args.length; index++) {
|
|
39
|
+
const argument = args[index];
|
|
40
|
+
if (literal || argument === "-" || !argument.startsWith("-")) paths.push(argument);
|
|
41
|
+
else if (argument === "--") literal = true;
|
|
42
|
+
else if (argument === "--dereference") follow = true;
|
|
43
|
+
else if (argument === "--cached=default" || argument === "--cached=never" || argument === "--cached=always") continue;
|
|
44
|
+
else if (argument === "--file-system") filesystem = true;
|
|
45
|
+
else if (argument === "--terse") terse = true;
|
|
46
|
+
else if (argument === "--format" || argument.startsWith("--format=") || argument === "--printf" || argument.startsWith("--printf=")) {
|
|
47
|
+
printf = argument.startsWith("--printf");
|
|
48
|
+
format = argument.includes("=") ? argument.slice(argument.indexOf("=") + 1) : args[++index];
|
|
49
|
+
if (format === void 0) throw new UsageError(`missing format for '${argument}'`);
|
|
50
|
+
} else if (!argument.startsWith("--")) {
|
|
51
|
+
for (let offset = 1; offset < argument.length; offset++) {
|
|
52
|
+
if (argument[offset] === "L") follow = true;
|
|
53
|
+
else if (argument[offset] === "f") filesystem = true;
|
|
54
|
+
else if (argument[offset] === "t") terse = true;
|
|
55
|
+
else if (argument[offset] === "c") {
|
|
56
|
+
format = argument.slice(offset + 1) || args[++index];
|
|
57
|
+
if (format === void 0) throw new UsageError("missing format for '-c'");
|
|
58
|
+
printf = false;
|
|
59
|
+
break;
|
|
60
|
+
} else throw new UsageError(`unrecognized option '${argument}'`);
|
|
61
|
+
}
|
|
62
|
+
} else throw new UsageError(`unrecognized option '${argument}'`);
|
|
63
|
+
}
|
|
64
|
+
requireOperands(paths);
|
|
65
|
+
return { follow, filesystem, terse, format, printf, paths };
|
|
66
|
+
}
|
|
67
|
+
function quoted(text, style) {
|
|
68
|
+
if (style === "literal") return text;
|
|
69
|
+
if (style && !["shell-escape-always", "shell-always"].includes(style)) throw new FsError("ENOTSUP", { message: `unsupported QUOTING_STYLE: ${style}` });
|
|
70
|
+
if (style !== "shell-always" && /[\x00-\x1f\x7f]/u.test(text)) {
|
|
71
|
+
return "$'" + text.replace(/[\\'\x00-\x1f\x7f]/gu, (character) => {
|
|
72
|
+
if (character === "\\" || character === "'") return `\\${character}`;
|
|
73
|
+
if (character === "\n") return "\\n";
|
|
74
|
+
if (character === "\r") return "\\r";
|
|
75
|
+
if (character === " ") return "\\t";
|
|
76
|
+
return `\\${character.charCodeAt(0).toString(8).padStart(3, "0")}`;
|
|
77
|
+
}) + "'";
|
|
78
|
+
}
|
|
79
|
+
return `'${text.replace(/'/gu, "'\\''")}'`;
|
|
80
|
+
}
|
|
81
|
+
function available(value, field) {
|
|
82
|
+
if (value === void 0) throw new FsError("ENOTSUP", { syscall: "stat", message: `filesystem does not expose ${field}` });
|
|
83
|
+
if (!Number.isFinite(value)) throw new FsError("EIO", { syscall: "stat", message: `invalid ${field}` });
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
86
|
+
function timestamp(milliseconds) {
|
|
87
|
+
const value = available(milliseconds, "timestamp");
|
|
88
|
+
if (Math.abs(value) > 864e13) throw new FsError("EIO", { message: "invalid filesystem timestamp" });
|
|
89
|
+
const [coefficient = "0", exponent = "0"] = Math.abs(value).toString().split("e");
|
|
90
|
+
const [integer = "0", fraction = ""] = coefficient.split(".");
|
|
91
|
+
const digits = BigInt(integer + fraction);
|
|
92
|
+
const power = Number(exponent) - fraction.length + 6;
|
|
93
|
+
const divisor = power < 0 ? 10n ** BigInt(-power) : 1n;
|
|
94
|
+
const magnitude = power < 0 ? (digits + divisor / 2n) / divisor : digits * 10n ** BigInt(power);
|
|
95
|
+
const nanoseconds = value < 0 ? -magnitude : magnitude;
|
|
96
|
+
const remainder = (nanoseconds % 1000000000n + 1000000000n) % 1000000000n;
|
|
97
|
+
const seconds = (nanoseconds - remainder) / 1000000000n;
|
|
98
|
+
const date = new Date(Number(seconds * 1000n));
|
|
99
|
+
if (Number.isNaN(date.getTime())) throw new FsError("EIO", { message: "invalid filesystem timestamp" });
|
|
100
|
+
return `${date.toISOString().replace("T", " ").replace(/\.\d{3}Z$/u, `.${remainder.toString().padStart(9, "0")}`)} +0000`;
|
|
101
|
+
}
|
|
102
|
+
function epoch(milliseconds, precision) {
|
|
103
|
+
const value = available(milliseconds, "timestamp");
|
|
104
|
+
const [coefficient = "0", exponent = "0"] = Math.abs(value).toString().split("e");
|
|
105
|
+
const [integer = "0", decimal = ""] = coefficient.split(".");
|
|
106
|
+
const digits = BigInt(integer + decimal);
|
|
107
|
+
const places = Math.min(precision, 9);
|
|
108
|
+
const scale = 10n ** BigInt(places);
|
|
109
|
+
const power = Number(exponent) - decimal.length - 3 + places;
|
|
110
|
+
const absolute = power < 0 ? digits / 10n ** BigInt(-power) : digits * 10n ** BigInt(power);
|
|
111
|
+
const fraction = absolute % scale;
|
|
112
|
+
const seconds = value < 0 && fraction === 0n ? -Math.floor(value / 1e3) : absolute / scale;
|
|
113
|
+
const suffix = precision ? "." + fraction.toString().padStart(places, "0") + "0".repeat(precision - places) : "";
|
|
114
|
+
return `${value < 0 ? "-" : ""}${seconds}${suffix}`;
|
|
115
|
+
}
|
|
116
|
+
function directive(format, start) {
|
|
117
|
+
let index = start + 1;
|
|
118
|
+
const flagsStart = index;
|
|
119
|
+
while (index < format.length && "-+ #0".includes(format[index])) index++;
|
|
120
|
+
const flags = format.slice(flagsStart, index);
|
|
121
|
+
const widthStart = index;
|
|
122
|
+
while (index < format.length && format[index] >= "0" && format[index] <= "9") index++;
|
|
123
|
+
const width = format.slice(widthStart, index);
|
|
124
|
+
let precision;
|
|
125
|
+
if (format[index] === ".") {
|
|
126
|
+
const precisionStart = ++index;
|
|
127
|
+
while (index < format.length && format[index] >= "0" && format[index] <= "9") index++;
|
|
128
|
+
precision = format.slice(precisionStart, index);
|
|
129
|
+
}
|
|
130
|
+
const code = format[index];
|
|
131
|
+
if (code === void 0) throw new UsageError("invalid stat format directive");
|
|
132
|
+
const codePoint = code.charCodeAt(0);
|
|
133
|
+
if (code !== "%" && !(codePoint >= 65 && codePoint <= 90) && !(codePoint >= 97 && codePoint <= 122)) {
|
|
134
|
+
throw new UsageError("invalid stat format directive");
|
|
135
|
+
}
|
|
136
|
+
return { code, flags, length: index + 1 - start, precision, width };
|
|
137
|
+
}
|
|
138
|
+
function formatField(text, code, flags, width, precision, numeric, epoch2) {
|
|
139
|
+
if (numeric) {
|
|
140
|
+
const nonzero = !/^0+$/u.test(text);
|
|
141
|
+
if (!epoch2 && precision !== void 0) text = precision === 0 && !nonzero ? "" : text.padStart(precision, "0");
|
|
142
|
+
if (flags.includes("#")) text = code === "a" ? text.startsWith("0") ? text : `0${text}` : (code === "f" || code === "D") && nonzero ? `0x${text}` : text;
|
|
143
|
+
if (epoch2 && !text.startsWith("-") && (flags.includes("+") || flags.includes(" "))) text = `${flags.includes("+") ? "+" : " "}${text}`;
|
|
144
|
+
}
|
|
145
|
+
if (epoch2 && precision) {
|
|
146
|
+
const decimal = text.indexOf(".");
|
|
147
|
+
const integerWidth = width > precision + 2 && !flags.includes("-") ? width - precision - 1 : 0;
|
|
148
|
+
const integer = formatField(text.slice(0, decimal), code, flags, integerWidth, void 0, true, false);
|
|
149
|
+
const trailingWidth = integer.length < width && 1 < width - integer.length ? Math.abs(width - integer.length - 1 - precision) : 0;
|
|
150
|
+
return concatBytes([integer, syncStatEncoder.encode(text.slice(decimal)), allocSpaces(trailingWidth)]);
|
|
151
|
+
}
|
|
152
|
+
const encoded = syncStatEncoder.encode(text);
|
|
153
|
+
const bytes = !numeric && precision !== void 0 ? encoded.subarray(0, precision) : encoded;
|
|
154
|
+
const padding = Math.max(0, width - bytes.length);
|
|
155
|
+
if (flags.includes("-")) return concatBytes([bytes, allocSpaces(padding)]);
|
|
156
|
+
if (numeric && flags.includes("0") && (epoch2 || precision === void 0) && padding) {
|
|
157
|
+
const prefix = /^[+ -]|^0x/u.exec(text)?.[0] ?? "";
|
|
158
|
+
return syncStatEncoder.encode(prefix + "0".repeat(padding) + text.slice(prefix.length));
|
|
159
|
+
}
|
|
160
|
+
return concatBytes([allocSpaces(padding), bytes]);
|
|
161
|
+
}
|
|
162
|
+
async function render(context, path, name, stat, format, escapes, limit, filesystem, terse) {
|
|
163
|
+
const chunks = [];
|
|
164
|
+
let bytes = 0;
|
|
165
|
+
const append = (text) => {
|
|
166
|
+
const chunk = typeof text === "string" ? new TextEncoder().encode(text) : text;
|
|
167
|
+
bytes += chunk.byteLength;
|
|
168
|
+
if (bytes > limit) throw new FsError("EFBIG", { message: "stat format output limit exceeded" });
|
|
169
|
+
chunks.push(chunk);
|
|
170
|
+
};
|
|
171
|
+
for (let index = 0; index < format.length; ) {
|
|
172
|
+
context.signal.throwIfAborted();
|
|
173
|
+
if (escapes && format[index] === "\\") {
|
|
174
|
+
const named = { a: "\x07", b: "\b", e: "\x1B", f: "\f", n: "\n", r: "\r", t: " ", v: "\v", "\\": "\\", '"': '"' };
|
|
175
|
+
const code2 = format[index + 1] ?? "";
|
|
176
|
+
if (Object.hasOwn(named, code2)) {
|
|
177
|
+
append(named[code2]);
|
|
178
|
+
index += 2;
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
const radix = code2 === "x" ? 16 : 8;
|
|
182
|
+
const start = index + (radix === 16 ? 2 : 1);
|
|
183
|
+
const end = Math.min(format.length, start + (radix === 16 ? 2 : 3));
|
|
184
|
+
let offset = start;
|
|
185
|
+
let value = 0;
|
|
186
|
+
while (offset < end) {
|
|
187
|
+
const digit = "0123456789abcdef".indexOf(format[offset].toLowerCase());
|
|
188
|
+
if (digit < 0 || digit >= radix) break;
|
|
189
|
+
value = value * radix + digit;
|
|
190
|
+
offset++;
|
|
191
|
+
}
|
|
192
|
+
if (offset === start) {
|
|
193
|
+
append(format[index++]);
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
append(Uint8Array.of(value));
|
|
197
|
+
index = offset;
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
if (format[index] !== "%") {
|
|
201
|
+
const point = String.fromCodePoint(format.codePointAt(index));
|
|
202
|
+
append(point);
|
|
203
|
+
index += point.length;
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
const parsed = directive(format, index);
|
|
207
|
+
index += parsed.length;
|
|
208
|
+
const { code, flags } = parsed;
|
|
209
|
+
const width = Number(parsed.width || 0);
|
|
210
|
+
if (!Number.isSafeInteger(width) || width > limit) throw new FsError("EFBIG", { message: "stat format width limit exceeded" });
|
|
211
|
+
const epochCode = !filesystem && ["X", "Y", "Z", "W"].includes(code);
|
|
212
|
+
const precision = parsed.precision === void 0 ? void 0 : Number(parsed.precision || (epochCode ? 9 : 0));
|
|
213
|
+
if (precision !== void 0 && (!Number.isSafeInteger(precision) || precision > limit)) throw new FsError("EFBIG", { message: "stat format precision limit exceeded" });
|
|
214
|
+
if (code === "%" && parsed.length !== 2) throw new UsageError("invalid stat format directive");
|
|
215
|
+
if (filesystem) {
|
|
216
|
+
let text2;
|
|
217
|
+
if (code === "n") text2 = name;
|
|
218
|
+
else if (code === "%") text2 = "%";
|
|
219
|
+
else if (code === "T") {
|
|
220
|
+
if (stat.filesystemType === void 0) throw new FsError("ENOTSUP", { syscall: "stat", message: "filesystem does not expose its type" });
|
|
221
|
+
if (typeof stat.filesystemType !== "string" || stat.filesystemType.length === 0) throw new FsError("EIO", { syscall: "stat", message: "invalid filesystem type" });
|
|
222
|
+
text2 = stat.filesystemType;
|
|
223
|
+
} else throw new FsError("ENOTSUP", { message: `unsupported filesystem stat format: %${code}` });
|
|
224
|
+
append(formatField(text2, code, flags, width, precision, false, false));
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
let text;
|
|
228
|
+
let linkText;
|
|
229
|
+
let numeric = false;
|
|
230
|
+
if (["a", "A", "f"].includes(code)) available(stat.mode, "mode");
|
|
231
|
+
const times = { X: stat.atimeMs, Y: stat.mtimeMs, Z: stat.ctimeMs, W: stat.birthtimeMs };
|
|
232
|
+
if (Object.hasOwn(times, code)) {
|
|
233
|
+
text = terse && times[code] === void 0 ? "?" : epoch(available(times[code], code), precision ?? 0);
|
|
234
|
+
numeric = text !== "?";
|
|
235
|
+
} else if (code === "n") text = name;
|
|
236
|
+
else if (code === "N") {
|
|
237
|
+
text = quoted(name, context.env.QUOTING_STYLE);
|
|
238
|
+
if (stat.type === "symlink") {
|
|
239
|
+
if (!context.fs.readlink) throw new FsError("ENOTSUP", { syscall: "readlink", path });
|
|
240
|
+
linkText = quoted(await context.fs.readlink(path, { signal: context.signal }), context.env.QUOTING_STYLE);
|
|
241
|
+
}
|
|
242
|
+
} else if (code === "%") text = "%";
|
|
243
|
+
else if (code === "A") text = permissionString(stat.mode, stat.type);
|
|
244
|
+
else if (code === "U") text = available(stat.uid, "u") === 0 ? "root" : String(stat.uid);
|
|
245
|
+
else if (code === "G") text = available(stat.gid, "g") === 0 ? "root" : String(stat.gid);
|
|
246
|
+
else if (code === "m") text = "/";
|
|
247
|
+
else if (code === "F") text = stat.type === "directory" ? "directory" : stat.type === "symlink" ? "symbolic link" : stat.type === "character" ? "character special file" : stat.size === 0 ? "regular empty file" : "regular file";
|
|
248
|
+
else if (["x", "y", "z", "w"].includes(code)) {
|
|
249
|
+
const value = times[code.toUpperCase()];
|
|
250
|
+
text = code === "w" && value === void 0 ? "-" : timestamp(available(value, code));
|
|
251
|
+
} else {
|
|
252
|
+
const fields = {
|
|
253
|
+
s: stat.size,
|
|
254
|
+
a: stat.mode & 4095,
|
|
255
|
+
f: stat.mode,
|
|
256
|
+
i: stat.ino,
|
|
257
|
+
h: stat.nlink,
|
|
258
|
+
u: stat.uid,
|
|
259
|
+
g: stat.gid,
|
|
260
|
+
d: stat.dev,
|
|
261
|
+
D: stat.dev,
|
|
262
|
+
B: 512,
|
|
263
|
+
b: stat.allocatedBytes === void 0 ? void 0 : Math.ceil(stat.allocatedBytes / 512),
|
|
264
|
+
o: stat.ioBlockSize,
|
|
265
|
+
t: stat.rdevMajor,
|
|
266
|
+
T: stat.rdevMinor
|
|
267
|
+
};
|
|
268
|
+
if (!Object.hasOwn(fields, code)) throw new FsError("ENOTSUP", { message: `unsupported stat format: %${code}` });
|
|
269
|
+
const value = fields[code];
|
|
270
|
+
text = terse && value === void 0 ? "?" : available(value, code).toString(code === "a" ? 8 : ["f", "D", "t", "T"].includes(code) ? 16 : 10);
|
|
271
|
+
numeric = text !== "?";
|
|
272
|
+
}
|
|
273
|
+
append(formatField(text, code, flags, width, precision, numeric, epochCode));
|
|
274
|
+
if (linkText !== void 0) {
|
|
275
|
+
append(" -> ");
|
|
276
|
+
append(formatField(linkText, code, flags, width, precision, false, false));
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return concatBytes(chunks);
|
|
280
|
+
}
|
|
281
|
+
function createStatCommand(configuration = {}) {
|
|
282
|
+
const configured = settings(configuration);
|
|
283
|
+
return metadataCommand("stat", async (context) => {
|
|
284
|
+
const budget = new MetadataBudget(context, configured.limits);
|
|
285
|
+
const parsed = parse(context.args);
|
|
286
|
+
let exitCode = 0;
|
|
287
|
+
for (const name of parsed.paths) {
|
|
288
|
+
await budget.step();
|
|
289
|
+
try {
|
|
290
|
+
const path = pathOf(context, name);
|
|
291
|
+
const stat = await context.fs[parsed.follow || parsed.filesystem ? "stat" : "lstat"](path, { signal: context.signal });
|
|
292
|
+
const terse = parsed.terse && parsed.format === void 0;
|
|
293
|
+
if (terse && parsed.filesystem) throw new FsError("ENOTSUP", { message: "filesystem terse stat is unsupported" });
|
|
294
|
+
const format = parsed.format ?? (parsed.filesystem ? " File: %n\n Type: %T" : terse ? "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %W %o" : " File: %N\n Size: %s Type: %F\n Mode: %a (%A)\nAccess: %x\nModify: %y\nChange: %z\n Birth: %w");
|
|
295
|
+
const text = await render(context, path, name, stat, format, parsed.printf, configured.limits.maxOutputBytes, parsed.filesystem, terse);
|
|
296
|
+
await budget.output(parsed.printf ? text : concatBytes([text, Uint8Array.of(10)]));
|
|
297
|
+
} catch (error) {
|
|
298
|
+
context.signal.throwIfAborted();
|
|
299
|
+
if (codeOf(error) === "EFBIG") throw error;
|
|
300
|
+
await diagnostic(context, error);
|
|
301
|
+
exitCode = 1;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return { exitCode };
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
var syncStatDecoder = new TextDecoder("utf-8", { fatal: false });
|
|
308
|
+
function renderSync(path, name, stat, format, escapes, limit, filesystem, terse, quotingStyle) {
|
|
309
|
+
const chunks = [];
|
|
310
|
+
let bytes = 0;
|
|
311
|
+
const append = (text) => {
|
|
312
|
+
const chunk = typeof text === "string" ? new TextEncoder().encode(text) : text;
|
|
313
|
+
bytes += chunk.byteLength;
|
|
314
|
+
if (bytes > limit) throw new FsError("EFBIG", { message: "stat format output limit exceeded" });
|
|
315
|
+
chunks.push(chunk);
|
|
316
|
+
};
|
|
317
|
+
for (let index = 0; index < format.length; ) {
|
|
318
|
+
if (escapes && format[index] === "\\") {
|
|
319
|
+
const named = { a: "\x07", b: "\b", e: "\x1B", f: "\f", n: "\n", r: "\r", t: " ", v: "\v", "\\": "\\", '"': '"' };
|
|
320
|
+
const code2 = format[index + 1] ?? "";
|
|
321
|
+
if (Object.hasOwn(named, code2)) {
|
|
322
|
+
append(named[code2]);
|
|
323
|
+
index += 2;
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
const radix = code2 === "x" ? 16 : 8;
|
|
327
|
+
const start = index + (radix === 16 ? 2 : 1);
|
|
328
|
+
const end = Math.min(format.length, start + (radix === 16 ? 2 : 3));
|
|
329
|
+
let offset = start;
|
|
330
|
+
let value = 0;
|
|
331
|
+
while (offset < end) {
|
|
332
|
+
const digit = "0123456789abcdef".indexOf(format[offset].toLowerCase());
|
|
333
|
+
if (digit < 0 || digit >= radix) break;
|
|
334
|
+
value = value * radix + digit;
|
|
335
|
+
offset++;
|
|
336
|
+
}
|
|
337
|
+
if (offset === start) {
|
|
338
|
+
append(format[index++]);
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
append(Uint8Array.of(value));
|
|
342
|
+
index = offset;
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
if (format[index] !== "%") {
|
|
346
|
+
const point = String.fromCodePoint(format.codePointAt(index));
|
|
347
|
+
append(point);
|
|
348
|
+
index += point.length;
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
const parsed = directive(format, index);
|
|
352
|
+
index += parsed.length;
|
|
353
|
+
const { code, flags } = parsed;
|
|
354
|
+
const width = Number(parsed.width || 0);
|
|
355
|
+
if (!Number.isSafeInteger(width) || width > limit) throw new FsError("EFBIG", { message: "stat format width limit exceeded" });
|
|
356
|
+
const epochCode = !filesystem && ["X", "Y", "Z", "W"].includes(code);
|
|
357
|
+
const precision = parsed.precision === void 0 ? void 0 : Number(parsed.precision || (epochCode ? 9 : 0));
|
|
358
|
+
if (precision !== void 0 && (!Number.isSafeInteger(precision) || precision > limit)) throw new FsError("EFBIG", { message: "stat format precision limit exceeded" });
|
|
359
|
+
if (code === "%" && parsed.length !== 2) throw new UsageError("invalid stat format directive");
|
|
360
|
+
if (filesystem) {
|
|
361
|
+
let text2;
|
|
362
|
+
if (code === "n") text2 = name;
|
|
363
|
+
else if (code === "%") text2 = "%";
|
|
364
|
+
else if (code === "T") {
|
|
365
|
+
if (stat.filesystemType === void 0) throw new FsError("ENOTSUP", { syscall: "stat", message: "filesystem does not expose its type" });
|
|
366
|
+
if (typeof stat.filesystemType !== "string" || stat.filesystemType.length === 0) throw new FsError("EIO", { syscall: "stat", message: "invalid filesystem type" });
|
|
367
|
+
text2 = stat.filesystemType;
|
|
368
|
+
} else throw new FsError("ENOTSUP", { message: `unsupported filesystem stat format: %${code}` });
|
|
369
|
+
append(formatField(text2, code, flags, width, precision, false, false));
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
let text;
|
|
373
|
+
let linkText;
|
|
374
|
+
let numeric = false;
|
|
375
|
+
if (["a", "A", "f"].includes(code)) available(stat.mode, "mode");
|
|
376
|
+
const times = { X: stat.atimeMs, Y: stat.mtimeMs, Z: stat.ctimeMs, W: stat.birthtimeMs };
|
|
377
|
+
if (Object.hasOwn(times, code)) {
|
|
378
|
+
text = terse && times[code] === void 0 ? "?" : epoch(available(times[code], code), precision ?? 0);
|
|
379
|
+
numeric = text !== "?";
|
|
380
|
+
} else if (code === "n") text = name;
|
|
381
|
+
else if (code === "N") {
|
|
382
|
+
text = quoted(name, quotingStyle);
|
|
383
|
+
if (stat.type === "symlink") {
|
|
384
|
+
if (stat.target === void 0) throw new FsError("ENOTSUP", { syscall: "readlink", path });
|
|
385
|
+
linkText = quoted(stat.target, quotingStyle);
|
|
386
|
+
}
|
|
387
|
+
} else if (code === "%") text = "%";
|
|
388
|
+
else if (code === "A") text = permissionString(stat.mode, stat.type);
|
|
389
|
+
else if (code === "U") text = available(stat.uid, "u") === 0 ? "root" : String(stat.uid);
|
|
390
|
+
else if (code === "G") text = available(stat.gid, "g") === 0 ? "root" : String(stat.gid);
|
|
391
|
+
else if (code === "m") text = "/";
|
|
392
|
+
else if (code === "F") text = stat.type === "directory" ? "directory" : stat.type === "symlink" ? "symbolic link" : stat.type === "character" ? "character special file" : stat.size === 0 ? "regular empty file" : "regular file";
|
|
393
|
+
else if (["x", "y", "z", "w"].includes(code)) {
|
|
394
|
+
const value = times[code.toUpperCase()];
|
|
395
|
+
text = code === "w" && value === void 0 ? "-" : timestamp(available(value, code));
|
|
396
|
+
} else {
|
|
397
|
+
const fields = {
|
|
398
|
+
s: stat.size,
|
|
399
|
+
a: stat.mode & 4095,
|
|
400
|
+
f: stat.mode,
|
|
401
|
+
i: stat.ino,
|
|
402
|
+
h: stat.nlink,
|
|
403
|
+
u: stat.uid,
|
|
404
|
+
g: stat.gid,
|
|
405
|
+
d: stat.dev,
|
|
406
|
+
D: stat.dev,
|
|
407
|
+
B: 512,
|
|
408
|
+
b: stat.allocatedBytes === void 0 ? void 0 : Math.ceil(stat.allocatedBytes / 512),
|
|
409
|
+
o: stat.ioBlockSize,
|
|
410
|
+
t: stat.rdevMajor,
|
|
411
|
+
T: stat.rdevMinor
|
|
412
|
+
};
|
|
413
|
+
if (!Object.hasOwn(fields, code)) throw new FsError("ENOTSUP", { message: `unsupported stat format: %${code}` });
|
|
414
|
+
const value = fields[code];
|
|
415
|
+
text = terse && value === void 0 ? "?" : available(value, code).toString(code === "a" ? 8 : ["f", "D", "t", "T"].includes(code) ? 16 : 10);
|
|
416
|
+
numeric = text !== "?";
|
|
417
|
+
}
|
|
418
|
+
append(formatField(text, code, flags, width, precision, numeric, epochCode));
|
|
419
|
+
if (linkText !== void 0) {
|
|
420
|
+
append(" -> ");
|
|
421
|
+
append(formatField(linkText, code, flags, width, precision, false, false));
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
return concatBytes(chunks);
|
|
425
|
+
}
|
|
426
|
+
function resolveSyncStatPath(cwd, target) {
|
|
427
|
+
const raw = target.startsWith("/") ? target : cwd.endsWith("/") ? cwd + target : `${cwd}/${target}`;
|
|
428
|
+
const parts = raw.split("/");
|
|
429
|
+
const stack = [];
|
|
430
|
+
for (const part of parts) {
|
|
431
|
+
if (!part || part === ".") continue;
|
|
432
|
+
if (part === "..") stack.pop();
|
|
433
|
+
else stack.push(part);
|
|
434
|
+
}
|
|
435
|
+
return "/" + stack.join("/");
|
|
436
|
+
}
|
|
437
|
+
function evalSyncStat(args, cwd, quotingStyle, inspectStat) {
|
|
438
|
+
let parsed;
|
|
439
|
+
try {
|
|
440
|
+
parsed = parse(args);
|
|
441
|
+
} catch {
|
|
442
|
+
return void 0;
|
|
443
|
+
}
|
|
444
|
+
const outChunks = [];
|
|
445
|
+
for (const name of parsed.paths) {
|
|
446
|
+
if (!name) return void 0;
|
|
447
|
+
const abs = resolveSyncStatPath(cwd, name);
|
|
448
|
+
const stat = inspectStat(abs, parsed.follow || parsed.filesystem);
|
|
449
|
+
if (!stat) return void 0;
|
|
450
|
+
const terse = parsed.terse && parsed.format === void 0;
|
|
451
|
+
if (terse && parsed.filesystem) return void 0;
|
|
452
|
+
const format = parsed.format ?? (parsed.filesystem ? " File: %n\n Type: %T" : terse ? "%n %s %b %f %u %g %D %i %h %t %T %X %Y %Z %W %o" : " File: %N\n Size: %s Type: %F\n Mode: %a (%A)\nAccess: %x\nModify: %y\nChange: %z\n Birth: %w");
|
|
453
|
+
try {
|
|
454
|
+
const rendered = renderSync(abs, name, stat, format, parsed.printf, 262144, parsed.filesystem, terse, quotingStyle);
|
|
455
|
+
outChunks.push(parsed.printf ? rendered : concatBytes([rendered, Uint8Array.of(10)]));
|
|
456
|
+
} catch {
|
|
457
|
+
return void 0;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
return syncStatDecoder.decode(concatBytes(outChunks));
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
export {
|
|
464
|
+
createStatCommand,
|
|
465
|
+
evalSyncStat
|
|
466
|
+
};
|
|
@@ -95,17 +95,19 @@ function createSyncSingleChunkByteSource(bytes, signal) {
|
|
|
95
95
|
function requiredFileInput(context, requirements, mode, file, maxBytes) {
|
|
96
96
|
if (maxBytes === Infinity && (context.inputBudget?.maxBytes ?? Infinity) === Infinity) {
|
|
97
97
|
const fastMemFs = context._fastMemoryBackingFs;
|
|
98
|
-
if (fastMemFs !== void 0 && fastMemFs.capabilitiesFor === void 0 &&
|
|
98
|
+
if (fastMemFs !== void 0 && fastMemFs.capabilitiesFor === void 0 && !Object.prototype.hasOwnProperty.call(fastMemFs, "readStream") && !Object.prototype.hasOwnProperty.call(fastMemFs, "readFile")) {
|
|
99
99
|
const path2 = pathOf(context, file);
|
|
100
100
|
if (path2 !== "/dev" && !path2.startsWith("/dev/")) {
|
|
101
|
+
let bytes;
|
|
101
102
|
try {
|
|
102
|
-
|
|
103
|
-
if (bytes !== void 0) {
|
|
104
|
-
context._chargeFastFsOp?.();
|
|
105
|
-
return createSyncSingleChunkByteSource(bytes, context.signal);
|
|
106
|
-
}
|
|
103
|
+
bytes = tryReadMemoryFileViewSync(fastMemFs, path2, void 0, context.signal);
|
|
107
104
|
} catch {
|
|
108
105
|
}
|
|
106
|
+
if (bytes !== void 0) {
|
|
107
|
+
context.inputBudget?.check(bytes.byteLength);
|
|
108
|
+
context._chargeFastFsOp?.();
|
|
109
|
+
return createSyncSingleChunkByteSource(bytes, context.signal);
|
|
110
|
+
}
|
|
109
111
|
}
|
|
110
112
|
}
|
|
111
113
|
const path = pathOf(context, file);
|
|
@@ -135,9 +137,9 @@ async function* requiredFileInputSlow(context, requirements, mode, file, maxByte
|
|
|
135
137
|
try {
|
|
136
138
|
for await (const chunk of readBytes(context.fs.readStream(path, { signal: context.signal }), context.signal)) {
|
|
137
139
|
reading = false;
|
|
140
|
+
context.inputBudget?.check(bytes + chunk.byteLength);
|
|
138
141
|
if (chunk.byteLength > maxBytes - bytes) throw new FsError("EFBIG", { syscall: "read", path, message: "input file byte limit exceeded" });
|
|
139
142
|
bytes += chunk.byteLength;
|
|
140
|
-
context.inputBudget?.check(bytes);
|
|
141
143
|
if (chunk.byteLength) emitted = true;
|
|
142
144
|
yield chunk;
|
|
143
145
|
reading = true;
|
|
@@ -167,7 +167,7 @@ function tryExecuteJqFastSync(context, limits) {
|
|
|
167
167
|
const syncSink = typeof context.stdout.writeSync === "function" ? context.stdout : void 0;
|
|
168
168
|
if (!syncSink) return void 0;
|
|
169
169
|
const fastMemFs = context._fastMemoryBackingFs;
|
|
170
|
-
if (!fastMemFs || fastMemFs.capabilitiesFor !== void 0 ||
|
|
170
|
+
if (!fastMemFs || fastMemFs.capabilitiesFor !== void 0 || Object.prototype.hasOwnProperty.call(fastMemFs, "readStream") || Object.prototype.hasOwnProperty.call(fastMemFs, "readFile")) {
|
|
171
171
|
return void 0;
|
|
172
172
|
}
|
|
173
173
|
const absolute = file.charCodeAt(0) === 47 && file.length > 1 && file.charCodeAt(file.length - 1) !== 47 && !file.includes("//") && !file.includes("/.") ? file : pathOf(context, file);
|
|
@@ -178,6 +178,7 @@ function tryExecuteJqFastSync(context, limits) {
|
|
|
178
178
|
} catch {
|
|
179
179
|
return void 0;
|
|
180
180
|
}
|
|
181
|
+
if (rawBytes !== void 0) context.inputBudget?.check(rawBytes.byteLength);
|
|
181
182
|
if (!rawBytes || rawBytes.byteLength === 0 || rawBytes[0] !== 123 || rawBytes[rawBytes.byteLength - 1] !== 10) {
|
|
182
183
|
return void 0;
|
|
183
184
|
}
|
|
@@ -661,23 +662,25 @@ function inputs(context, options, budget, convert, onValue, onChunkEnd, hasPendi
|
|
|
661
662
|
const file = options.files[0];
|
|
662
663
|
const absolute = pathOf(context, file);
|
|
663
664
|
const fastMemFs = context._fastMemoryBackingFs;
|
|
664
|
-
if (fastMemFs !== void 0 && fastMemFs.capabilitiesFor === void 0 &&
|
|
665
|
+
if (fastMemFs !== void 0 && fastMemFs.capabilitiesFor === void 0 && absolute !== "/dev" && !absolute.startsWith("/dev/") && !Object.prototype.hasOwnProperty.call(fastMemFs, "readStream") && !Object.prototype.hasOwnProperty.call(fastMemFs, "readFile")) {
|
|
666
|
+
let rawBytes;
|
|
665
667
|
try {
|
|
666
|
-
|
|
667
|
-
if (rawBytes !== void 0) {
|
|
668
|
-
const tickPromise = budget.tickSync();
|
|
669
|
-
if (tickPromise) {
|
|
670
|
-
return (async function* () {
|
|
671
|
-
await tickPromise;
|
|
672
|
-
yield* inputs(context, options, budget, convert, onValue, onChunkEnd, hasPendingDiagnostics, retainValues);
|
|
673
|
-
})();
|
|
674
|
-
}
|
|
675
|
-
context._chargeFastFsOp?.();
|
|
676
|
-
budget.inputLocation = { name: file, line: 0, complete: false };
|
|
677
|
-
source = createSyncSingleChunkByteSource(rawBytes, context.signal);
|
|
678
|
-
}
|
|
668
|
+
rawBytes = tryReadMemoryFileViewSync(fastMemFs, absolute, void 0, context.signal);
|
|
679
669
|
} catch {
|
|
680
670
|
}
|
|
671
|
+
if (rawBytes !== void 0) {
|
|
672
|
+
context.inputBudget?.check(rawBytes.byteLength);
|
|
673
|
+
const tickPromise = budget.tickSync();
|
|
674
|
+
if (tickPromise) {
|
|
675
|
+
return (async function* () {
|
|
676
|
+
await tickPromise;
|
|
677
|
+
yield* inputs(context, options, budget, convert, onValue, onChunkEnd, hasPendingDiagnostics, retainValues);
|
|
678
|
+
})();
|
|
679
|
+
}
|
|
680
|
+
context._chargeFastFsOp?.();
|
|
681
|
+
budget.inputLocation = { name: file, line: 0, complete: false };
|
|
682
|
+
source = createSyncSingleChunkByteSource(rawBytes, context.signal);
|
|
683
|
+
}
|
|
681
684
|
}
|
|
682
685
|
if (source === void 0) {
|
|
683
686
|
const backing = getRuntimeBackingFileSystem(context.fs);
|
|
@@ -79,7 +79,7 @@ function createOptionsParser(profiles2) {
|
|
|
79
79
|
} else {
|
|
80
80
|
if (!supplied || ![...supplied].every((character) => character >= "0" && character <= "9") || !Number.isSafeInteger(Number(supplied))) throw new UsageError(`invalid --${name} value`);
|
|
81
81
|
const number = Number(supplied);
|
|
82
|
-
if (name === "threads" && number !== 1) throw new UsageError("only --threads=1 is supported by the single-threaded Zstandard codec");
|
|
82
|
+
if (name === "threads" && number !== 0 && number !== 1) throw new UsageError("only --threads=0 or --threads=1 is supported by the single-threaded Zstandard codec");
|
|
83
83
|
if (name === "long") {
|
|
84
84
|
if (number < 10 || number > 30) throw new UsageError("long-distance matching requires a window log from 10 through 30");
|
|
85
85
|
result.zstd.window = number;
|
|
@@ -208,7 +208,7 @@ function createOptionsParser(profiles2) {
|
|
|
208
208
|
}
|
|
209
209
|
if (argument === "--threads" || argument.startsWith("--threads=")) {
|
|
210
210
|
const threads = argument === "--threads" ? args[++index] : argument.slice("--threads=".length);
|
|
211
|
-
if (threads !== "1") throw new UsageError("only --threads=1 is supported by the single-threaded XZ codec");
|
|
211
|
+
if (threads !== "0" && threads !== "1") throw new UsageError("only --threads=0 or --threads=1 is supported by the single-threaded XZ codec");
|
|
212
212
|
continue;
|
|
213
213
|
}
|
|
214
214
|
}
|
|
@@ -254,7 +254,7 @@ function createOptionsParser(profiles2) {
|
|
|
254
254
|
case "T": {
|
|
255
255
|
if (profile.format !== "xz" && profile.format !== "zstd") throw new UsageError(`invalid option -- '${flag}'`);
|
|
256
256
|
const threads = flags.slice(offset + 1) || args[++index];
|
|
257
|
-
if (threads !== "1") throw new UsageError(`only --threads=1 is supported by the single-threaded ${profile.format} codec`);
|
|
257
|
+
if (threads !== "0" && threads !== "1") throw new UsageError(`only --threads=0 or --threads=1 is supported by the single-threaded ${profile.format} codec`);
|
|
258
258
|
offset = flags.length;
|
|
259
259
|
break;
|
|
260
260
|
}
|
|
@@ -1054,7 +1054,7 @@ function tryExecutePairFastSync(program, context, file, quiet, budget, separator
|
|
|
1054
1054
|
const stdoutSync = typeof context.stdout.writeSync === "function" ? context.stdout : void 0;
|
|
1055
1055
|
if (!stdoutSync) return void 0;
|
|
1056
1056
|
const fastMem = context._fastMemoryBackingFs;
|
|
1057
|
-
if (!fastMem || fastMem.capabilitiesFor !== void 0 ||
|
|
1057
|
+
if (!fastMem || fastMem.capabilitiesFor !== void 0 || Object.prototype.hasOwnProperty.call(fastMem, "readStream") || Object.prototype.hasOwnProperty.call(fastMem, "readFile")) {
|
|
1058
1058
|
return void 0;
|
|
1059
1059
|
}
|
|
1060
1060
|
const path = pathOf(context, file);
|
|
@@ -1066,6 +1066,7 @@ function tryExecutePairFastSync(program, context, file, quiet, budget, separator
|
|
|
1066
1066
|
console.error("SED_SYNC_ERR:", e);
|
|
1067
1067
|
return void 0;
|
|
1068
1068
|
}
|
|
1069
|
+
if (rawBytes !== void 0) context.inputBudget?.check(rawBytes.byteLength);
|
|
1069
1070
|
if (!rawBytes || rawBytes.byteLength < 256) return void 0;
|
|
1070
1071
|
const cachedBatch = getCachedLatin1Batch(rawBytes);
|
|
1071
1072
|
if (!cachedBatch || cachedBatch.lastLineStart !== cachedBatch.text.length || cachedBatch.maxLineLen > budget.maxBufferBytes) {
|