-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
57 lines (48 loc) · 1.11 KB
/
index.js
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
50
51
52
53
54
55
56
var Stream = require('stream')
var inherits = require('util').inherits
inherits(InvertStream, Stream)
function InvertStream (other) {
this.writable = this.readable = true
this.paused = false
if(other) {
this.other = other
other.other = this
this.b = other
other.a = this
}
}
InvertStream.prototype.write =
function (data) {
this.other.emit('data', data)
return !this.paused
}
InvertStream.prototype.end =
function () {
this.writable = false
this.other.readable = false
this.other.emit('end')
}
InvertStream.prototype.destroy =
function () {
this.writable = this.readable =
this.other.readable = this.other.writable = false
this.emit('close')
this.other.emit('close')
}
InvertStream.prototype.pause =
function () {
this.other.paused = true
this.other.emit('pause')
return this
}
InvertStream.prototype.resume =
function () {
this.other.paused = false
this.other.emit('drain')
return this
}
exports =
module.exports = function () {
return new InvertStream(new InvertStream())
}
exports.InvertStream = InvertStream