Avatar for beweOnline

beweOnline

Member since Aug 2022 • Last active Feb 2024
  • 1 conversations
  • 3 comments

Espruino's just so cool!

Most recent activity

  • started
    • 4 comments
    • 1.45k views
    @GermanWarez replied
  • in ESP8266
    Avatar for beweOnline

    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:

    1. ...
    2. var storage = require("Storage");
    3. var file = storage.read("xyz.html");
    4. res.writeHead(200, {'Content-Type': 'text/html'});
    5. // write response in packets
    6. var packet = 4096;
    7. var chunks = Math.ceil(file.length/packet);
    8. var n = 1;
    9. res.on('drain',function() {
    10. if(n===1){res.write(file.slice(0,packet*n));}
    11. else if(n>=2 && n<=chunks){
    12. res.write(file.slice(packet*(n-1),packet*n));
    13. }
    14. n++;
    15. if(n>chunks){res.end();}
    16. });
    17. res.write();
  • in ESP8266
    Avatar for beweOnline

    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!

Actions