Advertisement
Guest User

Untitled

a guest
Jul 15th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. http.createServer(function (req, res) {
  2. node.fs.stat(files+req.uri.path).addCallback(function (stats) {
  3. res.sendHeader(200, {"Content-Type": "text/plain", "content-length": stats.size});
  4. // Hack to flush output
  5. res.sendBody("");
  6. res.sendBody("");
  7. node.fs.open(files+req.uri.path,node.O_RDONLY, 0666).addCallback(function (fd) {
  8. var send = function (start) {
  9. node.fs.sendfile(req.connection.fd, fd, start, stats.size-start).addCallback(function (sent) {
  10. if (sent === 0 || sent === stats.size) {
  11. res.finish();
  12. } else {
  13. send(sent+start);
  14. }
  15. }).addErrback(function (e) {
  16. if (start === stats.size || e != 'Error: Resource temporarily unavailable') {
  17. res.finish();
  18. } else {
  19. setTimeout(function () { send(start) }, 10);
  20. }
  21. });
  22. };
  23. send(0);
  24. });
  25. });
  26. }).listen(9020);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement