so i have an array of filenames.
I need to go through each of those, read it as a stream, pipe one by one to a final stream.
Erroneously, the code would look something like this:
var files = ['file1.txt', 'file2.txt', 'file3.txt'];
var finalStream = fs.createReadStream()//throws(i need a file path here)
(function pipeSingleFile(file){
var stream = fs.createReadStream(file);
stream.on('end', function(){
if(files.length > 0){
pipeSingleFile( files.shift() );
}
});
stream.pipe(finalStream);
})( files.shift() )
finalStream.pipe(someOtherStream);
finalStream.on('end', function(){
//all the contents were piped to outside
});
Is there anyway to achieve this?