@poe-platform/safe-bash 0.1.81 → 0.1.82
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/safe-bash/browser.js +47 -24
- package/dist/safe-bash/browser.js.map +4 -4
- package/dist/safe-bash/commands/sort-admission.d.ts +6 -0
- package/dist/safe-bash/commands/sort-admission.d.ts.map +1 -0
- package/dist/safe-bash/commands/sort-admission.js +16 -0
- package/dist/safe-bash/commands/sort-admission.js.map +1 -0
- package/dist/safe-bash/commands/text.d.ts.map +1 -1
- package/dist/safe-bash/commands/text.js +33 -27
- package/dist/safe-bash/commands/text.js.map +1 -1
- package/package.json +2 -2
|
@@ -4653,6 +4653,23 @@ function streamCommands() {
|
|
|
4653
4653
|
|
|
4654
4654
|
// packages/safe-bash/src/commands/text.ts
|
|
4655
4655
|
init_platform();
|
|
4656
|
+
|
|
4657
|
+
// packages/safe-bash/src/commands/sort-admission.ts
|
|
4658
|
+
init_platform();
|
|
4659
|
+
var SortRecordBudget = class {
|
|
4660
|
+
#records = 0;
|
|
4661
|
+
#bytes = 0;
|
|
4662
|
+
admit(byteLength2) {
|
|
4663
|
+
const bytes2 = byteLength2 + 1;
|
|
4664
|
+
if (this.#records >= 1e5 || bytes2 > bufferLimit - this.#bytes) {
|
|
4665
|
+
throw new FsError("EFBIG", { message: "sort buffer limit exceeded" });
|
|
4666
|
+
}
|
|
4667
|
+
this.#records++;
|
|
4668
|
+
this.#bytes += bytes2;
|
|
4669
|
+
}
|
|
4670
|
+
};
|
|
4671
|
+
|
|
4672
|
+
// packages/safe-bash/src/commands/text.ts
|
|
4656
4673
|
var SortWork = class {
|
|
4657
4674
|
constructor(signal) {
|
|
4658
4675
|
this.signal = signal;
|
|
@@ -4921,20 +4938,25 @@ async function emitRecords(context, records, destination) {
|
|
|
4921
4938
|
await context.fs.writeFile(pathOf(context, destination), concatenate(chunks, size), { signal: context.signal });
|
|
4922
4939
|
}
|
|
4923
4940
|
}
|
|
4924
|
-
async function collectSortRecords(source, delimiter, accept) {
|
|
4941
|
+
async function collectSortRecords(source, delimiter, budget, signal, accept) {
|
|
4925
4942
|
let pending = [];
|
|
4926
4943
|
let size = 0;
|
|
4927
4944
|
for await (const chunk of source) {
|
|
4928
4945
|
let start = 0;
|
|
4929
4946
|
for (let offset = 0; offset < chunk.length; offset++) {
|
|
4930
4947
|
if (chunk[offset] !== delimiter) continue;
|
|
4931
|
-
|
|
4932
|
-
size += part.length;
|
|
4948
|
+
size += offset - start;
|
|
4933
4949
|
if (size > bufferLimit) throw new FsError("EFBIG", { message: "line buffer limit exceeded" });
|
|
4950
|
+
signal.throwIfAborted();
|
|
4951
|
+
budget.admit(size);
|
|
4952
|
+
const part = chunk.subarray(start, offset);
|
|
4953
|
+
let record4;
|
|
4934
4954
|
if (pending.length) {
|
|
4935
4955
|
pending.push(part);
|
|
4936
|
-
|
|
4937
|
-
} else
|
|
4956
|
+
record4 = concatenate(pending, size);
|
|
4957
|
+
} else record4 = new Uint8Array(part);
|
|
4958
|
+
const accepted = accept(record4);
|
|
4959
|
+
if ((accepted instanceof Promise ? await accepted : accepted) === false) return false;
|
|
4938
4960
|
pending = [];
|
|
4939
4961
|
size = 0;
|
|
4940
4962
|
start = offset + 1;
|
|
@@ -4945,7 +4967,12 @@ async function collectSortRecords(source, delimiter, accept) {
|
|
|
4945
4967
|
if (size > bufferLimit) throw new FsError("EFBIG", { message: "line buffer limit exceeded" });
|
|
4946
4968
|
}
|
|
4947
4969
|
}
|
|
4948
|
-
if (size)
|
|
4970
|
+
if (size) {
|
|
4971
|
+
signal.throwIfAborted();
|
|
4972
|
+
budget.admit(size);
|
|
4973
|
+
return await accept(concatenate(pending, size)) !== false;
|
|
4974
|
+
}
|
|
4975
|
+
return true;
|
|
4949
4976
|
}
|
|
4950
4977
|
function textCommands() {
|
|
4951
4978
|
return [
|
|
@@ -5037,30 +5064,26 @@ function textCommands() {
|
|
|
5037
5064
|
return result || (simple || parsed.flags.has("s") || parsed.flags.has("u") ? 0 : await compareSortBytes(left, right, work) * direction);
|
|
5038
5065
|
};
|
|
5039
5066
|
const records = [];
|
|
5040
|
-
|
|
5067
|
+
const recordBudget = new SortRecordBudget();
|
|
5041
5068
|
const exitCode = 0;
|
|
5042
5069
|
const delimiter = parsed.flags.has("z") ? 0 : 10;
|
|
5043
5070
|
for (const name2 of parsed.operands.length ? parsed.operands : ["-"]) {
|
|
5044
5071
|
try {
|
|
5045
|
-
|
|
5046
|
-
await collectSortRecords(input(context, name2), delimiter, (bytes2) => {
|
|
5047
|
-
context.signal.throwIfAborted();
|
|
5048
|
-
size += bytes2.length + 1;
|
|
5049
|
-
if (size > bufferLimit) throw new FsError("EFBIG", { message: "sort buffer limit exceeded" });
|
|
5050
|
-
records.push(bytes2);
|
|
5051
|
-
});
|
|
5052
|
-
continue;
|
|
5053
|
-
}
|
|
5054
|
-
for await (const line of lines(input(context, name2), delimiter)) {
|
|
5072
|
+
const complete2 = await collectSortRecords(input(context, name2), delimiter, recordBudget, context.signal, (bytes2) => {
|
|
5055
5073
|
context.signal.throwIfAborted();
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
await diagnostic(context, new Error(`disorder at record ${records.length + 1}`));
|
|
5060
|
-
return { exitCode: 1 };
|
|
5074
|
+
if (!parsed.flags.has("c")) {
|
|
5075
|
+
records.push(bytes2);
|
|
5076
|
+
return;
|
|
5061
5077
|
}
|
|
5062
|
-
|
|
5063
|
-
|
|
5078
|
+
return (async () => {
|
|
5079
|
+
if (records.length && (await compare(records.at(-1), bytes2) > 0 || parsed.flags.has("u") && await keyCompare(records.at(-1), bytes2) === 0)) {
|
|
5080
|
+
await diagnostic(context, new Error(`disorder at record ${records.length + 1}`));
|
|
5081
|
+
return false;
|
|
5082
|
+
}
|
|
5083
|
+
records.push(bytes2);
|
|
5084
|
+
})();
|
|
5085
|
+
});
|
|
5086
|
+
if (!complete2) return { exitCode: 1 };
|
|
5064
5087
|
} catch (error) {
|
|
5065
5088
|
await diagnostic(context, error);
|
|
5066
5089
|
return { exitCode: 2 };
|