最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Replacing util.pump() in Node.js - Stack Overflow

programmeradmin4浏览0评论

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:

  1. Why is util.pump deprecated?
  2. 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:

  1. Why is util.pump deprecated?
  2. 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 badges
Add a ment  | 

3 Answers 3

Reset to default 12

Okay, 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);
发布评论

评论列表(0)

  1. 暂无评论