@cloudflare/sandbox 0.10.0 → 0.10.1

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.
@@ -2050,13 +2050,8 @@ var FileClient = class extends BaseHttpClient {
2050
2050
  };
2051
2051
  return await this.post("/api/write", data);
2052
2052
  }
2053
- /**
2054
- * Read content from a file
2055
- * @param path - File path to read from
2056
- * @param sessionId - The session ID for this operation
2057
- * @param options - Optional settings (encoding)
2058
- */
2059
2053
  async readFile(path$1, sessionId, options) {
2054
+ if (options?.encoding === "none") throw new Error("readFile with encoding: 'none' requires the rpc transport. Set SANDBOX_TRANSPORT=rpc.");
2060
2055
  const data = {
2061
2056
  path: path$1,
2062
2057
  sessionId,
@@ -2143,6 +2138,13 @@ var FileClient = class extends BaseHttpClient {
2143
2138
  };
2144
2139
  return await this.post("/api/exists", data);
2145
2140
  }
2141
+ /**
2142
+ * Write a file via a raw binary stream over the RPC transport.
2143
+ * Throws on HTTP and WebSocket transports — use writeFile() with a string instead.
2144
+ */
2145
+ writeFileStream(_path, _content, _sessionId) {
2146
+ throw new Error("writeFileStream requires the rpc transport. Set SANDBOX_TRANSPORT=rpc.");
2147
+ }
2146
2148
  };
2147
2149
 
2148
2150
  //#endregion
@@ -2706,16 +2708,6 @@ var SandboxClient = class {
2706
2708
  return this.transport?.isConnected() ?? false;
2707
2709
  }
2708
2710
  /**
2709
- * Stream a file directly to the container over a binary RPC channel.
2710
- *
2711
- * Requires the container-control path (`transport: 'rpc'`). Calling this
2712
- * method with the HTTP or WebSocket route transports throws an error because
2713
- * those transports do not support binary streaming.
2714
- */
2715
- writeFileStream(_path, _content, _sessionId) {
2716
- throw new Error("writeFileStream requires the RPC transport. Enable it with transport: \"rpc\" in sandbox options.");
2717
- }
2718
- /**
2719
2711
  * Connect WebSocket transport (no-op in HTTP mode)
2720
2712
  * Called automatically on first request, but can be called explicitly
2721
2713
  * to establish connection upfront.
@@ -3300,9 +3292,6 @@ var ContainerControlClient = class {
3300
3292
  disconnect() {
3301
3293
  this.destroyConnection();
3302
3294
  }
3303
- async writeFileStream(path$1, stream, sessionId) {
3304
- return this.files.writeFileStream(path$1, stream, sessionId);
3305
- }
3306
3295
  };
3307
3296
 
3308
3297
  //#endregion
@@ -4257,7 +4246,7 @@ function isLocalhostPattern(hostname) {
4257
4246
  * This file is auto-updated by .github/changeset-version.ts during releases
4258
4247
  * DO NOT EDIT MANUALLY - Changes will be overwritten on the next version bump
4259
4248
  */
4260
- const SDK_VERSION = "0.10.0";
4249
+ const SDK_VERSION = "0.10.1";
4261
4250
 
4262
4251
  //#endregion
4263
4252
  //#region src/sandbox.ts
@@ -6081,7 +6070,7 @@ var Sandbox = class Sandbox extends Container {
6081
6070
  }
6082
6071
  async writeFile(path$1, content, options = {}) {
6083
6072
  const session = options.sessionId ?? await this.ensureDefaultSession();
6084
- if (content instanceof ReadableStream) return this.client.writeFileStream(path$1, content, session);
6073
+ if (content instanceof ReadableStream) return this.client.files.writeFileStream(path$1, content, session);
6085
6074
  return this.client.files.writeFile(path$1, content, session, { encoding: options.encoding });
6086
6075
  }
6087
6076
  async deleteFile(path$1, sessionId) {
@@ -6098,6 +6087,7 @@ var Sandbox = class Sandbox extends Container {
6098
6087
  }
6099
6088
  async readFile(path$1, options = {}) {
6100
6089
  const session = options.sessionId ?? await this.ensureDefaultSession();
6090
+ if (options.encoding === "none") return this.client.files.readFile(path$1, session, { encoding: "none" });
6101
6091
  return this.client.files.readFile(path$1, session, { encoding: options.encoding });
6102
6092
  }
6103
6093
  /**
@@ -6472,9 +6462,16 @@ var Sandbox = class Sandbox extends Container {
6472
6462
  ...options,
6473
6463
  sessionId
6474
6464
  }),
6475
- readFile: (path$1, options) => this.readFile(path$1, {
6476
- ...options,
6477
- sessionId
6465
+ readFile: ((path$1, options) => {
6466
+ const encoding = options?.encoding;
6467
+ if (encoding === "none") return this.readFile(path$1, {
6468
+ encoding: "none",
6469
+ sessionId
6470
+ });
6471
+ return this.readFile(path$1, {
6472
+ encoding,
6473
+ sessionId
6474
+ });
6478
6475
  }),
6479
6476
  readFileStream: (path$1) => this.readFileStream(path$1, { sessionId }),
6480
6477
  watch: (path$1, options) => this.watch(path$1, {
@@ -7534,7 +7531,7 @@ var Sandbox = class Sandbox extends Container {
7534
7531
  },
7535
7532
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
7536
7533
  });
7537
- await this.client.writeFileStream(archivePath, body, backupSession);
7534
+ await this.client.files.writeFileStream(archivePath, body, backupSession);
7538
7535
  } else {
7539
7536
  const archiveBuffer = await archiveObject.arrayBuffer();
7540
7537
  const base64Content = Buffer.from(archiveBuffer).toString("base64");
@@ -7592,4 +7589,4 @@ var Sandbox = class Sandbox extends Container {
7592
7589
 
7593
7590
  //#endregion
7594
7591
  export { DesktopInvalidOptionsError as A, CommandClient as C, BackupNotFoundError as D, BackupExpiredError as E, InvalidBackupConfigError as F, ProcessExitedBeforeReadyError as I, ProcessReadyTimeoutError as L, DesktopProcessCrashedError as M, DesktopStartFailedError as N, BackupRestoreError as O, DesktopUnavailableError as P, RPCTransportError as R, DesktopClient as S, BackupCreateError as T, UtilityClient as _, BucketMountError as a, GitClient as b, MissingCredentialsError as c, parseSSEStream as d, responseToAsyncIterable as f, SandboxClient as g, streamFile as h, proxyTerminal as i, DesktopNotStartedError as j, DesktopInvalidCoordinatesError as k, S3FSMountError as l, collectFile as m, getSandbox as n, BucketUnmountError as o, CodeInterpreter as p, proxyToSandbox as r, InvalidMountConfigError as s, Sandbox as t, asyncIterableToSSEStream as u, ProcessClient as v, BackupClient as w, FileClient as x, PortClient as y, SessionTerminatedError as z };
7595
- //# sourceMappingURL=sandbox-2bHZZmy5.js.map
7592
+ //# sourceMappingURL=sandbox-uC1vzWtG.js.map