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

Function transformBytes

packages/shell/src/extras.ts:458–472  ·  view source on GitHub ↗
(
  bytes: Uint8Array,
  stream: CompressionStream | DecompressionStream
)

Source from the content-addressed store, hash-verified

456}
457
458async function transformBytes(
459 bytes: Uint8Array,
460 stream: CompressionStream | DecompressionStream
461): Promise<Uint8Array> {
462 const input = new Blob([new Uint8Array(bytes)]).stream();
463 const transformed = input.pipeThrough(stream);
464 const chunks: Uint8Array[] = [];
465 const reader = transformed.getReader();
466 for (;;) {
467 const { done, value } = await reader.read();
468 if (done) break;
469 chunks.push(value);
470 }
471 return concatBytes(chunks);
472}
473
474function concatBytes(chunks: Uint8Array[]): Uint8Array {
475 const total = chunks.reduce((sum, chunk) => sum + chunk.byteLength, 0);

Callers 2

gzipBytesFunction · 0.85
gunzipBytesFunction · 0.85

Calls 4

concatBytesFunction · 0.85
pipeThroughMethod · 0.80
getReaderMethod · 0.80
readMethod · 0.65

Tested by

no test coverage detected