sandboxedjs 0.1.11 → 0.1.12

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 CHANGED
@@ -620,6 +620,20 @@ Two ways in, both byte-exact:
620
620
  await box.fs.writeFile("/workspace/uploads/clip.mp4", bytes); // creates missing directories
621
621
  ```
622
622
 
623
+ The `File` returned by a browser picker can be passed directly too. It is read
624
+ as bytes and written at the exact container path, including an application-
625
+ generated temporary path:
626
+
627
+ ```js
628
+ const picked = input.files[0];
629
+ const sourcePath = "/tmp/transcribe-quran-52fjch/source-1786307713702-baleela.f32le";
630
+ await box.fs.writeFile(sourcePath, picked);
631
+ ```
632
+
633
+ Do not pass `picked.path` (or any other host path) to a command in the
634
+ container. Browser file pickers provide file data, not a path the sandbox can
635
+ see.
636
+
623
637
  ```js
624
638
  // 2. Through a server running inside the container — a picker in the previewed
625
639
  // app posting to its own backend. Publish the port and upload normally.
package/dist/index.cjs CHANGED
@@ -23480,6 +23480,14 @@ function installUserland(kernel) {
23480
23480
 
23481
23481
  // src/container/fs.ts
23482
23482
  init_path();
23483
+ async function bytesFor(data) {
23484
+ if (data instanceof Uint8Array) return data;
23485
+ if (data instanceof ArrayBuffer) return new Uint8Array(data);
23486
+ if (ArrayBuffer.isView(data)) {
23487
+ return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
23488
+ }
23489
+ return new Uint8Array(await data.arrayBuffer());
23490
+ }
23483
23491
  var ContainerFs = class {
23484
23492
  constructor(kernel) {
23485
23493
  this.kernel = kernel;
@@ -23496,10 +23504,12 @@ var ContainerFs = class {
23496
23504
  const abs = clean(path);
23497
23505
  const parent = dirname(abs);
23498
23506
  if (!this.vfs.lexists(parent)) this.vfs.mkdir(parent, { recursive: true, mode: 493 });
23499
- this.vfs.writeFile(abs, data, { privileged: true, mode: opts.mode ?? 420 });
23507
+ const content = typeof data === "string" ? data : await bytesFor(data);
23508
+ this.vfs.writeFile(abs, content, { privileged: true, mode: opts.mode ?? 420 });
23500
23509
  }
23501
23510
  async appendFile(path, data) {
23502
- this.vfs.appendFile(clean(path), data, { privileged: true });
23511
+ const content = typeof data === "string" ? data : await bytesFor(data);
23512
+ this.vfs.appendFile(clean(path), content, { privileged: true });
23503
23513
  }
23504
23514
  async readdir(path, opts) {
23505
23515
  if (opts?.withFileTypes) return this.vfs.readdirWithTypes(clean(path));