| 382 | } |
| 383 | |
| 384 | get stream(): Stream.Stream<Uint8Array, HttpClientError.HttpClientError> { |
| 385 | return Stream.callback<Uint8Array, HttpClientError.HttpClientError>( |
| 386 | (queue) => |
| 387 | Effect.acquireRelease( |
| 388 | Effect.sync(() => { |
| 389 | const exchange = this.exchange |
| 390 | const fail = (error: HttpClientError.HttpClientError) => { |
| 391 | Queue.failCauseUnsafe(queue, Cause.fail(error)) |
| 392 | } |
| 393 | const unreadable = this.unreadable() |
| 394 | if (unreadable) return fail(unreadable) |
| 395 | this.streamed = true |
| 396 | const flush = () => { |
| 397 | const chunks = exchange.chunks |
| 398 | for (const chunk of chunks) { |
| 399 | if (chunk === "") continue |
| 400 | const bytes = this.bytes(chunk) |
| 401 | if (!(bytes instanceof Uint8Array)) return fail(bytes) |
| 402 | Queue.offerUnsafe(queue, bytes) |
| 403 | } |
| 404 | // Release consumed chunks from long-lived streams. |
| 405 | chunks.length = 0 |
| 406 | if (exchange.error === null) Queue.endUnsafe(queue) |
| 407 | else if (exchange.error !== undefined) { |
| 408 | fail(this.failed(exchange.error)) |
| 409 | } |
| 410 | } |
| 411 | exchange.listeners.add(flush) |
| 412 | flush() |
| 413 | return flush |
| 414 | }), |
| 415 | (flush) => Effect.sync(() => flush && this.exchange.listeners.delete(flush)) |
| 416 | ) |
| 417 | ) |
| 418 | } |
| 419 | |
| 420 | get text(): Effect.Effect<string, HttpClientError.HttpClientError> { |
| 421 | return this.binary |