Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- this.Server.prototype.stream = 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) {
- callback(err);
- sys.error(err);
- });
- } else {
- res.end();
- callback(null, buffer, offset);
- }
- })(files.slice(0), 0);
- };
Add Comment
Please, Sign In to add comment