Skip to content

Instantly share code, notes, and snippets.

@MarcoCiaramella
Last active July 13, 2016 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarcoCiaramella/995797deeee730dd484b434b9cf747cd to your computer and use it in GitHub Desktop.
Save MarcoCiaramella/995797deeee730dd484b434b9cf747cd to your computer and use it in GitHub Desktop.
Nodejs function for copying a source to a destination file asynchronously
function cpAsync(srcPath,destPath,callback){
var rs = fs.createReadStream(srcPath);
var ws = fs.createWriteStream(destPath);
rs.on('error', function(err) {
console.log(err);
});
ws.on('error', function(err) {
console.log(err);
});
if (callback){
ws.on('finish',function(){
callback(destPath);
});
}
rs.pipe(ws);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment