不使用wc的解决方案:
var i;var count = 0;require('fs').createReadStream(process.argv[2]) .on('data', function(chunk) { for (i=0; i < chunk.length; ++i) if (chunk[i] == 10) count++; }) .on('end', function() { console.log(count); });速度较慢,但您可能没有想到的那么多-140M +文件的传输时间为0.6秒,包括node.js加载和启动时间
>time node countlines.js video.mp4 619643real 0m0.614suser 0m0.489ssys 0m0.132s>time wc -l video.mp4 619643 video.mp4real 0m0.133suser 0m0.108ssys 0m0.024s>wc -c video.mp4144681406 video.mp4



