MCPcopy Create free account
hub / github.com/Effect-TS/effect / compressResponse

Function compressResponse

packages/platform/node/src/NodeHttpPlatform.ts:36–66  ·  view source on GitHub ↗
(response, algorithm, options)

Source from the content-addressed store, hash-verified

34const 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/**

Callers

nothing calls this directly

Calls 6

compressedBodyFunction · 0.85
rawMethod · 0.80
streamMethod · 0.65
onMethod · 0.65
pipeMethod · 0.65
succeedMethod · 0.45

Tested by

no test coverage detected