Skip to content

Instantly share code, notes, and snippets.

Forked from Marak/stream.js
Created October 28, 2010 20:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do? = function (pathname, files, buffer, res, callback) {
(function streamFile(files, offset) {
var file = files.shift();
if (file) {
// 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, 0);
res.write (chunk, 'binary');
offset += chunk.length;
}).addListener('close', function () {
streamFile(files, offset);
}).addListener('error', function (err) {
} else {
callback(null, buffer, offset);
})(files.slice(0), 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment