Skip to content

Commit

Permalink
fix dbl stream.end
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Jun 20, 2023
1 parent cd05668 commit 9629b4a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const END_OF_TAR = b4a.alloc(1024)

class Sink extends Writable {
constructor (pack, header, callback) {
super({ mapWritable })
super({ mapWritable, eagerOpen: true })

this.written = 0
this.header = header
Expand Down Expand Up @@ -49,6 +49,10 @@ class Sink extends Writable {
this._pack._encode(this.header)
}

if (this._isVoid) {
this._finish()
}

cb(null)
}

Expand All @@ -67,21 +71,26 @@ class Sink extends Writable {
this._pack._drain = cb
}

_final (cb) {
_finish () {
if (this._finished) return
this._finished = true

if (this._isLinkname) {
this.header.linkname = this._linkname ? b4a.toString(this._linkname, 'utf-8') : ''
this._pack._encode(this.header)
}

overflow(this._pack, this.header.size)

this._pack._done(this)
}

_final (cb) {
if (this.written !== this.header.size) { // corrupting tar
return cb(new Error('Size mismatch'))
}

this._pack._done(this)
this._finished = true

this._finish()
cb(null)
}

Expand Down Expand Up @@ -142,7 +151,6 @@ class Pack extends Readable {
}

if (sink._isVoid) {
sink.end()
return sink
}

Expand Down

0 comments on commit 9629b4a

Please sign in to comment.