* Process the stream in chunks
(
callback: (chunk: Uint8Array, bytesProcessed: number) => Promise<void> | void
)
| 67 | * Process the stream in chunks |
| 68 | */ |
| 69 | async readByChunks( |
| 70 | callback: (chunk: Uint8Array, bytesProcessed: number) => Promise<void> | void |
| 71 | ): Promise<number> { |
| 72 | try { |
| 73 | while (!this.aborted) { |
| 74 | const { done, value } = await this.reader.read(); |
| 75 | |
| 76 | if (done) break; |
| 77 | |
| 78 | this.bytesProcessed += value.length; |
| 79 | |
| 80 | // Process the chunk |
| 81 | await callback(value, this.bytesProcessed); |
| 82 | |
| 83 | if (this.options.onProgress) { |
| 84 | this.options.onProgress(this.bytesProcessed); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | return this.bytesProcessed; |
| 89 | } catch (error) { |
| 90 | if (!this.aborted) { |
| 91 | console.error('Error reading stream by chunks:', error); |
| 92 | throw error; |
| 93 | } |
| 94 | |
| 95 | return this.bytesProcessed; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Process a text stream line by line (for CSV, etc.) |
no outgoing calls
no test coverage detected