• Sure, the code I ended up using was:

    var http = require("http");
    var page = `<html>
    <head>
        <title>test pipe</title>
        <script src="https://ajax.googleapis.com/ajax/li­bs/jquery/2.1.4/jquery.min.js"></script>­
    </head>
    <body>
          <button id="uploadPipe">Upload piped</button>
          <button id="uploadStd">Upload eventdriven</button>
          <button id="getUploaded">Read uploaded</button>
          <textarea rows="25" cols="100" id="Htmlfile"></textarea>
    </body>
    <script>
      $("#Htmlfile").val( $("html").html());
      $("#uploadPipe").click(function(){
        $.post("uploadPipe",$("#Htmlfile").val()­,function(data){});
      });
      $("#uploadStd").click(function(){
        $.post("uploadStd",$("#Htmlfile").val(),­function(data){});
      });
      $("#getUploaded").click(function(){
        $.get("uploaded.html",function(data){
          $("#Htmlfile").val(data);
        });
      });
    </script>
    </html>`;
    var r;
    
    function httpServer(){
      var me = this;
      var srv;
      function handleGet(req,res){
        res.writeHead(200,{"Content-Type":"text/­html"});
        if (req.url!=="/uploaded.html") {
          res.end(page);
          return;
        } 
        var f = E.openFile("uploaded.html","r");
        var data,ext,type;
        if(f !== undefined){
          do{
            data = f.read(32);
            if (data) res.write(data);
          } while(data);
          res.end();
          f.close();
        }
        else{
          res.end(a.pathname + " not found");
        }
      }
      function uploadStd(a,req,res){
        console.log("uploadPipe",a);
        var f = E.openFile("uploaded.html","w");
        req.on("data",function(data){f.write(dat­a);});
        req.on("close",function(){
          console.log();
          f.close();
          res.end("event upload done");
        });
    
      }
      
      function uploadPipe(a,req,res){
        console.log("uploadStd",a);
        var f = E.openFile("uploaded.html","w");
        req.pipe(f,{chunkSize:512, end:false,
          complete:function(){
              console.log("Complete");
              f.close();
              res.end("pipe upload done");
          }
        });
        res.end();
      }
      function handlePost(req,res){
        var a = url.parse(req.url,true); 
        switch(a.pathname){
          case "/uploadPipe":uploadPipe(a,req,res);brea­k;
          case "/uploadStd":uploadStd(a,req,res);break;­
        }
      }
      function handle(req,res){
        if (req.method == 'POST') 
          handlePost(req,res);
        else if(req.method == 'GET') 
          handleGet(req,res);
        else req.connection.destroy();
      }
      me.init = function(){
        srv = http.createServer(handle);
        srv.listen(8080);
      };
    }
    var srv = new httpServer();
    srv.init();
    

    So basically I call end immediately, because the connection will still be held open while the data received < Content-Length

About

Avatar for Gordon @Gordon started