@poe-platform/safe-bash 0.1.82 → 0.1.83
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 +97 -54
- package/dist/safe-bash/browser.js.map +4 -4
- package/dist/safe-bash/commands/internal.d.ts +1 -1
- package/dist/safe-bash/commands/internal.d.ts.map +1 -1
- package/dist/safe-bash/commands/internal.js +18 -25
- package/dist/safe-bash/commands/internal.js.map +1 -1
- package/dist/safe-bash/commands/record-buffer.d.ts +11 -0
- package/dist/safe-bash/commands/record-buffer.d.ts.map +1 -0
- package/dist/safe-bash/commands/record-buffer.js +61 -0
- package/dist/safe-bash/commands/record-buffer.js.map +1 -0
- package/dist/safe-bash/commands/text.d.ts.map +1 -1
- package/dist/safe-bash/commands/text.js +23 -37
- package/dist/safe-bash/commands/text.js.map +1 -1
- package/package.json +2 -2
|
@@ -2623,6 +2623,69 @@ var predicateRequirements = [
|
|
|
2623
2623
|
{ id: "access", description: "Inspect path access permissions", capabilities: ["access"] }
|
|
2624
2624
|
];
|
|
2625
2625
|
|
|
2626
|
+
// packages/safe-bash/src/commands/record-buffer.ts
|
|
2627
|
+
init_platform();
|
|
2628
|
+
var segmentSize = 4096;
|
|
2629
|
+
var RecordBuffer = class {
|
|
2630
|
+
constructor(capacity, finalizationCapacity = capacity * 2) {
|
|
2631
|
+
this.capacity = capacity;
|
|
2632
|
+
this.finalizationCapacity = finalizationCapacity;
|
|
2633
|
+
}
|
|
2634
|
+
capacity;
|
|
2635
|
+
finalizationCapacity;
|
|
2636
|
+
#segments = [];
|
|
2637
|
+
#size = 0;
|
|
2638
|
+
#allocated = 0;
|
|
2639
|
+
get size() {
|
|
2640
|
+
return this.#size;
|
|
2641
|
+
}
|
|
2642
|
+
#admit(length) {
|
|
2643
|
+
if (length > this.capacity - this.#size) {
|
|
2644
|
+
throw new FsError("EFBIG", { message: "line buffer limit exceeded" });
|
|
2645
|
+
}
|
|
2646
|
+
}
|
|
2647
|
+
append(bytes2, start = 0, end = bytes2.length) {
|
|
2648
|
+
this.#admit(end - start);
|
|
2649
|
+
let offset = start;
|
|
2650
|
+
while (offset < end) {
|
|
2651
|
+
let segment = this.#segments.at(-1);
|
|
2652
|
+
const used = this.#size % segmentSize;
|
|
2653
|
+
if (!segment || used === 0) {
|
|
2654
|
+
segment = new Uint8Array(Math.min(segmentSize, this.capacity - this.#allocated));
|
|
2655
|
+
this.#segments.push(segment);
|
|
2656
|
+
this.#allocated += segment.length;
|
|
2657
|
+
}
|
|
2658
|
+
const length = Math.min(end - offset, segment.length - used);
|
|
2659
|
+
segment.set(bytes2.subarray(offset, offset + length), used);
|
|
2660
|
+
this.#size += length;
|
|
2661
|
+
offset += length;
|
|
2662
|
+
}
|
|
2663
|
+
}
|
|
2664
|
+
finish(admit2, bytes2, start = 0, end = bytes2?.length ?? 0) {
|
|
2665
|
+
this.#admit(end - start);
|
|
2666
|
+
const size = this.#size + end - start;
|
|
2667
|
+
admit2?.(size);
|
|
2668
|
+
if (size > this.finalizationCapacity - this.#allocated) {
|
|
2669
|
+
throw new FsError("EFBIG", { message: "line finalization buffer limit exceeded" });
|
|
2670
|
+
}
|
|
2671
|
+
const result = new Uint8Array(size);
|
|
2672
|
+
let offset = 0;
|
|
2673
|
+
for (const segment of this.#segments) {
|
|
2674
|
+
const length = Math.min(segment.length, this.#size - offset);
|
|
2675
|
+
result.set(segment.subarray(0, length), offset);
|
|
2676
|
+
offset += length;
|
|
2677
|
+
}
|
|
2678
|
+
if (bytes2 && end > start) result.set(bytes2.subarray(start, end), offset);
|
|
2679
|
+
this.clear();
|
|
2680
|
+
return result;
|
|
2681
|
+
}
|
|
2682
|
+
clear() {
|
|
2683
|
+
this.#segments = [];
|
|
2684
|
+
this.#size = 0;
|
|
2685
|
+
this.#allocated = 0;
|
|
2686
|
+
}
|
|
2687
|
+
};
|
|
2688
|
+
|
|
2626
2689
|
// packages/safe-bash/src/commands/internal.ts
|
|
2627
2690
|
var encoder2 = new TextEncoder();
|
|
2628
2691
|
var decoder2 = new TextDecoder();
|
|
@@ -2796,29 +2859,22 @@ function concatenate(chunks, size = chunks.reduce((sum, chunk) => sum + chunk.le
|
|
|
2796
2859
|
}
|
|
2797
2860
|
return result;
|
|
2798
2861
|
}
|
|
2799
|
-
async function* lines(source, separator = 10) {
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
pending.
|
|
2810
|
-
yield { bytes: concatenate(pending, size), terminated: true };
|
|
2811
|
-
pending = [];
|
|
2812
|
-
size = 0;
|
|
2813
|
-
start = offset + 1;
|
|
2814
|
-
}
|
|
2815
|
-
if (start < chunk.length) {
|
|
2816
|
-
pending.push(new Uint8Array(chunk.subarray(start)));
|
|
2817
|
-
size += chunk.length - start;
|
|
2818
|
-
if (size > bufferLimit) throw new FsError("EFBIG", { message: "line buffer limit exceeded" });
|
|
2862
|
+
async function* lines(source, separator = 10, admit2) {
|
|
2863
|
+
const pending = new RecordBuffer(bufferLimit);
|
|
2864
|
+
try {
|
|
2865
|
+
for await (const chunk of source) {
|
|
2866
|
+
let start = 0;
|
|
2867
|
+
for (let offset = 0; offset < chunk.length; offset++) {
|
|
2868
|
+
if (chunk[offset] !== separator) continue;
|
|
2869
|
+
yield { bytes: pending.finish(admit2, chunk, start, offset), terminated: true };
|
|
2870
|
+
start = offset + 1;
|
|
2871
|
+
}
|
|
2872
|
+
pending.append(chunk, start);
|
|
2819
2873
|
}
|
|
2874
|
+
if (pending.size) yield { bytes: pending.finish(admit2), terminated: false };
|
|
2875
|
+
} finally {
|
|
2876
|
+
pending.clear();
|
|
2820
2877
|
}
|
|
2821
|
-
if (size) yield { bytes: concatenate(pending, size), terminated: false };
|
|
2822
2878
|
}
|
|
2823
2879
|
function emptyInput() {
|
|
2824
2880
|
return toByteSource("");
|
|
@@ -4939,40 +4995,27 @@ async function emitRecords(context, records, destination) {
|
|
|
4939
4995
|
}
|
|
4940
4996
|
}
|
|
4941
4997
|
async function collectSortRecords(source, delimiter, budget, signal, accept) {
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
for await (const chunk of source) {
|
|
4945
|
-
let start = 0;
|
|
4946
|
-
for (let offset = 0; offset < chunk.length; offset++) {
|
|
4947
|
-
if (chunk[offset] !== delimiter) continue;
|
|
4948
|
-
size += offset - start;
|
|
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;
|
|
4954
|
-
if (pending.length) {
|
|
4955
|
-
pending.push(part);
|
|
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;
|
|
4960
|
-
pending = [];
|
|
4961
|
-
size = 0;
|
|
4962
|
-
start = offset + 1;
|
|
4963
|
-
}
|
|
4964
|
-
if (start < chunk.length) {
|
|
4965
|
-
pending.push(new Uint8Array(chunk.subarray(start)));
|
|
4966
|
-
size += chunk.length - start;
|
|
4967
|
-
if (size > bufferLimit) throw new FsError("EFBIG", { message: "line buffer limit exceeded" });
|
|
4968
|
-
}
|
|
4969
|
-
}
|
|
4970
|
-
if (size) {
|
|
4998
|
+
const pending = new RecordBuffer(bufferLimit);
|
|
4999
|
+
const admit2 = (length) => {
|
|
4971
5000
|
signal.throwIfAborted();
|
|
4972
|
-
budget.admit(
|
|
4973
|
-
|
|
5001
|
+
budget.admit(length);
|
|
5002
|
+
};
|
|
5003
|
+
try {
|
|
5004
|
+
for await (const chunk of source) {
|
|
5005
|
+
let start = 0;
|
|
5006
|
+
for (let offset = 0; offset < chunk.length; offset++) {
|
|
5007
|
+
if (chunk[offset] !== delimiter) continue;
|
|
5008
|
+
const accepted = accept(pending.finish(admit2, chunk, start, offset));
|
|
5009
|
+
if ((accepted instanceof Promise ? await accepted : accepted) === false) return false;
|
|
5010
|
+
start = offset + 1;
|
|
5011
|
+
}
|
|
5012
|
+
pending.append(chunk, start);
|
|
5013
|
+
}
|
|
5014
|
+
if (pending.size) return await accept(pending.finish(admit2)) !== false;
|
|
5015
|
+
return true;
|
|
5016
|
+
} finally {
|
|
5017
|
+
pending.clear();
|
|
4974
5018
|
}
|
|
4975
|
-
return true;
|
|
4976
5019
|
}
|
|
4977
5020
|
function textCommands() {
|
|
4978
5021
|
return [
|
|
@@ -5238,7 +5281,7 @@ function textCommands() {
|
|
|
5238
5281
|
if (start >= 0) await writer.write(line.bytes.subarray(start, end));
|
|
5239
5282
|
}
|
|
5240
5283
|
} else {
|
|
5241
|
-
const decoder3 = new TextDecoder();
|
|
5284
|
+
const decoder3 = new TextDecoder("utf-8", { ignoreBOM: true });
|
|
5242
5285
|
let index = 0;
|
|
5243
5286
|
let emitted = false;
|
|
5244
5287
|
let previousIncluded = false;
|