Hi,

I am missing a good example for how to adopt stream.pipe for my old 
util.pump code when it comes to replacing a file with the contents of 
another file. As of today, I am using code similar to this:

var readS = fs.createReadStream("fileA.txt");
var writeS = fs.createWriteStream("fileB.txt");
util.pump(readS, writeS, function(error)
   // Operation done
}); 

Now with stream.pipe I am uncertain if I am using it correctly. I am 
wondering if I have to call resume() or not before piping and I also wonder 
how to register a callback when the operation is fully completed. My 
attempt is this:

var readS = fs.createReadStream("fileA.txt");
var writeS = fs.createWriteStream("fileB.txt");
readS.pipe(writeS);

readS.on("end", function() {
   // Operation done
});

I would really appreciate if someone could tell me if this is the right way 
of doing it. As a related question, I am wondering if I should open the 
file with "w" or "r+". However, I think "w" is correct because I am 
replacing the file contents.

Thanks,
Ben

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to