@teammy/server 0.2.8 → 0.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +3744 -1673
- package/dist/web/assets/Assistant-C9Zo5FN_.js +1 -0
- package/dist/web/assets/Computers-DNIWiHu4.js +5 -0
- package/dist/web/assets/Computers-XUdWIkZr.css +1 -0
- package/dist/web/assets/{Conversation-CNmGkVy7.css → Conversation-BVNmvuHR.css} +1 -1
- package/dist/web/assets/Conversation-DiVjLVVt.js +1 -0
- package/dist/web/assets/Dashboard-C6M9c0SB.js +1 -0
- package/dist/web/assets/Dashboard-ChX6TZDn.css +1 -0
- package/dist/web/assets/Dropdown-BnYLBw2s.js +55 -0
- package/dist/web/assets/Files-CQcAEYH9.js +1 -0
- package/dist/web/assets/{Help-DwUoT8ZM.js → Help-CDOqVRjJ.js} +158 -37
- package/dist/web/assets/HtmlPreview-BzvYKdju.js +1 -0
- package/dist/web/assets/{Markdown-DorC2YjE.js → Markdown-zJQlHcvy.js} +4 -4
- package/dist/web/assets/MessageComposer-CBI6RiJq.js +1 -0
- package/dist/web/assets/MessageComposer-CJGxkvML.css +1 -0
- package/dist/web/assets/ResourceLibrary-CEFCe7QW.js +6 -0
- package/dist/web/assets/TerminalPane-BrSy-0jI.css +1 -0
- package/dist/web/assets/TerminalPane-GU69G9Ak.js +22 -0
- package/dist/web/assets/WorkspaceTree-BhDZe1go.js +1 -0
- package/dist/web/assets/file-links-V3R--z0b.js +1 -0
- package/dist/web/assets/index-D9m13C7l.js +12 -0
- package/dist/web/assets/index-qX1GRw9I.css +1 -0
- package/dist/web/assets/teammy-logo-dark-GROHRRMa.svg +6 -0
- package/dist/web/assets/teammy-logo-light-B6BoNVcp.svg +6 -0
- package/dist/web/assets/teammy-y-standard-dark-C4LRaRpE.svg +6 -0
- package/dist/web/assets/teammy-y-standard-light-Bl5D78Uj.svg +6 -0
- package/dist/web/downloads/teammy-inbox-skill.zip +0 -0
- package/dist/web/downloads/teammy-skill.zip +0 -0
- package/dist/web/index.html +10 -3
- package/node_modules/@fastify/websocket/.gitattributes +2 -0
- package/node_modules/@fastify/websocket/.github/dependabot.yml +53 -0
- package/node_modules/@fastify/websocket/.github/workflows/ci.yml +33 -0
- package/node_modules/@fastify/websocket/.github/workflows/lock-threads.yml +19 -0
- package/node_modules/@fastify/websocket/.github/workflows/release.yml +24 -0
- package/node_modules/@fastify/websocket/LICENSE +21 -0
- package/node_modules/@fastify/websocket/README.md +393 -0
- package/node_modules/@fastify/websocket/eslint.config.js +6 -0
- package/node_modules/@fastify/websocket/index.js +276 -0
- package/node_modules/@fastify/websocket/package.json +79 -0
- package/node_modules/@fastify/websocket/test/base.test.js +785 -0
- package/node_modules/@fastify/websocket/test/hooks.test.js +414 -0
- package/node_modules/@fastify/websocket/test/inject.test.js +174 -0
- package/node_modules/@fastify/websocket/test/router.test.js +890 -0
- package/node_modules/@fastify/websocket/tsconfig.json +3 -0
- package/node_modules/@fastify/websocket/types/index.d.ts +128 -0
- package/node_modules/@fastify/websocket/types/index.tst.ts +261 -0
- package/node_modules/duplexify/.travis.yml +9 -0
- package/node_modules/duplexify/LICENSE +21 -0
- package/node_modules/duplexify/README.md +97 -0
- package/node_modules/duplexify/example.js +21 -0
- package/node_modules/duplexify/index.js +238 -0
- package/node_modules/duplexify/package.json +39 -0
- package/node_modules/duplexify/test.js +339 -0
- package/node_modules/end-of-stream/LICENSE +21 -0
- package/node_modules/end-of-stream/README.md +54 -0
- package/node_modules/end-of-stream/index.js +96 -0
- package/node_modules/end-of-stream/package.json +37 -0
- package/node_modules/once/LICENSE +15 -0
- package/node_modules/once/README.md +79 -0
- package/node_modules/once/once.js +42 -0
- package/node_modules/once/package.json +33 -0
- package/node_modules/readable-stream/CONTRIBUTING.md +38 -0
- package/node_modules/readable-stream/GOVERNANCE.md +136 -0
- package/node_modules/readable-stream/LICENSE +47 -0
- package/node_modules/readable-stream/README.md +106 -0
- package/node_modules/readable-stream/errors-browser.js +127 -0
- package/node_modules/readable-stream/errors.js +116 -0
- package/node_modules/readable-stream/experimentalWarning.js +17 -0
- package/node_modules/readable-stream/lib/_stream_duplex.js +126 -0
- package/node_modules/readable-stream/lib/_stream_passthrough.js +37 -0
- package/node_modules/readable-stream/lib/_stream_readable.js +1027 -0
- package/node_modules/readable-stream/lib/_stream_transform.js +190 -0
- package/node_modules/readable-stream/lib/_stream_writable.js +641 -0
- package/node_modules/readable-stream/lib/internal/streams/async_iterator.js +180 -0
- package/node_modules/readable-stream/lib/internal/streams/buffer_list.js +183 -0
- package/node_modules/readable-stream/lib/internal/streams/destroy.js +96 -0
- package/node_modules/readable-stream/lib/internal/streams/end-of-stream.js +86 -0
- package/node_modules/readable-stream/lib/internal/streams/from-browser.js +3 -0
- package/node_modules/readable-stream/lib/internal/streams/from.js +52 -0
- package/node_modules/readable-stream/lib/internal/streams/pipeline.js +86 -0
- package/node_modules/readable-stream/lib/internal/streams/state.js +22 -0
- package/node_modules/readable-stream/lib/internal/streams/stream-browser.js +1 -0
- package/node_modules/readable-stream/lib/internal/streams/stream.js +1 -0
- package/node_modules/readable-stream/package.json +68 -0
- package/node_modules/readable-stream/readable-browser.js +9 -0
- package/node_modules/readable-stream/readable.js +16 -0
- package/node_modules/stream-shift/.github/workflows/test.yml +23 -0
- package/node_modules/stream-shift/LICENSE +21 -0
- package/node_modules/stream-shift/README.md +25 -0
- package/node_modules/stream-shift/index.js +21 -0
- package/node_modules/stream-shift/package.json +25 -0
- package/node_modules/stream-shift/test.js +48 -0
- package/node_modules/string_decoder/LICENSE +48 -0
- package/node_modules/string_decoder/README.md +47 -0
- package/node_modules/string_decoder/lib/string_decoder.js +296 -0
- package/node_modules/string_decoder/package.json +34 -0
- package/node_modules/util-deprecate/History.md +16 -0
- package/node_modules/util-deprecate/LICENSE +24 -0
- package/node_modules/util-deprecate/README.md +53 -0
- package/node_modules/util-deprecate/browser.js +67 -0
- package/node_modules/util-deprecate/node.js +6 -0
- package/node_modules/util-deprecate/package.json +27 -0
- package/node_modules/wrappy/LICENSE +15 -0
- package/node_modules/wrappy/README.md +36 -0
- package/node_modules/wrappy/package.json +29 -0
- package/node_modules/wrappy/wrappy.js +33 -0
- package/package.json +15 -2
- package/dist/web/assets/Assistant-CYSa4zNi.js +0 -1
- package/dist/web/assets/Computers-4L48XuFg.js +0 -4
- package/dist/web/assets/Computers-_ugR447I.css +0 -1
- package/dist/web/assets/Conversation-BBWm5w-C.js +0 -1
- package/dist/web/assets/Dashboard-Bdh00JcC.css +0 -1
- package/dist/web/assets/Dashboard-Ck2NsAbX.js +0 -1
- package/dist/web/assets/Files-CjNjoKS3.js +0 -1
- package/dist/web/assets/HtmlPreview-B6aQIaMB.js +0 -1
- package/dist/web/assets/MessageComposer-DQBDG5yF.js +0 -1
- package/dist/web/assets/MessageComposer-DavJdQPa.css +0 -1
- package/dist/web/assets/ResourceLibrary-104NuVRn.js +0 -6
- package/dist/web/assets/WorkspaceTree-B4FMRlCw.js +0 -1
- package/dist/web/assets/file-links-DnngiTbC.js +0 -1
- package/dist/web/assets/index-6PvvMCD7.css +0 -1
- package/dist/web/assets/index-DiR0ePCJ.js +0 -66
- package/dist/web/assets/teammy-calm-DVuoOK0F.png +0 -0
- package/dist/web/assets/teammy-favicon-BiDvlPj2.png +0 -0
- package/dist/web/assets/teammy-mark-CxBtF1-X.png +0 -0
- package/dist/web/assets/teammy-wave-CVTgecuC.png +0 -0
- package/dist/web/assets/teammy-wordmark-ZFwxG0yl.png +0 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
var stream = require('readable-stream')
|
|
2
|
+
var eos = require('end-of-stream')
|
|
3
|
+
var inherits = require('inherits')
|
|
4
|
+
var shift = require('stream-shift')
|
|
5
|
+
|
|
6
|
+
var SIGNAL_FLUSH = (Buffer.from && Buffer.from !== Uint8Array.from)
|
|
7
|
+
? Buffer.from([0])
|
|
8
|
+
: new Buffer([0])
|
|
9
|
+
|
|
10
|
+
var onuncork = function(self, fn) {
|
|
11
|
+
if (self._corked) self.once('uncork', fn)
|
|
12
|
+
else fn()
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
var autoDestroy = function (self, err) {
|
|
16
|
+
if (self._autoDestroy) self.destroy(err)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
var destroyer = function(self, end) {
|
|
20
|
+
return function(err) {
|
|
21
|
+
if (err) autoDestroy(self, err.message === 'premature close' ? null : err)
|
|
22
|
+
else if (end && !self._ended) self.end()
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var end = function(ws, fn) {
|
|
27
|
+
if (!ws) return fn()
|
|
28
|
+
if (ws._writableState && ws._writableState.finished) return fn()
|
|
29
|
+
if (ws._writableState) return ws.end(fn)
|
|
30
|
+
ws.end()
|
|
31
|
+
fn()
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var noop = function() {}
|
|
35
|
+
|
|
36
|
+
var toStreams2 = function(rs) {
|
|
37
|
+
return new (stream.Readable)({objectMode:true, highWaterMark:16}).wrap(rs)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
var Duplexify = function(writable, readable, opts) {
|
|
41
|
+
if (!(this instanceof Duplexify)) return new Duplexify(writable, readable, opts)
|
|
42
|
+
stream.Duplex.call(this, opts)
|
|
43
|
+
|
|
44
|
+
this._writable = null
|
|
45
|
+
this._readable = null
|
|
46
|
+
this._readable2 = null
|
|
47
|
+
|
|
48
|
+
this._autoDestroy = !opts || opts.autoDestroy !== false
|
|
49
|
+
this._forwardDestroy = !opts || opts.destroy !== false
|
|
50
|
+
this._forwardEnd = !opts || opts.end !== false
|
|
51
|
+
this._corked = 1 // start corked
|
|
52
|
+
this._ondrain = null
|
|
53
|
+
this._drained = false
|
|
54
|
+
this._forwarding = false
|
|
55
|
+
this._unwrite = null
|
|
56
|
+
this._unread = null
|
|
57
|
+
this._ended = false
|
|
58
|
+
|
|
59
|
+
this.destroyed = false
|
|
60
|
+
|
|
61
|
+
if (writable) this.setWritable(writable)
|
|
62
|
+
if (readable) this.setReadable(readable)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
inherits(Duplexify, stream.Duplex)
|
|
66
|
+
|
|
67
|
+
Duplexify.obj = function(writable, readable, opts) {
|
|
68
|
+
if (!opts) opts = {}
|
|
69
|
+
opts.objectMode = true
|
|
70
|
+
opts.highWaterMark = 16
|
|
71
|
+
return new Duplexify(writable, readable, opts)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
Duplexify.prototype.cork = function() {
|
|
75
|
+
if (++this._corked === 1) this.emit('cork')
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
Duplexify.prototype.uncork = function() {
|
|
79
|
+
if (this._corked && --this._corked === 0) this.emit('uncork')
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
Duplexify.prototype.setWritable = function(writable) {
|
|
83
|
+
if (this._unwrite) this._unwrite()
|
|
84
|
+
|
|
85
|
+
if (this.destroyed) {
|
|
86
|
+
if (writable && writable.destroy) writable.destroy()
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (writable === null || writable === false) {
|
|
91
|
+
this.end()
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
var self = this
|
|
96
|
+
var unend = eos(writable, {writable:true, readable:false}, destroyer(this, this._forwardEnd))
|
|
97
|
+
|
|
98
|
+
var ondrain = function() {
|
|
99
|
+
var ondrain = self._ondrain
|
|
100
|
+
self._ondrain = null
|
|
101
|
+
if (ondrain) ondrain()
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
var clear = function() {
|
|
105
|
+
self._writable.removeListener('drain', ondrain)
|
|
106
|
+
unend()
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (this._unwrite) process.nextTick(ondrain) // force a drain on stream reset to avoid livelocks
|
|
110
|
+
|
|
111
|
+
this._writable = writable
|
|
112
|
+
this._writable.on('drain', ondrain)
|
|
113
|
+
this._unwrite = clear
|
|
114
|
+
|
|
115
|
+
this.uncork() // always uncork setWritable
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
Duplexify.prototype.setReadable = function(readable) {
|
|
119
|
+
if (this._unread) this._unread()
|
|
120
|
+
|
|
121
|
+
if (this.destroyed) {
|
|
122
|
+
if (readable && readable.destroy) readable.destroy()
|
|
123
|
+
return
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (readable === null || readable === false) {
|
|
127
|
+
this.push(null)
|
|
128
|
+
this.resume()
|
|
129
|
+
return
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
var self = this
|
|
133
|
+
var unend = eos(readable, {writable:false, readable:true}, destroyer(this))
|
|
134
|
+
|
|
135
|
+
var onreadable = function() {
|
|
136
|
+
self._forward()
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
var onend = function() {
|
|
140
|
+
self.push(null)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
var clear = function() {
|
|
144
|
+
self._readable2.removeListener('readable', onreadable)
|
|
145
|
+
self._readable2.removeListener('end', onend)
|
|
146
|
+
unend()
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
this._drained = true
|
|
150
|
+
this._readable = readable
|
|
151
|
+
this._readable2 = readable._readableState ? readable : toStreams2(readable)
|
|
152
|
+
this._readable2.on('readable', onreadable)
|
|
153
|
+
this._readable2.on('end', onend)
|
|
154
|
+
this._unread = clear
|
|
155
|
+
|
|
156
|
+
this._forward()
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
Duplexify.prototype._read = function() {
|
|
160
|
+
this._drained = true
|
|
161
|
+
this._forward()
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
Duplexify.prototype._forward = function() {
|
|
165
|
+
if (this._forwarding || !this._readable2 || !this._drained) return
|
|
166
|
+
this._forwarding = true
|
|
167
|
+
|
|
168
|
+
var data
|
|
169
|
+
|
|
170
|
+
while (this._drained && (data = shift(this._readable2)) !== null) {
|
|
171
|
+
if (this.destroyed) continue
|
|
172
|
+
this._drained = this.push(data)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
this._forwarding = false
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
Duplexify.prototype.destroy = function(err, cb) {
|
|
179
|
+
if (!cb) cb = noop
|
|
180
|
+
if (this.destroyed) return cb(null)
|
|
181
|
+
this.destroyed = true
|
|
182
|
+
|
|
183
|
+
var self = this
|
|
184
|
+
process.nextTick(function() {
|
|
185
|
+
self._destroy(err)
|
|
186
|
+
cb(null)
|
|
187
|
+
})
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
Duplexify.prototype._destroy = function(err) {
|
|
191
|
+
if (err) {
|
|
192
|
+
var ondrain = this._ondrain
|
|
193
|
+
this._ondrain = null
|
|
194
|
+
if (ondrain) ondrain(err)
|
|
195
|
+
else this.emit('error', err)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (this._forwardDestroy) {
|
|
199
|
+
if (this._readable && this._readable.destroy) this._readable.destroy()
|
|
200
|
+
if (this._writable && this._writable.destroy) this._writable.destroy()
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
this.emit('close')
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
Duplexify.prototype._write = function(data, enc, cb) {
|
|
207
|
+
if (this.destroyed) return
|
|
208
|
+
if (this._corked) return onuncork(this, this._write.bind(this, data, enc, cb))
|
|
209
|
+
if (data === SIGNAL_FLUSH) return this._finish(cb)
|
|
210
|
+
if (!this._writable) return cb()
|
|
211
|
+
|
|
212
|
+
if (this._writable.write(data) === false) this._ondrain = cb
|
|
213
|
+
else if (!this.destroyed) cb()
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
Duplexify.prototype._finish = function(cb) {
|
|
217
|
+
var self = this
|
|
218
|
+
this.emit('preend')
|
|
219
|
+
onuncork(this, function() {
|
|
220
|
+
end(self._forwardEnd && self._writable, function() {
|
|
221
|
+
// haxx to not emit prefinish twice
|
|
222
|
+
if (self._writableState.prefinished === false) self._writableState.prefinished = true
|
|
223
|
+
self.emit('prefinish')
|
|
224
|
+
onuncork(self, cb)
|
|
225
|
+
})
|
|
226
|
+
})
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
Duplexify.prototype.end = function(data, enc, cb) {
|
|
230
|
+
if (typeof data === 'function') return this.end(null, null, data)
|
|
231
|
+
if (typeof enc === 'function') return this.end(data, null, enc)
|
|
232
|
+
this._ended = true
|
|
233
|
+
if (data) this.write(data)
|
|
234
|
+
if (!this._writableState.ending && !this._writableState.destroyed) this.write(SIGNAL_FLUSH)
|
|
235
|
+
return stream.Writable.prototype.end.call(this, cb)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
module.exports = Duplexify
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "duplexify",
|
|
3
|
+
"version": "4.1.3",
|
|
4
|
+
"description": "Turn a writable and readable stream into a streams2 duplex stream with support for async initialization and streams1/streams2 input",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"end-of-stream": "^1.4.1",
|
|
8
|
+
"inherits": "^2.0.3",
|
|
9
|
+
"readable-stream": "^3.1.1",
|
|
10
|
+
"stream-shift": "^1.0.2"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"concat-stream": "^1.5.2",
|
|
14
|
+
"tape": "^4.0.0",
|
|
15
|
+
"through2": "^2.0.0"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test": "tape test.js"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git://github.com/mafintosh/duplexify"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"duplex",
|
|
26
|
+
"streams2",
|
|
27
|
+
"streams",
|
|
28
|
+
"stream",
|
|
29
|
+
"writable",
|
|
30
|
+
"readable",
|
|
31
|
+
"async"
|
|
32
|
+
],
|
|
33
|
+
"author": "Mathias Buus",
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/mafintosh/duplexify/issues"
|
|
37
|
+
},
|
|
38
|
+
"homepage": "https://github.com/mafintosh/duplexify"
|
|
39
|
+
}
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
var tape = require('tape')
|
|
2
|
+
var through = require('through2')
|
|
3
|
+
var concat = require('concat-stream')
|
|
4
|
+
var stream = require('readable-stream')
|
|
5
|
+
var net = require('net')
|
|
6
|
+
var duplexify = require('./')
|
|
7
|
+
|
|
8
|
+
var HELLO_WORLD = (Buffer.from && Buffer.from !== Uint8Array.from)
|
|
9
|
+
? Buffer.from('hello world')
|
|
10
|
+
: new Buffer('hello world')
|
|
11
|
+
|
|
12
|
+
tape('passthrough', function(t) {
|
|
13
|
+
t.plan(2)
|
|
14
|
+
|
|
15
|
+
var pt = through()
|
|
16
|
+
var dup = duplexify(pt, pt)
|
|
17
|
+
|
|
18
|
+
dup.end('hello world')
|
|
19
|
+
dup.on('finish', function() {
|
|
20
|
+
t.ok(true, 'should finish')
|
|
21
|
+
})
|
|
22
|
+
dup.pipe(concat(function(data) {
|
|
23
|
+
t.same(data.toString(), 'hello world', 'same in as out')
|
|
24
|
+
}))
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
tape('passthrough + double end', function(t) {
|
|
28
|
+
t.plan(2)
|
|
29
|
+
|
|
30
|
+
var pt = through()
|
|
31
|
+
var dup = duplexify(pt, pt)
|
|
32
|
+
|
|
33
|
+
dup.end('hello world')
|
|
34
|
+
dup.end()
|
|
35
|
+
|
|
36
|
+
dup.on('finish', function() {
|
|
37
|
+
t.ok(true, 'should finish')
|
|
38
|
+
})
|
|
39
|
+
dup.pipe(concat(function(data) {
|
|
40
|
+
t.same(data.toString(), 'hello world', 'same in as out')
|
|
41
|
+
}))
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
tape('async passthrough + end', function(t) {
|
|
45
|
+
t.plan(2)
|
|
46
|
+
|
|
47
|
+
var pt = through.obj({highWaterMark:1}, function(data, enc, cb) {
|
|
48
|
+
setTimeout(function() {
|
|
49
|
+
cb(null, data)
|
|
50
|
+
}, 100)
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
var dup = duplexify(pt, pt)
|
|
54
|
+
|
|
55
|
+
dup.write('hello ')
|
|
56
|
+
dup.write('world')
|
|
57
|
+
dup.end()
|
|
58
|
+
|
|
59
|
+
dup.on('finish', function() {
|
|
60
|
+
t.ok(true, 'should finish')
|
|
61
|
+
})
|
|
62
|
+
dup.pipe(concat(function(data) {
|
|
63
|
+
t.same(data.toString(), 'hello world', 'same in as out')
|
|
64
|
+
}))
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
tape('duplex', function(t) {
|
|
68
|
+
var readExpected = ['read-a', 'read-b', 'read-c']
|
|
69
|
+
var writeExpected = ['write-a', 'write-b', 'write-c']
|
|
70
|
+
|
|
71
|
+
t.plan(readExpected.length+writeExpected.length+2)
|
|
72
|
+
|
|
73
|
+
var readable = through.obj()
|
|
74
|
+
var writable = through.obj(function(data, enc, cb) {
|
|
75
|
+
t.same(data, writeExpected.shift(), 'onwrite should match')
|
|
76
|
+
cb()
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
var dup = duplexify.obj(writable, readable)
|
|
80
|
+
|
|
81
|
+
readExpected.slice().forEach(function(data) {
|
|
82
|
+
readable.write(data)
|
|
83
|
+
})
|
|
84
|
+
readable.end()
|
|
85
|
+
|
|
86
|
+
writeExpected.slice().forEach(function(data) {
|
|
87
|
+
dup.write(data)
|
|
88
|
+
})
|
|
89
|
+
dup.end()
|
|
90
|
+
|
|
91
|
+
dup.on('data', function(data) {
|
|
92
|
+
t.same(data, readExpected.shift(), 'ondata should match')
|
|
93
|
+
})
|
|
94
|
+
dup.on('end', function() {
|
|
95
|
+
t.ok(true, 'should end')
|
|
96
|
+
})
|
|
97
|
+
dup.on('finish', function() {
|
|
98
|
+
t.ok(true, 'should finish')
|
|
99
|
+
})
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
tape('async', function(t) {
|
|
103
|
+
var dup = duplexify()
|
|
104
|
+
var pt = through()
|
|
105
|
+
|
|
106
|
+
dup.pipe(concat(function(data) {
|
|
107
|
+
t.same(data.toString(), 'i was async', 'same in as out')
|
|
108
|
+
t.end()
|
|
109
|
+
}))
|
|
110
|
+
|
|
111
|
+
dup.write('i')
|
|
112
|
+
dup.write(' was ')
|
|
113
|
+
dup.end('async')
|
|
114
|
+
|
|
115
|
+
setTimeout(function() {
|
|
116
|
+
dup.setWritable(pt)
|
|
117
|
+
setTimeout(function() {
|
|
118
|
+
dup.setReadable(pt)
|
|
119
|
+
}, 50)
|
|
120
|
+
}, 50)
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
tape('destroy', function(t) {
|
|
124
|
+
t.plan(2)
|
|
125
|
+
|
|
126
|
+
var write = through()
|
|
127
|
+
var read = through()
|
|
128
|
+
var dup = duplexify(write, read)
|
|
129
|
+
|
|
130
|
+
write.destroy = function() {
|
|
131
|
+
t.ok(true, 'write destroyed')
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
dup.on('close', function() {
|
|
135
|
+
t.ok(true, 'close emitted')
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
dup.destroy()
|
|
139
|
+
dup.destroy() // should only work once
|
|
140
|
+
dup.end()
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
tape('destroy both', function(t) {
|
|
144
|
+
t.plan(3)
|
|
145
|
+
|
|
146
|
+
var write = through()
|
|
147
|
+
var read = through()
|
|
148
|
+
var dup = duplexify(write, read)
|
|
149
|
+
|
|
150
|
+
write.destroy = function() {
|
|
151
|
+
t.ok(true, 'write destroyed')
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
read.destroy = function() {
|
|
155
|
+
t.ok(true, 'read destroyed')
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
dup.on('close', function() {
|
|
159
|
+
t.ok(true, 'close emitted')
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
dup.destroy()
|
|
163
|
+
dup.destroy() // should only work once
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
tape('bubble read errors', function(t) {
|
|
167
|
+
t.plan(2)
|
|
168
|
+
|
|
169
|
+
var write = through()
|
|
170
|
+
var read = through()
|
|
171
|
+
var dup = duplexify(write, read)
|
|
172
|
+
|
|
173
|
+
dup.on('error', function(err) {
|
|
174
|
+
t.same(err.message, 'read-error', 'received read error')
|
|
175
|
+
})
|
|
176
|
+
dup.on('close', function() {
|
|
177
|
+
t.ok(true, 'close emitted')
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
read.emit('error', new Error('read-error'))
|
|
181
|
+
write.emit('error', new Error('write-error')) // only emit first error
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
tape('bubble write errors', function(t) {
|
|
185
|
+
t.plan(2)
|
|
186
|
+
|
|
187
|
+
var write = through()
|
|
188
|
+
var read = through()
|
|
189
|
+
var dup = duplexify(write, read)
|
|
190
|
+
|
|
191
|
+
dup.on('error', function(err) {
|
|
192
|
+
t.same(err.message, 'write-error', 'received write error')
|
|
193
|
+
})
|
|
194
|
+
dup.on('close', function() {
|
|
195
|
+
t.ok(true, 'close emitted')
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
write.emit('error', new Error('write-error'))
|
|
199
|
+
read.emit('error', new Error('read-error')) // only emit first error
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
tape('bubble errors from write()', function(t) {
|
|
203
|
+
t.plan(3)
|
|
204
|
+
|
|
205
|
+
var errored = false
|
|
206
|
+
var dup = duplexify(new stream.Writable({
|
|
207
|
+
write: function(chunk, enc, next) {
|
|
208
|
+
next(new Error('write-error'))
|
|
209
|
+
}
|
|
210
|
+
}))
|
|
211
|
+
|
|
212
|
+
dup.on('error', function(err) {
|
|
213
|
+
errored = true
|
|
214
|
+
t.same(err.message, 'write-error', 'received write error')
|
|
215
|
+
})
|
|
216
|
+
dup.on('close', function() {
|
|
217
|
+
t.pass('close emitted')
|
|
218
|
+
t.ok(errored, 'error was emitted before close')
|
|
219
|
+
})
|
|
220
|
+
dup.end('123')
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
tape('destroy while waiting for drain', function(t) {
|
|
224
|
+
t.plan(3)
|
|
225
|
+
|
|
226
|
+
var errored = false
|
|
227
|
+
var dup = duplexify(new stream.Writable({
|
|
228
|
+
highWaterMark: 0,
|
|
229
|
+
write: function() {}
|
|
230
|
+
}))
|
|
231
|
+
|
|
232
|
+
dup.on('error', function(err) {
|
|
233
|
+
errored = true
|
|
234
|
+
t.same(err.message, 'destroy-error', 'received destroy error')
|
|
235
|
+
})
|
|
236
|
+
dup.on('close', function() {
|
|
237
|
+
t.pass('close emitted')
|
|
238
|
+
t.ok(errored, 'error was emitted before close')
|
|
239
|
+
})
|
|
240
|
+
dup.write('123')
|
|
241
|
+
dup.destroy(new Error('destroy-error'))
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
tape('reset writable / readable', function(t) {
|
|
245
|
+
t.plan(3)
|
|
246
|
+
|
|
247
|
+
var toUpperCase = function(data, enc, cb) {
|
|
248
|
+
cb(null, data.toString().toUpperCase())
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
var passthrough = through()
|
|
252
|
+
var upper = through(toUpperCase)
|
|
253
|
+
var dup = duplexify(passthrough, passthrough)
|
|
254
|
+
|
|
255
|
+
dup.once('data', function(data) {
|
|
256
|
+
t.same(data.toString(), 'hello')
|
|
257
|
+
dup.setWritable(upper)
|
|
258
|
+
dup.setReadable(upper)
|
|
259
|
+
dup.once('data', function(data) {
|
|
260
|
+
t.same(data.toString(), 'HELLO')
|
|
261
|
+
dup.once('data', function(data) {
|
|
262
|
+
t.same(data.toString(), 'HI')
|
|
263
|
+
t.end()
|
|
264
|
+
})
|
|
265
|
+
})
|
|
266
|
+
dup.write('hello')
|
|
267
|
+
dup.write('hi')
|
|
268
|
+
})
|
|
269
|
+
dup.write('hello')
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
tape('cork', function(t) {
|
|
273
|
+
var passthrough = through()
|
|
274
|
+
var dup = duplexify(passthrough, passthrough)
|
|
275
|
+
var ok = false
|
|
276
|
+
|
|
277
|
+
dup.on('prefinish', function() {
|
|
278
|
+
dup.cork()
|
|
279
|
+
setTimeout(function() {
|
|
280
|
+
ok = true
|
|
281
|
+
dup.uncork()
|
|
282
|
+
}, 100)
|
|
283
|
+
})
|
|
284
|
+
dup.on('finish', function() {
|
|
285
|
+
t.ok(ok)
|
|
286
|
+
t.end()
|
|
287
|
+
})
|
|
288
|
+
dup.end()
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
tape('prefinish not twice', function(t) {
|
|
292
|
+
var passthrough = through()
|
|
293
|
+
var dup = duplexify(passthrough, passthrough)
|
|
294
|
+
var prefinished = false
|
|
295
|
+
|
|
296
|
+
dup.on('prefinish', function() {
|
|
297
|
+
t.ok(!prefinished, 'only prefinish once')
|
|
298
|
+
prefinished = true
|
|
299
|
+
})
|
|
300
|
+
|
|
301
|
+
dup.on('finish', function() {
|
|
302
|
+
t.end()
|
|
303
|
+
})
|
|
304
|
+
|
|
305
|
+
dup.end()
|
|
306
|
+
})
|
|
307
|
+
|
|
308
|
+
tape('close', function(t) {
|
|
309
|
+
var passthrough = through()
|
|
310
|
+
var dup = duplexify(passthrough, passthrough)
|
|
311
|
+
|
|
312
|
+
passthrough.emit('close')
|
|
313
|
+
dup.on('close', function() {
|
|
314
|
+
t.ok(true, 'should forward close')
|
|
315
|
+
t.end()
|
|
316
|
+
})
|
|
317
|
+
})
|
|
318
|
+
|
|
319
|
+
tape('works with node native streams (net)', function(t) {
|
|
320
|
+
t.plan(1)
|
|
321
|
+
|
|
322
|
+
var server = net.createServer(function(socket) {
|
|
323
|
+
var dup = duplexify(socket, socket)
|
|
324
|
+
|
|
325
|
+
dup.once('data', function(chunk) {
|
|
326
|
+
t.same(chunk, HELLO_WORLD)
|
|
327
|
+
server.close()
|
|
328
|
+
socket.end()
|
|
329
|
+
t.end()
|
|
330
|
+
})
|
|
331
|
+
})
|
|
332
|
+
|
|
333
|
+
server.listen(0, function () {
|
|
334
|
+
var socket = net.connect(server.address().port)
|
|
335
|
+
var dup = duplexify(socket, socket)
|
|
336
|
+
|
|
337
|
+
dup.write(HELLO_WORLD)
|
|
338
|
+
})
|
|
339
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014 Mathias Buus
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# end-of-stream
|
|
2
|
+
|
|
3
|
+
A node module that calls a callback when a readable/writable/duplex stream has completed or failed.
|
|
4
|
+
|
|
5
|
+
npm install end-of-stream
|
|
6
|
+
|
|
7
|
+
[](https://travis-ci.org/mafintosh/end-of-stream)
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
Simply pass a stream and a callback to the `eos`.
|
|
12
|
+
Both legacy streams, streams2 and stream3 are supported.
|
|
13
|
+
|
|
14
|
+
``` js
|
|
15
|
+
var eos = require('end-of-stream');
|
|
16
|
+
|
|
17
|
+
eos(readableStream, function(err) {
|
|
18
|
+
// this will be set to the stream instance
|
|
19
|
+
if (err) return console.log('stream had an error or closed early');
|
|
20
|
+
console.log('stream has ended', this === readableStream);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
eos(writableStream, function(err) {
|
|
24
|
+
if (err) return console.log('stream had an error or closed early');
|
|
25
|
+
console.log('stream has finished', this === writableStream);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
eos(duplexStream, function(err) {
|
|
29
|
+
if (err) return console.log('stream had an error or closed early');
|
|
30
|
+
console.log('stream has ended and finished', this === duplexStream);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
eos(duplexStream, {readable:false}, function(err) {
|
|
34
|
+
if (err) return console.log('stream had an error or closed early');
|
|
35
|
+
console.log('stream has finished but might still be readable');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
eos(duplexStream, {writable:false}, function(err) {
|
|
39
|
+
if (err) return console.log('stream had an error or closed early');
|
|
40
|
+
console.log('stream has ended but might still be writable');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
eos(readableStream, {error:false}, function(err) {
|
|
44
|
+
// do not treat emit('error', err) as a end-of-stream
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## License
|
|
49
|
+
|
|
50
|
+
MIT
|
|
51
|
+
|
|
52
|
+
## Related
|
|
53
|
+
|
|
54
|
+
`end-of-stream` is part of the [mississippi stream utility collection](https://github.com/maxogden/mississippi) which includes more useful stream modules similar to this one.
|