Removed "stream threshold" setting
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 2895303 · Browse files · 2 files·+23 added−37 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+23 added−37 removed
- other:+23 added−37 removed
Provenance
- Commit
ee4c7d3- Tree
f689fd7- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
2895303
2 files changed+23 added−37 removed
modified:docs/guide.md-3 removed
79 unmodified lines80 * _home_ Application base path used for _res.redirect()_ and transparently handling mounted apps.81 * _views_ Root views directory defaulting to **CWD/views**82 * _view engine_ Default view engine name for views rendered without extensions83 * _view options_ An object specifying global view options84- * _stream threshold_ Bytesize indicating when a file should be streamed for _res.sendfile()_ using _fs.ReadStream()_ and _sys.pump()_.84 85 ### Routing86 87 Express utilizes the HTTP verbs to provide a meaningful, expressive routing API.682 unmodified lines770 console.log('transferred %s', path);771 }772 });773 775-When the filesize exceeds the _stream threshold_ (defaulting to 32k), the file will be streamed using _fs.ReadStream_ and _sys.pump()_.776-774 ### res.download(file[, filename])775 776 Transfer the given _file_ as an attachment with optional alternative _filename_.777 331 unmodified linesmodified:lib/express/response.js+23 added-34 removed
134 unmodified lines135 */136 137 http.ServerResponse.prototype.sendfile = function(path, fn){138 var self = this139- , streamThreshold = this.app.set('stream threshold') || 32 * 1024139 , ranges = self.req.headers.range140 , head = 'HEAD' == self.req.method;141 143- if (~path.indexOf('..')) this.send(403);142+ if (~path.indexOf('..')) return this.send(403);143 144 function error(err) {145 delete self.headers['Content-Disposition'];146 if (fn) {4 unmodified lines151 }152 153 fs.stat(path, function(err, stat){154 if (err) return error(err);156- if (stat.size >= streamThreshold) {157- var status = 200;158- if (ranges) ranges = parseRange(stat.size, ranges);159- if (ranges) {160- var stream = fs.createReadStream(path, ranges[0])161- , start = ranges[0].start162- , end = ranges[0].end;163- status = 206;164- self.header('Content-Range', 'bytes '165- + start166- + '-'167- + end168- + '/'169- + stat.size);155+ var status = 200;156+ if (ranges) ranges = parseRange(stat.size, ranges);157+ if (ranges) {158+ var stream = fs.createReadStream(path, ranges[0])159+ , start = ranges[0].start160+ , end = ranges[0].end;161+ status = 206;162+ self.header('Content-Range', 'bytes '163+ + start164+ + '-'165+ + end166+ + '/'167+ + stat.size);170- } else {171- var stream = fs.createReadStream(path);172- self.header('Content-Length', stat.size);173- }174- self.contentType(path);175- self.header('Accept-Ranges', 'bytes');176- self.writeHead(status, self.headers);177- if (head) return self.end();178- pump(stream, self, function(err){179- fn && fn(err, path, true);180- });168 } else {182- fs.readFile(path, function(err, buf){183- if (err) return error(err);184- self.contentType(path);185- if (head) return self.end();186- self.send(buf);187- fn && fn(null, path);188- });169+ var stream = fs.createReadStream(path);170+ self.header('Content-Length', stat.size);171 }172+ self.contentType(path);173+ self.header('Accept-Ranges', 'bytes');174+ self.writeHead(status, self.headers);175+ if (head) return self.end();176+ pump(stream, self, function(err){177+ fn && fn(err, path, true);178+ });179 });180 };181 182 /**204 unmodified lines