On Sun, Sep 23, 2012 at 6:52 PM, Andris Reinman <[email protected]> wrote: > What would be the best way to detect a file has been written to disk? Once I > have passed all the data to a fs.WriteStream, the data is at first buffered > by node and written to the disk asynchronously. There is no "end" or "close" > event to listen to (or at least these don't trigger on my system (node > v0.8.9)) when all bytes are actually written to the disk. > > The best I have come up to is to listen to the "drain" event and then > compare writablestream.bytesWritten and the length of the data I sent to the > stream. > > var len = 0; > myReadStream.on("data", function(chunk){ > myWriteStream.write(chunk); > len += chunk.length; > }); > > myWriteStream.on("drain", function(){ > if(myWriteStream.bytesWritten == len){ > console.log("All bytes written to disk"); > } > }); > > But this doesn't seem very future proof, what if the conditions for the > 'drain' event with file write change one day? Is there a better way for > this?
Doesn't myReadStream.pipe(myWriteStream) work? -- 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
