I am trying to implement a function ._readfor a readable stream, the problem occurs when ._readno data is called , the documentation says that I can push('')until there is more data, and I should only return falsewhen the stream will never have more data.
https://nodejs.org/api/stream.html#stream_readable_read_size_1
But he also says that if I need it, then something is terribly wrong with my design.
https://nodejs.org/api/stream.html#stream_stream_push
But I can not find an alternative to this.
code:
var http = require('http');
var https = require('https');
var Readable = require('stream').Readable;
var router = require('express').Router();
var buffer = [];
router.post('/', function(clientRequest, clientResponse) {
var delayedMSStream = new Readable;
delayedMSStream._read = function() {
var a=buffer.shift();
if(typeof a === 'undefined'){
this.push('');
return true;
}
else {
this.push(a);
if(a===null) {
return false;
}
return true;
}
};
https.request({hostname:'example.com'}, function(exampleResponse){
data='';
exampleResponse.on('data',function(chunk){data+=chunk});
exampleResponse.on('end',function(){
var MSRequestOptions = {hostname: data, method: 'POST'};
var MSRequest = https.request(MSRequestOptions, function(MSResponse){
MSResponse.on('end', function () {
console.log("MSResponse.on(end)");
});
});
delayedMSStream.pipe(MSRequest);
});
});
clientRequest.on('data', function (chunk) {
buffer.push(chunk);
});
clientRequest.on('end', function () {
buffer.push(null);
});
});
:
POST- , URL- example.com, example.com URL-, .
?