Responder.prototype.handleFileStream = function()

in src/responder.js [115:152]


Responder.prototype.handleFileStream = function(file, result) {
  const self = this;

  this.streamedFile = file;
  this.res.statusCode = file.status || 200;
  if (this.res.statusCode === 200 && file.file === this.config.errorPage) {
    this.res.statusCode = 404;
  }
  this.res.setHeader(
    "Content-Type",
    result.contentType || mime.contentType(path.extname(file.file))
  );
  if (result.size) {
    this.res.setHeader("Content-Length", result.size);
  }
  if (result.etag) {
    this.res.setHeader("ETag", result.etag);
  }
  if (result.modified) {
    this.res.setHeader(
      "Last-Modified",
      new Date(result.modified).toUTCString()
    );
  }

  if (this.compressor) {
    this.compressor(this.req, this.res, () => {
      result.stream.pipe(self.res);
    });
  } else {
    result.stream.pipe(self.res);
  }

  return awaitFinished(this.res).then(() => {
    destroy(result.stream);
    return true;
  });
};