Piping transformed read stream into request.post()
<p>I'd like parse a log file and POST what is read to a request endpoint. I've managed to build a solution that generates a request for every log line read. However, it doesn't create any back pressure so it just flogs the server and I'd like to slow it down.</p>

<p>This lead me to investigate using stream pipes to see if I could route data from a file directly into request.post(). I can't get the post call to post a body object though.</p>

<pre><code>var stream = require('stream');
var request = require('request');
var liner = new stream.Transform( { objectMode: true } );

liner._transform = function (chunk, encoding, done) {
     var data = chunk.toString()
     if (this._lastLineData) data = this._lastLineData + data 

     var lines = data.split('\n') 
     this._lastLineData = lines.splice(lines.length-1,1)[0] 

     var that = this;
     lines.forEach(function(line) {
        var line_obj = JSON.parse(line);
        if( line_obj.url === "/api/usages" &amp;&amp; line_obj.method === 'POST' ) {
            var req_body = line_obj.body.body;
            that.push.bind(req_body);
        }
     });
     done();
}

var file_name = process.argv[2];
console.log('Reading from ' + file_name);

var fs = require('fs')
var liner = require('./liner')
var source = fs.createReadStream(file_name)
source.pipe(liner).pipe(request
                            .post("http://localhost:8081/api/usages")
                            .on('response', function(response) {
                                console.log(response.statusCode) // 200
                            })
                            .on('error', function(err) {
                                console.log(err);
                            }));
</code></pre>

<p>The push call in the transform function is working correctly, but it's not posting that object via the body in request.post().</p>

<p>What am I missing? </p>

<p>Will this provide the back pressure I'm looking for to throttle the POST calls before all of the file reads are completed?</p>