(chunk: Buffer | Uint8Array | string)
| 177 | } |
| 178 | |
| 179 | const onData = (chunk: Buffer | Uint8Array | string) => { |
| 180 | const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk) |
| 181 | totalBytes += buffer.byteLength |
| 182 | |
| 183 | if (totalBytes > options.maxBytes) { |
| 184 | if ('destroy' in stream && typeof stream.destroy === 'function') { |
| 185 | stream.destroy() |
| 186 | } |
| 187 | finish(() => |
| 188 | reject( |
| 189 | new PayloadSizeLimitError({ |
| 190 | label: options.label, |
| 191 | maxBytes: options.maxBytes, |
| 192 | observedBytes: totalBytes, |
| 193 | }) |
| 194 | ) |
| 195 | ) |
| 196 | return |
| 197 | } |
| 198 | |
| 199 | void options.onChunk?.(buffer, totalBytes) |
| 200 | chunks.push(buffer) |
| 201 | } |
| 202 | |
| 203 | const onEnd = () => { |
| 204 | finish(() => resolve(Buffer.concat(chunks, totalBytes))) |
no test coverage detected