Skip to content

Commit

Permalink
feat: Extend node.js http.ServerResponse class, add a download method…
Browse files Browse the repository at this point in the history
… that sends file attachments to
  • Loading branch information
teclone committed Jul 22, 2018
1 parent d4320d5 commit 29a06cf
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/modules/RServerResponse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {ServerResponse} from 'http';

export default {
/**
* returns an RServerResponse class
*@param {StaticFileServer} staticFileServer - static file server instance
*@returns {RServerResponse}
*/
getClass(staticFileServer) {

return class extends ServerResponse {
/**
* call the super class.
*/
constructor(...args) {
super(...args);
}

/**
* return the instance identifier
*/
get [Symbol.toStringTag]() {
return 'RServerResponse';
}

/**
* sends file intended for download to the client
*@param {string} filePath - file relative path
*@param {string} [filename] - suggested file download name that the browser uses while
* saving the file. defaults to the files base name.
*@param {Function} callback - the callback function to execute once the operation
* completes or fails
*/
download(filePath, filename, callback) {
staticFileServer.serveDownload(this, filePath, filename, callback);
}
};
}
};

0 comments on commit 29a06cf

Please sign in to comment.