Avatar for beweOnline

beweOnline

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

Espruino's just so cool!

Most recent activity

    • 4 comments
    • 1,103 views
  • 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:

    ...
    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();
    
  • 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