tar-stream
Advanced tools
Comparing version 0.2.5 to 0.3.0
@@ -78,3 +78,8 @@ var stream = require('stream'); | ||
var onheader = function() { | ||
var header = self._header = headers.decode(b.slice(0, 512)); | ||
var header | ||
try { | ||
header = self._header = headers.decode(b.slice(0, 512)); | ||
} catch (err) { | ||
self.emit('error', err) | ||
} | ||
b.consume(512); | ||
@@ -176,2 +181,2 @@ | ||
module.exports = Extract; | ||
module.exports = Extract; |
@@ -179,4 +179,2 @@ var ZEROS = '0000000000000000000'; | ||
if (!type) return null; | ||
var name = decodeStr(buf, 0, 100); | ||
@@ -196,18 +194,27 @@ var mode = decodeOct(buf, 100); | ||
if (cksum(buf) !== decodeOct(buf, 148)) return null; | ||
var c = cksum(buf) | ||
return { | ||
name: name, | ||
mode: mode, | ||
uid: uid, | ||
gid: gid, | ||
size: size, | ||
mtime: new Date(1000 * mtime), | ||
type: toType(typeflag), | ||
linkname: linkname, | ||
uname: uname, | ||
gname: gname, | ||
devmajor: devmajor, | ||
devminor: devminor | ||
}; | ||
}; | ||
//checksum is still initial value if header was null. | ||
if (c === 8*32) return null; | ||
//valid checksum | ||
if (c === decodeOct(buf, 148)) | ||
return { | ||
name: name, | ||
mode: mode, | ||
uid: uid, | ||
gid: gid, | ||
size: size, | ||
mtime: new Date(1000 * mtime), | ||
type: toType(typeflag), | ||
linkname: linkname, | ||
uname: uname, | ||
gname: gname, | ||
devmajor: devmajor, | ||
devminor: devminor | ||
}; | ||
//invalid checksum | ||
throw new Error('invalid header'); | ||
}; | ||
{ | ||
"name": "tar-stream", | ||
"version": "0.2.5", | ||
"version": "0.3.0", | ||
"description": "tar-stream is a streaming tar parser and generator and nothing else. It is streams2 and operates purely using streams which means you can easily extract/parse tarballs without ever hitting the file system.", | ||
@@ -20,3 +20,3 @@ "repository": "git://github.com:mafintosh/tar-stream.git", | ||
"scripts": { | ||
"test": "tap test/*.js" | ||
"test": "tap test/*.js" | ||
}, | ||
@@ -23,0 +23,0 @@ "keywords": [ |
@@ -407,2 +407,15 @@ var test = require('tap').test; | ||
extract.end(fs.readFileSync(fixtures.NAME_IS_100_TAR)); | ||
}); | ||
test('invalid-file', function(t) { | ||
t.plan(1); | ||
var extract = tar.extract(); | ||
extract.on('error', function(err) { | ||
t.ok(!!err); | ||
extract.destroy(); | ||
}); | ||
extract.end(fs.readFileSync(fixtures.INVALID_TGZ)); | ||
}); |
@@ -9,2 +9,3 @@ var path = require('path'); | ||
exports.UNICODE_TAR = path.join(__dirname, 'unicode.tar'); | ||
exports.NAME_IS_100_TAR = path.join(__dirname, 'name-is-100.tar'); | ||
exports.NAME_IS_100_TAR = path.join(__dirname, 'name-is-100.tar'); | ||
exports.INVALID_TGZ = path.join(__dirname, 'invalid.tgz'); |
120974
19
943