Last active
December 5, 2016 07:45
-
-
Save hustshawn/75d93fef5ba018d4f841683ac844e70b to your computer and use it in GitHub Desktop.
Copy large file with node stream
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
const fs = require('fs'); | |
var rs = fs.createReadStream(src); | |
var ws = fs.createWriteStream(dst); | |
rs.on('data', function (chunk) { | |
if (ws.write(chunk) === false) { | |
rs.pause(); | |
} | |
}); | |
rs.on('end', function () { | |
ws.end(); | |
}); | |
ws.on('drain', function () { | |
rs.resume(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment