I'm searching to send (return) a readableStream to a method (myMethod) with axios in a node program -> i'd like to stream the response to a ReadableStream that I can use to send to the myMethod() callers :
// This code does'nt work but that's what I'm trying to do
function myMethod() {
var readableStream = createReadableStream(); // does not exists but that's here to show the concept
const axiosObj = axios({
method: 'get',
url: 'https://www.google.fr',
responseType: 'stream'
}).then(function(res) {
res.data.pipe(readableStream);
}).catch(function(err) {
console.log(err);
});
return readableStream;
}
function myMethodCaller() {
myMethod().on('data', function(chunk) {
// Do some stuffs with the chunks
});
}
I know that we can only do in res.data a pipe to a writableStream. I'm stuck in returning a readableStream usable by the myMethod() callers. Have you got any ideas on that ?
Regards, Blured.