Guest User

Untitled

a guest
Jun 20th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1.  
  2. this.Server.prototype.stream = function (pathname, files, buffer, res, callback) {
  3. (function streamFile(files, offset) {
  4. var file = files.shift();
  5.  
  6. if (file) {
  7. // Stream the file to the client
  8. fs.createReadStream(path.join(pathname || '.', file), {
  9. flags: 'r',
  10. encoding: 'binary',
  11. mode: 0666,
  12. bufferSize: 4096
  13. }).addListener('data', function (chunk) {
  14. buffer.write(chunk, offset, 0);
  15. res.write (chunk, 'binary');
  16. offset += chunk.length;
  17. }).addListener('close', function () {
  18. streamFile(files, offset);
  19. }).addListener('error', function (err) {
  20. callback(err);
  21. sys.error(err);
  22. });
  23. } else {
  24. res.end();
  25. callback(null, buffer, offset);
  26. }
  27. })(files.slice(0), 0);
  28. };
Add Comment
Please, Sign In to add comment