Created
October 12, 2012 01:56
-
-
Save andrewrk/3876926 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function moveFile(source, dest, cb){ | |
fs.rename(source, dest, function(err){ | |
var ins, outs, had_error; | |
if (!err) { | |
return cb(); | |
} | |
if (err.code !== 'EXDEV') { | |
return cb(err); | |
} | |
ins = fs.createReadStream(source); | |
outs = fs.createWriteStream(dest); | |
had_error = false; | |
ins.on('error', function(err){ | |
had_error = true; | |
outs.destroy(); | |
cb(err); | |
}); | |
outs.on('error', function(err){ | |
had_error = true; | |
ins.destroy(); | |
cb(err); | |
}); | |
outs.on('close', function(){ | |
if (!had_error) { | |
cb(); | |
} | |
}); | |
ins.pipe(outs); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment