| 34 | const compression = NodeHttpCompression.make({ |
| 35 | algorithms: NodeHttpCompression.algorithms, |
| 36 | compressResponse(response, algorithm, options) { |
| 37 | const body = response.body |
| 38 | switch (body._tag) { |
| 39 | case "Stream": { |
| 40 | return Effect.succeed(compressedBody( |
| 41 | response, |
| 42 | HttpBody.stream( |
| 43 | NodeStream.pipeThroughDuplex(body.stream, { |
| 44 | evaluate: () => NodeHttpCompression.compressTransform(algorithm, options) |
| 45 | }), |
| 46 | body.contentType |
| 47 | ) |
| 48 | )) |
| 49 | } |
| 50 | case "Raw": { |
| 51 | const readable = body.body instanceof Readable |
| 52 | ? body.body |
| 53 | : Readable.fromWeb(new Response(body.body as BodyInit).body as any) |
| 54 | const transform = NodeHttpCompression.compressTransform(algorithm, options) |
| 55 | readable.on("error", (cause) => transform.destroy(cause)) |
| 56 | transform.on("error", (cause) => readable.destroy(cause)) |
| 57 | transform.on("close", () => readable.destroy()) |
| 58 | return Effect.succeed( |
| 59 | compressedBody(response, HttpBody.raw(readable.pipe(transform), { contentType: body.contentType })) |
| 60 | ) |
| 61 | } |
| 62 | default: { |
| 63 | return Effect.succeed(response) |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | }) |
| 68 | |
| 69 | /** |