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();
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
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: