码迷,mamicode.com
首页 > 其他好文 > 详细

stream

时间:2017-05-29 18:16:54      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:stream   unshift   set   方法   UI   pipe   creates   code   pause   

1.四个流类型。 读、写、可读写和可改变四个流。

2.看一个例子:

var destroy = require(‘destroy‘)
var http = require(‘http‘)
var onFinished = require(‘on-finished‘)
 
http.createServer(function onRequest(req, res) {
  var stream = fs.createReadStream(‘package.json‘)
  //res为一个可写流,pipe是把源流输出到目标可写流(writable)
  stream.pipe(res)
  //如果完成,触发销毁这个流
  onFinished(res, function (err) {
    destroy(stream)
  })
})

 3.stream类的原型

var Stream = require(‘stream‘);
//Stream { pipe: [Function] },  只有一个pipe方法。
console.log(Stream.prototype);

 4.可读流的方法

var Stream = require(‘stream‘);
var readableStream = Stream.Readable;
/*
    Readable {
      push: [Function],
      unshift: [Function],
      isPaused: [Function],
      setEncoding: [Function],
      read: [Function],
      _read: [Function],
      pipe: [Function],
      unpipe: [Function],
      on: [Function],
      addListener: [Function],
      resume: [Function],
      pause: [Function],
      wrap: [Function] 
    }
 */
console.log(readableStream.prototype);

 

stream

标签:stream   unshift   set   方法   UI   pipe   creates   code   pause   

原文地址:http://www.cnblogs.com/liuyinlei/p/6918441.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!