{"version":3,"sources":["../../../../src/server/lib/release-compression-stream.ts"],"sourcesContent":["import type { ServerResponse } from 'node:http'\nimport { Duplex } from 'node:stream'\n\nconst noop = () => {}\n\n/**\n * Destroys the zlib stream that the `compression` middleware left open on a\n * response that never finished.\n *\n * The middleware ends its stream only from its own `res.end()` wrapper, so a\n * client disconnect leaves it open, and an open zlib stream is pinned by its\n * native handle: it survives GC, permanently retaining ~256 KiB of deflate\n * state. Ending it rather than destroying it does not work -- its `data` handler\n * writes to the dead response, `res.write()` returns `false`, and the middleware\n * pauses the stream, so it never reaches `end`.\n *\n * `res.on('drain', …)` is forwarded to that stream and `EventEmitter#on` returns\n * the emitter, which is the only handle to it from outside. When compression is\n * inactive the call returns `res` itself.\n */\nexport function releaseCompressionStream(res: ServerResponse): void {\n  const maybeStream: unknown = res.on('drain', noop)\n\n  // The `Duplex` check keeps a future middleware change from turning this into a\n  // `destroy()` on a non-stream, which would throw from a `close` handler.\n  if (maybeStream === res || !(maybeStream instanceof Duplex)) {\n    res.off('drain', noop)\n    return\n  }\n\n  maybeStream.destroy()\n}\n"],"names":["Duplex","noop","releaseCompressionStream","res","maybeStream","on","off","destroy"],"mappings":"AACA,SAASA,MAAM,QAAQ,cAAa;AAEpC,MAAMC,OAAO,KAAO;AAEpB;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASC,yBAAyBC,GAAmB;IAC1D,MAAMC,cAAuBD,IAAIE,EAAE,CAAC,SAASJ;IAE7C,+EAA+E;IAC/E,yEAAyE;IACzE,IAAIG,gBAAgBD,OAAO,CAAEC,CAAAA,uBAAuBJ,MAAK,GAAI;QAC3DG,IAAIG,GAAG,CAAC,SAASL;QACjB;IACF;IAEAG,YAAYG,OAAO;AACrB","ignoreList":[0]}