[Pkg-javascript-commits] [node-static] 38/151: use Stream#pipe
Tonnerre Lombard
tonnerre-guest at moszumanska.debian.org
Tue Jan 7 23:17:57 UTC 2014
This is an automated email from the git hooks/post-receive script.
tonnerre-guest pushed a commit to branch master
in repository node-static.
commit 2ecc6c2cac8894b68104e5bb4c3f05546c41534f
Author: cloudhead <alexis at cloudhead.io>
Date: Fri Apr 15 17:47:28 2011 -0400
use Stream#pipe
---
lib/node-static.js | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/lib/node-static.js b/lib/node-static.js
index 6fa296a..420af63 100644
--- a/lib/node-static.js
+++ b/lib/node-static.js
@@ -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);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-static.git
More information about the Pkg-javascript-commits
mailing list