MCPcopy Create free account
hub / github.com/cloudflare/agents / writeFileStream

Method writeFileStream

packages/shell/src/filesystem.ts:907–936  ·  view source on GitHub ↗
(
    path: string,
    stream: ReadableStream<Uint8Array>,
    mimeType = "application/octet-stream"
  )

Source from the content-addressed store, hash-verified

905 }
906
907 async writeFileStream(
908 path: string,
909 stream: ReadableStream<Uint8Array>,
910 mimeType = "application/octet-stream"
911 ): Promise<void> {
912 const reader = stream.getReader();
913 const chunks: Uint8Array[] = [];
914 let totalSize = 0;
915 for (;;) {
916 const { done, value } = await reader.read();
917 if (done) break;
918 totalSize += value.byteLength;
919 if (totalSize > MAX_STREAM_SIZE) {
920 reader.cancel();
921 throw new Error(
922 `EFBIG: stream exceeds maximum size of ${MAX_STREAM_SIZE} bytes`
923 );
924 }
925 chunks.push(value);
926 }
927
928 const buffer = new Uint8Array(totalSize);
929 let offset = 0;
930 for (const chunk of chunks) {
931 buffer.set(chunk, offset);
932 offset += chunk.byteLength;
933 }
934
935 await this.writeFileBytes(path, buffer, mimeType);
936 }
937
938 async appendFile(
939 path: string,

Callers 2

writeStreamMethod · 0.80
writeStreamBytesMethod · 0.80

Calls 5

writeFileBytesMethod · 0.95
getReaderMethod · 0.80
readMethod · 0.65
cancelMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected