You are reading a single comment by @net-tobi and its replies. Click here to read the full conversation.
  • Dear community,

    I tried to pipe an http response directly to a file to save RAM. I experienced that sometimes the file contains the right content, sometimes it contains strange characters. Furthermore the "complete" function defined in the pipe options is never getting called.

    I formatted the SD card before I tested and I typed E.unmountSD() to be sure that it is not a problem with the SD card filesystem.

    Could you please help me? Below you find the function.

    Best,

    Tobias

    var downloadFile = function(path, filePath) {
        var file = E.openFile(filePath, 'w');
        var body = "";
        var options = {
            method: 'GET',
            host: '192.168.0.11',
            port: 3000,
            path: path,
            headers: {
                "Content-Type": "application/json",
                "Content-Length": body.length
            }
        };
        var req = require('http').request(options, function(res) {
          res.pipe(file, { chunkSize : 32, end: true, complete: function() { console.log('Complete'); } });
          res.on('close', function() {
            console.log('Closed.');
          });
        });
        req.write(body);
        req.end();
    };
    
About

Avatar for net-tobi @net-tobi started