I recently updated to the latest version of Node.js (1.10~) from 0.8~, and I've been getting a message when running that says:
util.pump() is deprecated. Use readableStream.pipe() instead.
I've tried to switch my functions to say readableStream.pipe(), but I don't think it's working the same.
So I have three questions:
- Why is util.pump deprecated?
- How do I switch to readableStream.pipe()? OR 3. How do I turn off this warning?
Here is the code where I'm using it (with mustache)
var stream = mupileAndRender(template_file, json_object_from_db);
util.pump(stream, res);
When I replace util.pump with readableStream.pipe, I get this error:
ReferenceError: readableStream is not defined
Can anyone help point me in the right direction?
I recently updated to the latest version of Node.js (1.10~) from 0.8~, and I've been getting a message when running that says:
util.pump() is deprecated. Use readableStream.pipe() instead.
I've tried to switch my functions to say readableStream.pipe(), but I don't think it's working the same.
So I have three questions:
- Why is util.pump deprecated?
- How do I switch to readableStream.pipe()? OR 3. How do I turn off this warning?
Here is the code where I'm using it (with mustache)
var stream = mu.pileAndRender(template_file, json_object_from_db);
util.pump(stream, res);
When I replace util.pump with readableStream.pipe, I get this error:
ReferenceError: readableStream is not defined
Can anyone help point me in the right direction?
Share Improve this question asked May 5, 2013 at 4:38 streetlightstreetlight 5,96813 gold badges66 silver badges102 bronze badges3 Answers
Reset to default 12Okay, so this question was a pretty easy answer after some more experimentation (though documentation was null).
Basically, readableStream is just a variable you're supposed to replace with your stream. So in my case, the answer is:
stream.pipe(res);
You just replace util, basically, with the stream. Easy peezy.
I Think the following link will help for your work ! https://groups.google./forum/#!msg/nodejs/YWQ1sRoXOdI/3vDqoTazbQQJ
var readS = fs.createReadStream("fileA.txt");
var writeS = fs.createWriteStream("fileB.txt");
util.pump(readS, writeS, function(error)
// Operation done
});
=====>
var readS = fs.createReadStream("fileA.txt");
var writeS = fs.createWriteStream("fileB.txt");
readS.pipe(writeS);
readS.on("end", function() {
// Operation done
});
You can look this link http://nodejs.cn/api/stream.html
This is emitted whenever the stream.pipe() method is called on a readable stream, adding this writable to its set of destinations.
var writer = getWritableStreamSomehow();
var reader = getReadableStreamSomehow();
writer.on('pipe', (src) => {
console.error('something is piping into the writer');
assert.equal(src, reader);
});
reader.pipe(writer);