-
• #2
have a look at https://www.espruino.com/Reference#StorageFile
-
• #3
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();
-
• #4
I would not use ESP8266 for a web server, because it is slow.
But if you want to I'd suggest to read my post 'HowTo: Webserver with HTML/JavaScript/CSS/Images on ESP8266 (4 MB)'. I've created a custom firmware that supports E.openFile and E.pipe.
E.openFile is not available because the modules Filesystem (and FlashFS) are not in the standard firmware for ESP8266.
Dear all!
Reading a file with require("Storage").read() but running out of mem with larger files, like serving a ~20kb html file. So I want to stream instead as suggested here. However, if the NodeMCU hasn't got E.openFile(), how then do you open a file for streaming such that I might use E.pipe()?
Scratching my head over this one. Any help much appreaciated!