| 1372 | } |
| 1373 | |
| 1374 | body(chunk: Uint8Array): void { |
| 1375 | const header = this.header! |
| 1376 | this.written += chunk.length |
| 1377 | if (this.written > header.size) { |
| 1378 | throw sizeMismatch(header, this.written) |
| 1379 | } |
| 1380 | if (chunk.length < COPY_LIMIT) { |
| 1381 | // `reserve` can start a new slab, so it must run before `slab` is read |
| 1382 | const offset = this.reserve(chunk.length) |
| 1383 | this.slab.set(chunk, offset) |
| 1384 | return |
| 1385 | } |
| 1386 | this.cut() |
| 1387 | this.chunks.push(chunk) |
| 1388 | this.buffered += chunk.length |
| 1389 | } |
| 1390 | |
| 1391 | end(): void { |
| 1392 | const header = this.header! |