2db47680
hexiaodong
chore: 初始提交 php 遗...
|
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
|
const stream = require('stream')
const util = require('util')
function WritableStream () {
stream.Writable.call(this)
this.forceError = false
this.once('finish', function () {
this.close()
})
}
util.inherits(WritableStream, stream.Writable)
WritableStream.prototype._write = function (data, encoding, cb) {
if (this.forceError) this.emit('error', new Error('Fake error'))
cb(this.forceError || null)
}
WritableStream.prototype.close = function (cb) {
this.emit('close')
if (cb) cb()
}
WritableStream.prototype.forceErrorOnWrite = function () {
this.forceError = true
return this
}
module.exports = WritableStream
|