Skip to content

Instantly share code, notes, and snippets.

@hustshawn
Last active December 5, 2016 07:45
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 hustshawn/75d93fef5ba018d4f841683ac844e70b to your computer and use it in GitHub Desktop.
Save hustshawn/75d93fef5ba018d4f841683ac844e70b to your computer and use it in GitHub Desktop.
Copy large file with node stream
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