We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
首先引入文件模块 var fs = require('fs');
var fs = require('fs');
function copy(src, target) { console.log(target); fs.writeFileSync(target, fs.readFileSync(src)); }
function copy(src, target) { var rs = fs.createReadStream(src), ws = fs.createWriteStream(target); fs.on('data', function(chunk) { console.log('read'); ws.write(chunk, function() { console.log('write'); }) }) fs.on('end', function() { ws.end(); }) }
根据 Method 2 改进
function copy(src, target) { var rs = fs.createReadStream(src), ws = fs.createWriteStream(target); fs.on('data', function(chunk) { console.log('read'); if (ws.write(chunk, function() { console.log('write'); }) === false) { rs.pause(); } else { rs.resume(); } }) fs.on('end', function() { ws.end(); }) }
node中支持pipe方法,类似于管道,将读出来的内容通过管道写入到目标文件中
function copy(src, target) { fs.createReadStream(src).pipe(fs.createWriteStream(target)); }
1.64G 的文件用了20秒复制完毕,没有内存溢出
The text was updated successfully, but these errors were encountered:
ccforward
No branches or pull requests
首先引入文件模块
var fs = require('fs');
Method 1
Method 2
Method 3
根据 Method 2 改进
Method 4
node中支持pipe方法,类似于管道,将读出来的内容通过管道写入到目标文件中
1.64G 的文件用了20秒复制完毕,没有内存溢出
The text was updated successfully, but these errors were encountered: