Created
July 23, 2015 03:22
-
-
Save piaoger/0d591be74f7bf1a8ced4 to your computer and use it in GitHub Desktop.
copyfileSync in node.js
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 copyFileSync(srcFile, destFile) { | |
var BUF_LENGTH, buff, bytesRead, fdr, fdw, pos; | |
BUF_LENGTH = 64 * 1024; | |
buff = new Buffer(BUF_LENGTH); | |
fdr = fs.openSync(srcFile, 'r'); | |
fdw = fs.openSync(destFile, 'w'); | |
bytesRead = 1; | |
pos = 0; | |
while (bytesRead > 0) { | |
bytesRead = fs.readSync(fdr, buff, 0, BUF_LENGTH, pos); | |
fs.writeSync(fdw, buff, 0, bytesRead); | |
pos += bytesRead; | |
} | |
fs.closeSync(fdr); | |
return fs.closeSync(fdw); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment