Skip to content

Commit

Permalink
fix: dont use internal _events attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak committed Feb 28, 2024
1 parent dae35a9 commit 9f8eec6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions deps/dicer/lib/Dicer.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Dicer.prototype._write = function (data, encoding, cb) {
if (this._headerFirst && this._isPreamble) {
if (!this._part) {
this._part = new PartStream(this._partOpts)
if (this._events.preamble) { this.emit('preamble', this._part) } else { this._ignore() }
if (this.listenerCount('preamble') !== 0) { this.emit('preamble', this._part) } else { this._ignore() }
}
const r = this._hparser.push(data)
if (!this._inHeader && r !== undefined && r < data.length) { data = data.slice(r) } else { return cb() }
Expand Down Expand Up @@ -135,7 +135,7 @@ Dicer.prototype._oninfo = function (isMatch, data, start, end) {
}
}
if (this._dashes === 2) {
if ((start + i) < end && this._events.trailer) { this.emit('trailer', data.slice(start + i, end)) }
if ((start + i) < end && this.listenerCount('trailer') !== 0) { this.emit('trailer', data.slice(start + i, end)) }
this.reset()
this._finished = true
// no more parts will be added
Expand All @@ -153,7 +153,13 @@ Dicer.prototype._oninfo = function (isMatch, data, start, end) {
this._part._read = function (n) {
self._unpause()
}
if (this._isPreamble && this._events.preamble) { this.emit('preamble', this._part) } else if (this._isPreamble !== true && this._events.part) { this.emit('part', this._part) } else { this._ignore() }
if (this._isPreamble && this.listenerCount('preamble') !== 0) {
this.emit('preamble', this._part)
} else if (this._isPreamble !== true && this.listenerCount('part') !== 0) {
this.emit('part', this._part)
} else {
this._ignore()
}
if (!this._isPreamble) { this._inHeader = true }
}
if (data && start < end && !this._ignoreData) {
Expand Down
2 changes: 1 addition & 1 deletion lib/types/multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function Multipart (boy, cfg) {

++nfiles

if (!boy._events.file) {
if (boy.listenerCount('file') === 0) {
self.parser._ignore()
return
}
Expand Down

0 comments on commit 9f8eec6

Please sign in to comment.