Created
October 8, 2012 00:31
-
-
Save al6x/3850106 to your computer and use it in GitHub Desktop.
How to copy file using pipe
This file contains 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
var copy = function(from, to, cb){ | |
var fromStream = fs.createReadStream(from) | |
fromStream.on('error', cb) | |
var toStream = fs.createWriteStream(to) | |
toStream.on('error', cb) | |
fromStream.on('end', cb) | |
fromStream.pipe(toStream) | |
} | |
copy('non existing file a', 'non existing dir/file b', function(err){ | |
console.log(err) | |
}) | |
// Error will be reported twice: | |
// | |
// { [Error: ENOENT, open 'non existing file a'] errno: 34, | |
// code: 'ENOENT', path: 'non existing file a' } | |
// { [Error: ENOENT, open 'non existing dir/file b'] errno: 34, | |
// code: 'ENOENT', path: 'non existing dir/file b' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With callbacks it may be something like that