Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- http.createServer(function (req, res) {
- node.fs.stat(files+req.uri.path).addCallback(function (stats) {
- res.sendHeader(200, {"Content-Type": "text/plain", "content-length": stats.size});
- // Hack to flush output
- res.sendBody("");
- res.sendBody("");
- node.fs.open(files+req.uri.path,node.O_RDONLY, 0666).addCallback(function (fd) {
- var send = function (start) {
- node.fs.sendfile(req.connection.fd, fd, start, stats.size-start).addCallback(function (sent) {
- if (sent === 0 || sent === stats.size) {
- res.finish();
- } else {
- send(sent+start);
- }
- }).addErrback(function (e) {
- if (start === stats.size || e != 'Error: Resource temporarily unavailable') {
- res.finish();
- } else {
- setTimeout(function () { send(start) }, 10);
- }
- });
- };
- send(0);
- });
- });
- }).listen(9020);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement