(bytes: Uint8Array)
| 100 | } |
| 101 | |
| 102 | export 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 | |
| 115 | export async function writeFile( |
| 116 | db: Database, |
no test coverage detected