* Get the final ArrayBuffer containing all written data. * Merges all chunks into a single buffer.
()
| 97 | * Merges all chunks into a single buffer. |
| 98 | */ |
| 99 | toArrayBuffer(): ArrayBuffer { |
| 100 | // Add final chunk if it has data |
| 101 | if (this.offset > 0) { |
| 102 | this.chunks.push(this.currentBuffer.slice(0, this.offset)); |
| 103 | } |
| 104 | |
| 105 | // Calculate total size |
| 106 | const totalSize = this.chunks.reduce((sum, chunk) => sum + chunk.byteLength, 0); |
| 107 | |
| 108 | // Merge all chunks into single buffer |
| 109 | const result = new ArrayBuffer(totalSize); |
| 110 | const resultView = new Uint8Array(result); |
| 111 | let position = 0; |
| 112 | |
| 113 | for (const chunk of this.chunks) { |
| 114 | resultView.set(new Uint8Array(chunk), position); |
| 115 | position += chunk.byteLength; |
| 116 | } |
| 117 | |
| 118 | return result; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Get as Blob for download |
no outgoing calls