diff --git a/test/extract.js b/test/extract.js index 32dc6ad..91fe98b 100644 --- a/test/extract.js +++ b/test/extract.js @@ -265,4 +265,41 @@ test('types', function(t) { }); extract.end(fs.readFileSync(fixtures.TYPES_TAR)); +}); + +test('long-name', function(t) { + t.plan(3); + + var extract = tar.extract(); + var noEntries = false; + + extract.on('entry', function(header, stream, callback) { + t.deepEqual(header, { + name: 'my/file/is/longer/than/100/characters/and/should/use/the/prefix/header/foobarbaz/foobarbaz/foobarbaz/foobarbaz/foobarbaz/foobarbaz/filename.txt', + mode: 0644, + uid: 501, + gid: 20, + size: 15, + mtime: new Date(1387580181000), + type: 'file', + linkname: null, + uname: 'maf', + gname: 'staff', + devmajor: 0, + devminor: 0 + }); + + stream.pipe(concat(function(data) { + noEntries = true; + t.same(data.toString(), 'hello long name'); + callback(); + })); + }); + + extract.on('finish', function() { + t.ok(noEntries); + }); + + extract.end(fs.readFileSync(fixtures.LONG_NAME_TAR)); + }); \ No newline at end of file diff --git a/test/fixtures/index.js b/test/fixtures/index.js index 9658a5a..7e29b74 100644 --- a/test/fixtures/index.js +++ b/test/fixtures/index.js @@ -3,3 +3,4 @@ var path = require('path'); exports.ONE_FILE_TAR = path.join(__dirname, 'one-file.tar'); exports.MULTI_FILE_TAR = path.join(__dirname, 'multi-file.tar'); exports.TYPES_TAR = path.join(__dirname, 'types.tar'); +exports.LONG_NAME_TAR = path.join(__dirname, 'long-name.tar'); diff --git a/test/fixtures/long-name.tar b/test/fixtures/long-name.tar new file mode 100644 index 0000000..ae8c658 Binary files /dev/null and b/test/fixtures/long-name.tar differ diff --git a/test/pack.js b/test/pack.js index 6346a87..3133437 100644 --- a/test/pack.js +++ b/test/pack.js @@ -95,4 +95,27 @@ test('types', function(t) { t.deepEqual(data, fs.readFileSync(fixtures.TYPES_TAR)); })); +}); + +test('long-name', function(t) { + t.plan(2); + var pack = tar.pack(); + + pack.entry({ + name:'my/file/is/longer/than/100/characters/and/should/use/the/prefix/header/foobarbaz/foobarbaz/foobarbaz/foobarbaz/foobarbaz/foobarbaz/filename.txt', + mtime:new Date(1387580181000), + type:'file', + mode:0644, + uname:'maf', + gname:'staff', + uid:501, + gid:20 + }, 'hello long name'); + + pack.finalize(); + + pack.pipe(concat(function(data) { + t.equal(data.length & 511, 0); + t.deepEqual(data, fs.readFileSync(fixtures.LONG_NAME_TAR)); + })); }); \ No newline at end of file