Reputation:
I have some streams that I pipe, and at one point I receive many buffers
and want to concatenate them together. Hence, I tried to use the concat-stream
package, however, it is not readable stream and after it I cannot perform the pipe operation again. Here is the code that I want to achieve:
const concat = require('concat-stream');
request({ url, ...options })
.pipe(zlib.createGunzip())
.pipe(concat((buffer) => {
buffer.toString('utf-8');
}))
.pipe(smtaStream);
Is there any other method or package that would let me do this?
Upvotes: 1
Views: 1897
Reputation: 341
contact-stream
would collect all the data from a stream into a single buffer. That means all your data is in memory. So you don't have to use stream anymore. If you still want to use stream, you should change string to stream like that:
const Readable = require('stream').Readable;
const concat = require('concat-stream');
request({ url, ...options })
.pipe(zlib.createGunzip())
.pipe(concat((buffer) => {
const rs = new Readable();
rs.push(buffer.toString('utf-8'));
rs.push(null);
rs.pipe(smtaStream);
}));
Upvotes: 2