Last active
July 13, 2016 07:50
-
-
Save MarcoCiaramella/995797deeee730dd484b434b9cf747cd to your computer and use it in GitHub Desktop.
Nodejs function for copying a source to a destination file asynchronously
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 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