@poe-platform/safe-bash 0.1.77 → 0.1.78

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.
@@ -4045,6 +4045,26 @@ function bindFileOutputBudget(context, budget) {
4045
4045
  if (!context.registerCleanup) throw new TypeError("Shell output budgets require invocation cleanup ownership");
4046
4046
  filesystemOutputBudgets.set(context.registerCleanup, budget);
4047
4047
  }
4048
+ async function writeFileOutput(context, bytes2, write2) {
4049
+ context.signal.throwIfAborted();
4050
+ const budget = context.registerCleanup && filesystemOutputBudgets.get(context.registerCleanup);
4051
+ let pending;
4052
+ const destination = { write(chunk) {
4053
+ context.signal.throwIfAborted();
4054
+ return pending = (async () => {
4055
+ await write2(chunk);
4056
+ })();
4057
+ } };
4058
+ try {
4059
+ await (budget?.(destination) ?? destination).write(bytes2);
4060
+ } catch (error) {
4061
+ await pending?.catch(() => {
4062
+ });
4063
+ context.signal.throwIfAborted();
4064
+ throw error;
4065
+ }
4066
+ context.signal.throwIfAborted();
4067
+ }
4048
4068
  async function openFileOutput(context, path, flag, incremental) {
4049
4069
  let pipe;
4050
4070
  let task;
@@ -17544,7 +17564,7 @@ async function execute(program, context, files, quiet, budget) {
17544
17564
  appendedSize = 0;
17545
17565
  };
17546
17566
  const writeFile = async (file) => {
17547
- await context.fs.appendFile(virtualPath(context, file), bytes(pattern + "\n"), { signal: context.signal });
17567
+ await writeFileOutput(context, bytes(pattern + "\n"), (chunk) => context.fs.appendFile(virtualPath(context, file), chunk, { signal: context.signal }));
17548
17568
  };
17549
17569
  const matches = async (address) => address.kind === "number" ? number === address.number : address.kind === "last" ? (await peekNext()).done === true : getPattern(address.pattern).find(pattern, budget) !== void 0;
17550
17570
  for (let pc = 0; pc < program.length; ) {
@@ -17776,7 +17796,7 @@ function sedCommand(options3 = {}) {
17776
17796
  }
17777
17797
  const prepareOutputs = async () => {
17778
17798
  const paths = new Set(outputFiles.map((file) => virtualPath(context, file)));
17779
- for (const path of paths) await context.fs.writeFile(path, new Uint8Array(), { signal: context.signal });
17799
+ for (const path of paths) await writeFileOutput(context, new Uint8Array(), (chunk) => context.fs.writeFile(path, chunk, { signal: context.signal }));
17780
17800
  };
17781
17801
  if (inPlace !== void 0) {
17782
17802
  if (!files.length || files.includes("-")) throw new ProgramError("in-place editing requires named files");
@@ -17796,7 +17816,7 @@ function sedCommand(options3 = {}) {
17796
17816
  const result = await execute(program, child, [file], quiet, budget);
17797
17817
  const path = virtualPath(context, file);
17798
17818
  if (inPlace) await context.fs.copyFile(path, path + inPlace, { signal: context.signal });
17799
- await context.fs.writeFile(path, bytes(rewritten), { signal: context.signal });
17819
+ await writeFileOutput(context, bytes(rewritten), (chunk) => context.fs.writeFile(path, chunk, { signal: context.signal }));
17800
17820
  if (result.quit || result.status) return result.status;
17801
17821
  }
17802
17822
  return 0;