i sugest you to check the dir existence with fs.stat first. It's more reliable and it's a better code style to check explicitly for expeting error states, before it creates a runtime error like ENOENT.
still you can .destroy streams. it's doubt it's a good idea to call .end() on a errored Writable. it's also problematic to reuse the readable. you cant recycle streams, they are one shots (not only in node). if you unpipe and pipe to a new writable you cant ensure, that the first writable haven't read anything already, so you may write corrupt data. don't handle errors which you can prevent proactively. Am Donnerstag, 26. September 2013 21:48:26 UTC+2 schrieb [email protected]: > > I'm doing a file copy using fs.createReadStream & fs.createWriteStream. > When write stream throws an ENOENT error because destination directory > doesn't exist, I want to create it, and than re-create and re-pipe the > streams. > > To do that, first I need to kill & get rid of already existing streams > without them causing any more issues and not breaking the app. Currently, > I'm doing this: http://hastebin.com/qeketakofi.js > > Bu I don't know whether some lines inside terminate() are not redundant, > or whether I'm not doing something that I should. Node docs are generally > quite brief, leaving tons of questions unanswered :/ > > Also, for the sake of efficiency, is it possible to just recycle the read > stream, and pipe it to a new write stream? > -- -- 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.
