function calcLineCount(filename, callback) {
var fs = require('fs'); var fileStream = fs.createReadStream(filename),
lines = 0; fileStream.on('data', function (buf) {
lines += buf.toString().match(/\n/g).length + 1;
}); fileStream.on('end', function () {
callback(lines);
});
} calcLineCount('/Users/piaoger/Downloads/lc.js', function(lines) {
console.log(lines);
});

其实也可以直接在Node.js中调用“wc”来解决问题的。只不过我之前用str.split(/\n/).length来做,应该会比match慢吧。

Piaoger

最新文章

  1. Linux学习之CentOS(二十二)--单用户模式下修改Root用户的密码
  2. Python网络socket学习
  3. iOS常用第三方
  4. 打印出所有的 "水仙花数 ",所谓 "水仙花数 "是指一个三位数 其各位数字立方和等于该数本身。 例如:153是一个 "水仙花数 " 因为153=1*1*1+5*5*5+3*3*3
  5. 金蝶EAS常用表
  6. MVC项目实践,在三层架构下实现SportsStore-08,部署到IIS服务器
  7. List,set,Map 的用法和区别
  8. Swift学习初步(一)
  9. System Generator入门笔记
  10. 在ubuntu系统荣品开发配套JDK安装
  11. CSS+Javascript的那些框架
  12. iOS7——图像资源Images Assets
  13. 2014.8.20break,continue,字符串,数字和日期
  14. vscode: Visual Studio Code 常用快捷键
  15. SQLite基础回顾
  16. oracle 常用知识积累
  17. SQL 高效运行注意事项(二)
  18. Git冲突:You have not concluded your merge
  19. Django之验证码
  20. composer 出现You are running Composer with SSL/TLS protection disabled.

热门文章

  1. RocketMQ 拉取消息-文件获取
  2. PHP的抽象类、接口的区别和选择[转载]
  3. Python strings, 元组tuples, 和numbers是不可更改的对象,而list,dict等则是可以修改的
  4. JMeter 五:监控服务器
  5. Android常用酷炫控件(开源项目)github地址汇总
  6. 基于Prometheus搭建SpringCloud全方位立体监控体系
  7. github 管理图示
  8. 08-session详解
  9. java数据库操作:JDBC的操作
  10. 项目启动报错:No suitable driver found for jdbc:oracle:thin:@192.168.7.146:1521:oracle