1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 09:49:28 +02:00
Oinktube/node_modules/end-stream/index.js
2022-07-15 11:08:01 -03:00

34 lines
652 B
JavaScript

var WriteStream = require("write-stream")
module.exports = EndStream
function EndStream(write, end) {
var counter = 0
, ended = false
end = end || noop
var stream = WriteStream(function (chunk) {
counter++
write(chunk, function (err) {
if (err) {
return stream.emit("error", err)
}
counter--
if (counter === 0 && ended) {
stream.emit("finish")
}
})
}, function () {
ended = true
if (counter === 0) {
this.emit("finish")
}
})
return stream
}
function noop() {}