Comparing version 0.0.4 to 0.1.0
0.1.0 / 2012-08-25 | ||
================== | ||
* add options parameter to send() that is passed to fs.createReadStream() [kanongil] | ||
0.0.4 / 2012-08-16 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -36,2 +36,3 @@ | ||
* @param {String} path | ||
* @param {Object} options | ||
* @return {SendStream} | ||
@@ -41,4 +42,4 @@ * @api public | ||
function send(req, path) { | ||
return new SendStream(req, path); | ||
function send(req, path, options) { | ||
return new SendStream(req, path, options); | ||
} | ||
@@ -58,9 +59,11 @@ | ||
* @param {String} path | ||
* @param {Object} options | ||
* @api private | ||
*/ | ||
function SendStream(req, path) { | ||
function SendStream(req, path, options) { | ||
var self = this; | ||
this.req = req; | ||
this.path = path; | ||
this.options = options || {}; | ||
this.maxage(0); | ||
@@ -336,3 +339,3 @@ this.hidden(false); | ||
SendStream.prototype.send = function(path, stat){ | ||
var options = {}; | ||
var options = this.options; | ||
var len = stat.size; | ||
@@ -342,2 +345,3 @@ var res = this.res; | ||
var ranges = req.headers.range; | ||
var offset = options.start || 0; | ||
@@ -357,2 +361,9 @@ // set header fields | ||
// adjust len to start/end options | ||
len = Math.max(0, len - offset); | ||
if (options.end !== undefined) { | ||
var bytes = options.end - offset + 1; | ||
if (len > bytes) len = bytes; | ||
} | ||
// Range support | ||
@@ -370,14 +381,14 @@ if (ranges) { | ||
if (-2 != ranges) { | ||
options.start = ranges[0].start; | ||
options.end = ranges[0].end; | ||
options.start = offset + ranges[0].start; | ||
options.end = offset + ranges[0].end; | ||
// Content-Range | ||
len = options.end - options.start + 1; | ||
res.statusCode = 206; | ||
res.setHeader('Content-Range', 'bytes ' | ||
+ options.start | ||
+ ranges[0].start | ||
+ '-' | ||
+ options.end | ||
+ ranges[0].end | ||
+ '/' | ||
+ stat.size); | ||
+ len); | ||
len = options.end - options.start + 1; | ||
} | ||
@@ -384,0 +395,0 @@ } |
{ | ||
"name": "send", | ||
"version": "0.0.4", | ||
"version": "0.1.0", | ||
"description": "Better streaming static file server with Range and conditional-GET support", | ||
@@ -5,0 +5,0 @@ "keywords": ["static", "file", "server"], |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
15150
435
0
2