Skip to content
Myr

Fixed res.download() callback, passing stream. Closes #528

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

should be able to figure something out with this. at very least use redis or something with INCR/DECR to keep a count on active downloads

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 0e790e6 · Browse files · 2 files+14 added−6 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+14 added−6 removed

  • tests:+12 added−5 removed
  • other:+2 added−1 removed

2 files+14 added−6 removed

modified:lib/response.js+2 added-1 removed
120 unmodified lines
121/**122 * Transfer the file at the given `path`. Automatically sets 123 * the _Content-Type_ response header via `res.contentType()`. 124 *125 * Accepts an optional callback `fn(err, path)`.125 * Accepts an optional callback `fn(err, path, stream)`.126 *127 * @param {String} path128 * @param {Function} fn129 * @api public
49 unmodified lines
179 self.header('Accept-Ranges', 'bytes');180 self.writeHead(status, self.headers);181 if (head) return self.end();182 stream.pipe(self);183 fn && fn(null, path, stream);184 });185};186187/**
202 unmodified lines
modified:test/response.test.js+12 added-5 removed
2 unmodified lines
3 * Module dependencies.4 */56var express = require('express')7 , Buffer = require('buffer').Buffer7 , Stream = require('stream').Stream8 , assert = require('assert')9 , should = require('should');1011module.exports = {
304 unmodified lines
316 { url: '/large.json', headers: { 'Range': 'bytes=500-10' }},317 { body: 'Requested Range Not Satisfiable', status: 416 });318 },319 320 'test #download()': function(){321 var app = express.createServer();320 'test #download()': function(beforeExit){321 var app = express.createServer()322 , calls = 0;323 324 app.get('/json', function(req, res, next){325 var filePath = __dirname + '/fixtures/user.json';325 res.download(filePath, 'account.json', function(err, path){326 assert.equal(filePath, path);326 res.download(filePath, 'account.json', function(err, path, stream){327 ++calls;328 path.should.equal(filePath);329 stream.should.be.an.instanceof(Stream);330 });331 });332333 app.get('/*', function(req, res, next){
23 unmodified lines
357 { url: '/missing' },358 function(res){359 assert.equal(null, res.headers['content-disposition']);360 });361362 beforeExit(function(){363 calls.should.equal(1);364 });365 },366 367 'test #cookie()': function(){368 var app = express.createServer();
43 unmodified lines