nodejs中的流
来源:互联网 发布:actor critic知乎 编辑:程序博客网 时间:2024/06/05 19:06
首先定义:流 在nodejs中流是一个对象
nodejs官方写了一个核心模块stream【流】,来操作流
var sr = new stream.Readable
//创建写流对象
var sw = new stream.Writable //这里是没有e的
2.继承:stream继承自EventEmitter对象,因此读流和写流就拥有on 和 emit的方法
console.log('yes')
})
//读写流 也是继承自EventEmitter
var sd = new stream.Duplex//创建读写流
//读写流应用 on、emit
sd.on('duplex',function(){
console.log('nice')
})
nodejs官方写了一个核心模块stream【流】,来操作流
1.对于nodejs中的流,分为读流对象 写流对象 还有一种特殊的读写流
var stream = require('stream')//引入流对象
var sr = new stream.Readable
//创建写流对象
var sw = new stream.Writable //这里是没有e的
2.继承:stream继承自EventEmitter对象,因此读流和写流就拥有on 和 emit的方法
读流事件应用 on、emit 的例子:
sr.on('big',function(){
console.log('ok')
})
sr.emit('big')写流应用 on、emit 的例子:
console.log('yes')
})
sw.emit('write')
//读写流 也是继承自EventEmitter
var sd = new stream.Duplex//创建读写流
//读写流应用 on、emit
sd.on('duplex',function(){
console.log('nice')
})
sd.emit('duplex')
以上就是木持原对读流,写流,还有读写流(毒瘤,血流,毒血瘤)的简单介绍。
阅读全文
0 0
- Nodejs中的流
- nodejs中的流
- nodejs中的管道流和链式流
- nodejs中的require解析
- nodejs中的cron
- nodejs中的几个对象
- nodejs中的Crypto模块
- NodeJS中的promise思考
- nodejs中的HTTP请求
- NodeJS中的循环陷阱
- nodejs中的模块定义
- nodejs 中的 NODE_PATH
- nodejs中的underscore.js
- nodejs 中的 NODE_PATH
- nodejs中的中间件--Multer
- nodejs中的fs模块
- nodejs中的模块
- nodeJS中的事件--event
- VMware Workstation Pro14虚拟机破解版(附注册机+序列号+安装教程) 32/64位
- HTML5 音频,视频
- Hierarchical Notation ZOJ
- 什么是JWT
- HTTP状态码汇总
- nodejs中的流
- Java打飞机小游戏(附完整源码)
- Android中装饰者模式
- leetcode 617. Merge Two Binary Trees(C语言,二叉树求和,递归)53
- java 画数学函数图
- 3react初体验-1版本的选择
- springcloud 中关于编码的认识
- Opencv中at<> 与ptr<> 的不同
- Kali-linux密码在线破解-Hydra工具