| 260 | } |
| 261 | |
| 262 | enqueue(chunk: Uint8Array | string) { |
| 263 | if (this.controller) { |
| 264 | try { |
| 265 | let bytes: Uint8Array<ArrayBuffer> = |
| 266 | typeof chunk === "string" |
| 267 | ? Buffer.from(chunk) |
| 268 | : new Uint8Array(chunk); |
| 269 | |
| 270 | let available = (this.controller.desiredSize || 0) - bytes.byteLength; |
| 271 | this.controller.enqueue(bytes); |
| 272 | if (available <= 0) { |
| 273 | this.pause(); |
| 274 | } |
| 275 | } catch ( |
| 276 | // eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 277 | e |
| 278 | ) { |
| 279 | this.controller.error( |
| 280 | new Error( |
| 281 | "Could not create Buffer, chunk must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object", |
| 282 | ), |
| 283 | ); |
| 284 | this.cancel(); |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | pause() { |
| 290 | if (this.stream.pause) { |