comparison node_modules/node-static/lib/node-static.js @ 76:0ae87af84e2f

added oscgroups
author Rob Canning <rob@foo.net>
date Sun, 13 Jul 2014 10:07:41 +0100
parents 333afcfd3f3a
children
comparison
equal deleted inserted replaced
75:3a2845e3156e 76:0ae87af84e2f
6 , path = require('path') 6 , path = require('path')
7 , mime = require('mime') 7 , mime = require('mime')
8 , util = require('./node-static/util'); 8 , util = require('./node-static/util');
9 9
10 // Current version 10 // Current version
11 var version = [0, 7, 2]; 11 var version = [0, 7, 3];
12 12
13 Server = function (root, options) { 13 Server = function (root, options) {
14 if (root && (typeof(root) === 'object')) { options = root; root = null } 14 if (root && (typeof(root) === 'object')) { options = root; root = null }
15 15
16 this.root = path.resolve(root || '.'); 16 this.root = path.resolve(root || '.');
297 // Stream the file to the client 297 // Stream the file to the client
298 fs.createReadStream(file, { 298 fs.createReadStream(file, {
299 flags: 'r', 299 flags: 'r',
300 mode: 0666 300 mode: 0666
301 }).on('data', function (chunk) { 301 }).on('data', function (chunk) {
302 chunk.copy(buffer, offset); 302 // Bounds check the incoming chunk and offset, as copying
303 offset += chunk.length; 303 // a buffer from an invalid offset will throw an error and crash
304 if (chunk.length && offset < buffer.length && offset >= 0) {
305 chunk.copy(buffer, offset);
306 offset += chunk.length;
307 }
304 }).on('close', function () { 308 }).on('close', function () {
305 streamFile(files, offset); 309 streamFile(files, offset);
306 }).on('error', function (err) { 310 }).on('error', function (err) {
307 callback(err); 311 callback(err);
308 console.error(err); 312 console.error(err);