LevelUP Documentation says that pipe()
can be used (https://github.com/rvagg/node-levelup/#pipes-and-node-stream-compatibility).
I've tried the following code:
db.createValueStream().pipe(response)
But I could't do it, I've got an error:
events.js:72
throw er; // Unhandled 'error' event
^
TypeError: Invalid non-string/buffer chunk
at validChunk (_stream_writable.js:150:14)
at Writable.write (_stream_writable.js:179:12)
at write (_stream_readable.js:573:24)
at flow (_stream_readable.js:582:7)
at ReadStream.pipeOnReadable (_stream_readable.js:614:5)
at ReadStream.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:408:10)
at emitReadable (_stream_readable.js:404:5)
at readableAddChunk (_stream_readable.js:165:9)
at ReadStream.Readable.push (_stream_readable.js:127:10)
The actual problem is about memory usage when a use the event 'data' (). Then i was trying do make a stream.Transform and use pipe()
to do what a I need. Once memory leak in event emmiter is a problem: Memory leak when using streams in Node.js?
UPDATE
I've tried @paul-mougel without success. The function of error event are not called, and the it crashed. This is a piece of the code:
var rs = db.createValueStream();
request.on('close', function(){
rs.destroy();
response.end();
});
rs.on('end', function(){
response.end();
});
rs.on('error', function(err){
console.err('READ STREAM ERROR:',err.message);
response.end();
rs.destroy();
});
response.on('error', function(err){
console.log('RESPONSE ERROR:',err);
rs.destroy();
});
rs.pipe(stringifier).pipe(response);