MCPcopy Create free account
hub / github.com/cloudflare/computer / chunksOf

Function chunksOf

packages/dofs/src/fs/writeFile.ts:102–113  ·  view source on GitHub ↗
(bytes: Uint8Array)

Source from the content-addressed store, hash-verified

100}
101
102export function chunksOf(bytes: Uint8Array): PreparedChunk[] {
103 const chunks: PreparedChunk[] = [];
104 for (let offset = 0; offset < bytes.byteLength; offset += CHUNK_SIZE) {
105 const end = Math.min(offset + CHUNK_SIZE, bytes.byteLength);
106 // subarray (not slice) avoids an extra copy; sha256() takes its own
107 // copy when needed.
108 const slice = bytes.subarray(offset, end);
109 const hash = sha256(slice);
110 chunks.push({ hash, bytes: slice, size: slice.byteLength });
111 }
112 return chunks;
113}
114
115export async function writeFile(
116 db: Database,

Callers 1

writeFileSyncFunction · 0.85

Calls 2

sha256Function · 0.70
pushMethod · 0.65

Tested by

no test coverage detected