Permalink
Browse files

use Stream#pipe

  • Loading branch information...
1 parent 68a32ef commit 2ecc6c2cac8894b68104e5bb4c3f05546c41534f @cloudhead committed Apr 15, 2011
Showing with 8 additions and 11 deletions.
  1. +8 −11 lib/node-static.js
View
@@ -232,19 +232,16 @@ this.Server.prototype.stream = function (pathname, files, buffer, res, callback)
// Stream the file to the client
fs.createReadStream(path.join(pathname || '.', file), {
flags: 'r',
- encoding: 'binary',
- mode: 0666,
- bufferSize: 4096
- }).addListener('data', function (chunk) {
- buffer.write(chunk, offset, 'binary');
- res.write (chunk, 'binary');
- offset += chunk.length;
- }).addListener('close', function () {
+ mode: 0666
+ }).on('data', function (chunk) {
+ chunk.copy(buffer, offset);
+ offset += chunk.length;
+ }).on('close', function () {
streamFile(files, offset);
- }).addListener('error', function (err) {
+ }).on('error', function (err) {
callback(err);
- sys.error(err);
- });
+ console.error(err);
+ }).pipe(res, { end: false });
} else {
res.end();
callback(null, buffer, offset);

0 comments on commit 2ecc6c2

Please sign in to comment.