MCPcopy Index your code
hub / github.com/socketio/socket.io / sendFile

Method sendFile

lib/index.ts:609–642  ·  view source on GitHub ↗

* @param filename * @param req * @param res * @private

(
    filename: string,
    req: http.IncomingMessage,
    res: http.ServerResponse
  )

Source from the content-addressed store, hash-verified

607 * @private
608 */
609 private static sendFile(
610 filename: string,
611 req: http.IncomingMessage,
612 res: http.ServerResponse
613 ): void {
614 const readStream = createReadStream(
615 path.join(__dirname, "../client-dist/", filename)
616 );
617 const encoding = accepts(req).encodings(["br", "gzip", "deflate"]);
618
619 const onError = (err: NodeJS.ErrnoException | null) => {
620 if (err) {
621 res.end();
622 }
623 };
624
625 switch (encoding) {
626 case "br":
627 res.writeHead(200, { "content-encoding": "br" });
628 pipeline(readStream, createBrotliCompress(), res, onError);
629 break;
630 case "gzip":
631 res.writeHead(200, { "content-encoding": "gzip" });
632 pipeline(readStream, createGzip(), res, onError);
633 break;
634 case "deflate":
635 res.writeHead(200, { "content-encoding": "deflate" });
636 pipeline(readStream, createDeflate(), res, onError);
637 break;
638 default:
639 res.writeHead(200);
640 pipeline(readStream, res, onError);
641 }
642 }
643
644 /**
645 * Binds socket.io to an engine.io instance.

Callers 10

serveMethod · 0.80
index.jsFile · 0.80
index.tsFile · 0.80
index.jsFile · 0.80
index.jsFile · 0.80
index.tsFile · 0.80
index.jsFile · 0.80
index.jsFile · 0.80
index.tsFile · 0.80
index.jsFile · 0.80

Calls 1

joinMethod · 0.45

Tested by

no test coverage detected