Skip to content
Myr

Added callback support to res.download()

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 8308e50 · Browse files · 2 files+17 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+17 added−7 removed

  • tests:+4 added−1 removed
  • other:+13 added−6 removed

2 files+17 added−7 removed

modified:lib/express/response.js+13 added-6 removed
87 unmodified lines
88 this.end(body);89};9091/**92 * Transfer the file at the given `path`. Automatically sets the _Content-Type_93 * response header via `res.contentType()`.92 * Transfer the file at the given `path`. Automatically sets 93 * the _Content-Type_ response header via `res.contentType()`. 94 *95 * The given callback `fn` is invoked when an error occurs,96 * passing it as the first argument, or when the file is transferred,97 * passing the path as the second argument.98 *99 * @param {String} path100 * @param {Function} fn101 * @api public102 */
48 unmodified lines
151 return this;152};153154/**151 * Transfer the given `file` with optional `filename` as an attachment.155 * Transfer the file at the given `path`, with optional 156 * `filename` as an attachment. Once transferred, or if an157 * error occurs `fn` is called with the error and path.158 *153 * @param {String} file159 * @param {String} path160 * @param {String} filename161 * @param {Function} fn162 * @return {Type}163 * @api public164 */165159http.ServerResponse.prototype.download = function(file, filename){160 this.attachment(filename || file).sendfile(file);166http.ServerResponse.prototype.download = function(path, filename, fn){167 this.attachment(filename || path).sendfile(path, fn);168};169170/**171 * Set or get response header `name` with optional `val`.
75 unmodified lines
modified:test/response.test.js+4 added-1 removed
201 unmodified lines
202 'test #download()': function(assert){203 var app = express.createServer();204 205 app.get('/json', function(req, res, next){206 res.download(__dirname + '/fixtures/user.json', 'account.json');206 var filePath = __dirname + '/fixtures/user.json';207 res.download(filePath, 'account.json', function(err, path){208 assert.equal(filePath, path);209 });210 });211212 app.get('/*', function(req, res, next){213 res.download(__dirname + '/fixtures/' + req.params[0]);
17 unmodified lines