-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathReadable.js
More file actions
49 lines (39 loc) · 787 Bytes
/
Readable.js
File metadata and controls
49 lines (39 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var Readable = require('stream').Readable
// -- Long version --
var inherits = require('inherits')
inherits(MyReadable, Readable)
function MyReadable () {
Readable.call(this)
this._read = function () {
var data = 'payload'
this.push(data)
this.push(null)
}
}
var readStream = new MyReadable()
// -- Short version --
var readStream2 = new Readable({
read: function () {
var data = 'payload'
this.push(data)
this.push(null)
}
})
// -- Methods --
// .read([size])
// .setEncoding(encoding)
// .pause()
// .isPaused()
// .resume()
// .readable.unshift(chunk)
// .pipe(destination[, options])
// .unpipe([destination])
// -- Events --
readStream.on('data', (buff) => {
console.log(buff.toString())
})
// data
// end
// close
// error
// readable