Compare commits

..

No commits in common. "1e384904b9e4955282536166cc92633d37afffbe" and "2a1b1e9d999028f76abcaf860572589c7a815122" have entirely different histories.

8 changed files with 20 additions and 63 deletions

View file

@ -1,14 +1,12 @@
const constants = { // just for envs without fs
S_IFMT: 61440,
S_IFDIR: 16384,
S_IFCHR: 8192,
S_IFBLK: 24576,
S_IFIFO: 4096,
S_IFLNK: 40960
}
try {
module.exports = require('fs').constants || constants
module.exports = require('fs').constants
} catch {
module.exports = constants
module.exports = { // just for envs without fs
S_IFMT: 61440,
S_IFDIR: 16384,
S_IFCHR: 8192,
S_IFBLK: 24576,
S_IFIFO: 4096,
S_IFLNK: 40960
}
}

View file

@ -72,9 +72,6 @@ class Source extends Readable {
}
_read (cb) {
if (this.header.size === 0) {
this.push(null)
}
if (this._parent._stream === this) {
this._parent._update()
}
@ -163,7 +160,9 @@ class Extract extends Writable {
this._applyLongHeaders()
if (this._header.size === 0 || this._header.type === 'directory') {
this.emit('entry', this._header, this._createStream(), this._unlockBound)
const stream = this._createStream()
stream.push(null)
this.emit('entry', this._header, stream, this._unlockBound)
return true
}

20
pack.js
View file

@ -11,7 +11,7 @@ const END_OF_TAR = b4a.alloc(1024)
class Sink extends Writable {
constructor (pack, header, callback) {
super({ mapWritable, eagerOpen: true })
super({ mapWritable })
this.written = 0
this.header = header
@ -49,10 +49,6 @@ class Sink extends Writable {
this._pack._encode(this.header)
}
if (this._isVoid) {
this._finish()
}
cb(null)
}
@ -71,10 +67,7 @@ class Sink extends Writable {
this._pack._drain = cb
}
_finish () {
if (this._finished) return
this._finished = true
_final (cb) {
if (this._isLinkname) {
this.header.linkname = this._linkname ? b4a.toString(this._linkname, 'utf-8') : ''
this._pack._encode(this.header)
@ -82,15 +75,13 @@ class Sink extends Writable {
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._finish()
this._pack._done(this)
this._finished = true
cb(null)
}
@ -151,6 +142,7 @@ class Pack extends Readable {
}
if (sink._isVoid) {
sink.end()
return sink
}

View file

@ -1,6 +1,6 @@
{
"name": "tar-stream",
"version": "3.1.4",
"version": "3.1.0",
"description": "tar-stream is a streaming tar parser and generator and nothing else. It operates purely using streams which means you can easily extract/parse tarballs without ever hitting the file system.",
"main": "index.js",
"files": [
@ -24,7 +24,6 @@
"homepage": "https://github.com/mafintosh/tar-stream",
"dependencies": {
"b4a": "^1.6.4",
"fast-fifo": "^1.2.0",
"streamx": "^2.15.0"
},
"devDependencies": {

View file

@ -251,7 +251,7 @@ test('pax', function (t) {
})
test('types', function (t) {
t.plan(5)
t.plan(3)
const extract = tar.extract()
let noEntries = false
@ -283,9 +283,6 @@ test('types', function (t) {
stream.on('data', function () {
t.ok(false)
})
stream.on('end', function () {
t.pass('ended')
})
extract.once('entry', onlink)
cb()
}
@ -309,9 +306,6 @@ test('types', function (t) {
stream.on('data', function () {
t.ok(false)
})
stream.on('end', function () {
t.pass('ended')
})
noEntries = true
cb()
}
@ -676,26 +670,6 @@ test('gnu-incremental', function (t) {
extract.end(fs.readFileSync(fixtures.GNU_INCREMENTAL_TAR))
})
test('i-dont-know', function (t) {
t.plan(1)
const extract = tar.extract()
extract.on('entry', function (header, stream, cb) {
console.debug(header.name)
stream.on('end', function () {
cb() // ready for next entry
})
stream.resume()
})
extract.on('finish', function () {
t.ok(true)
})
extract.end(fs.readFileSync(fixtures.I_DONT_KNOW))
})
test('v7 unsupported', function (t) { // correctly fails to parse v7 tarballs
t.plan(1)

View file

@ -1 +0,0 @@
i-dont-know.tgz filter=lfs diff=lfs merge=lfs -text

BIN
test/fixtures/i-dont-know.tgz (Stored with Git LFS) vendored

Binary file not shown.

View file

@ -25,4 +25,3 @@ exports.GNU_INCREMENTAL_TAR = path.join(__dirname, 'gnu-incremental.tar')
exports.UNKNOWN_FORMAT = path.join(__dirname, 'unknown-format.tar')
// Created using gnu tar: tar cf v7.tar --format v7 test.txt
exports.V7_TAR = path.join(__dirname, 'v7.tar')
exports.I_DONT_KNOW = path.join(__dirname, 'i-dont-know.tgz')