(chunk)
| 315 | |
| 316 | return { |
| 317 | async write(chunk) { |
| 318 | if (aborted) throw new Error('Multipart upload already aborted') |
| 319 | if (firstError) throw firstError |
| 320 | const buf = typeof chunk === 'string' ? Buffer.from(chunk, 'utf8') : chunk |
| 321 | totalBytes += buf.length |
| 322 | pendingChunks.push(buf) |
| 323 | pendingBytes += buf.length |
| 324 | // Local storage has no multipart concept — accumulate and write once on complete. |
| 325 | if (!cloud) return |
| 326 | while (pendingBytes >= MULTIPART_PART_SIZE) { |
| 327 | const merged = drainPending() |
| 328 | const part = merged.subarray(0, MULTIPART_PART_SIZE) |
| 329 | const rest = merged.subarray(MULTIPART_PART_SIZE) |
| 330 | pendingChunks = rest.length ? [rest] : [] |
| 331 | pendingBytes = rest.length |
| 332 | await dispatchPart(part) |
| 333 | } |
| 334 | }, |
| 335 | async complete() { |
| 336 | try { |
| 337 | if (!backend) { |
nothing calls this directly
no test coverage detected