Comparing version 0.5.6 to 0.5.7
@@ -183,6 +183,17 @@ #! /usr/bin/env node | ||
var start = parseInt(partialstart, 10); | ||
var end = partialend ? parseInt(partialend, 10) : total-1; | ||
var end = Math.min(total-1, partialend ? parseInt(partialend, 10) : total-1); | ||
var chunksize = (end-start)+1; | ||
if (start > end || isNaN(start) || isNaN(end)) { | ||
return status['416'](res, next); | ||
} | ||
var fstream = fs.createReadStream(file, {start: start, end: end}); | ||
res.writeHead(206, { 'Content-Range': 'bytes ' + start + '-' + end + '/' + total, 'Accept-Ranges': 'bytes', 'Content-Length': chunksize, 'Content-Type': contentType || 'application/octet-stream' }); | ||
fstream.on('error', function (err) { | ||
status['500'](res, next, { error: err }); | ||
}); | ||
res.writeHead(206, { | ||
'Content-Range': 'bytes ' + start + '-' + end + '/' + total, | ||
'Accept-Ranges': 'bytes', | ||
'Content-Length': chunksize, | ||
'Content-Type': contentType || 'application/octet-stream' | ||
}); | ||
fstream.pipe(res); | ||
@@ -189,0 +200,0 @@ return; |
@@ -47,2 +47,15 @@ // not modified | ||
exports['416'] = function (res, next) { | ||
res.statusCode = 416; | ||
if (typeof next === "function") { | ||
next(); | ||
} | ||
else { | ||
if (res.writable) { | ||
res.setHeader('content-type', 'text/plain'); | ||
res.end('Requested range not satisfiable'); | ||
} | ||
} | ||
}; | ||
// flagrant error | ||
@@ -49,0 +62,0 @@ exports['500'] = function (res, next, opts) { |
@@ -5,3 +5,3 @@ { | ||
"description": "A simple static file server middleware that works with both Express and Flatiron", | ||
"version": "0.5.6", | ||
"version": "0.5.7", | ||
"homepage": "https://github.com/jesusabdullah/node-ecstatic", | ||
@@ -8,0 +8,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
244435
45
1322
13