You are reading a single comment by @beweOnline and its replies. Click here to read the full conversation.
  • Thanks for your reply! While I can slice up the file into chunks and write a GET response using the node.js drain event as explained in the tutorial mentioned above, I was hoping someone could shed light on the whole matter. I'm curious as to why E.pipe() is available when E.openFile() is not! What's the use case here?

    Anyways, I post my WIP here, in case somebody's wondering. This goes into the routing callback function you'd supply to the createServer() method:

    ...
    var storage = require("Storage");
    var file = storage.read("xyz.html");
    res.writeHead(200, {'Content-Type': 'text/html'});
    
    // write response in packets
    var packet = 4096;
    var chunks = Math.ceil(file.length/packet);
    var n = 1;
    res.on('drain',function() {
         if(n===1){res.write(file.slice(0,packet*­n));}
         else if(n>=2 && n<=chunks){
           res.write(file.slice(packet*(n-1),packet­*n));
         }
         n++;
         if(n>chunks){res.end();}
    });
    res.write();
    
About

Avatar for beweOnline @beweOnline started