Answer the question
In order to leave comments, you need to log in
How to let in a stream, a stream received from another service?
Good morning!
Help solve the problem, please. Using a third party API, I can download videos from Youtube service.
With the help of the following code, I get the video in a stream, in chunks.
let data = [];
youtubeApi.downloadVideo('v=4P1-JwZF0Vo&t=4519s', chunk => data.push(chunk), () => {
console.log('downloaded ', data.length);
fs.writeFileSync('video.mp4', Buffer.concat(data));
});
Youtube -> My Nodejs App -> Client
Answer the question
In order to leave comments, you need to log in
without knowing what kind of lib provides youtubeApi, it is problematic to do it adequately, but you can do it universally:
const {PassThrough} = require('stream');
const youtubeStream = new PassThrough();
youtubeApi.downloadVideo(
'v=4P1-JwZF0Vo&t=4519s',
chunk => youtubeStream.write(chunk),
() => youtubeStream.end()
);
youtubeStream.pipe(res); // где res - выходной поток к клиенту
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question