diff --git a/test/extract.js b/test/extract.js index 91fe98b..5f9f6db 100644 --- a/test/extract.js +++ b/test/extract.js @@ -279,7 +279,7 @@ test('long-name', function(t) { mode: 0644, uid: 501, gid: 20, - size: 15, + size: 16, mtime: new Date(1387580181000), type: 'file', linkname: null, @@ -291,7 +291,7 @@ test('long-name', function(t) { stream.pipe(concat(function(data) { noEntries = true; - t.same(data.toString(), 'hello long name'); + t.same(data.toString(), 'hello long name\n'); callback(); })); }); @@ -301,5 +301,76 @@ test('long-name', function(t) { }); extract.end(fs.readFileSync(fixtures.LONG_NAME_TAR)); +}); +test('unicode-bsd', function(t) { // can unpack a bsdtar unicoded tarball + t.plan(3); + + var extract = tar.extract(); + var noEntries = false; + + extract.on('entry', function(header, stream, callback) { + t.deepEqual(header, { + name: 'høllø.txt', + mode: 0644, + uid: 501, + gid: 20, + size: 4, + mtime: new Date(1387588646000), + type: 'file', + linkname: null, + uname: 'maf', + gname: 'staff', + devmajor: 0, + devminor: 0 + }); + + stream.pipe(concat(function(data) { + noEntries = true; + t.same(data.toString(), 'hej\n'); + callback(); + })); + }); + + extract.on('finish', function() { + t.ok(noEntries); + }); + + extract.end(fs.readFileSync(fixtures.UNICODE_BSD_TAR)); +}); + +test('unicode', function(t) { // can unpack a bsdtar unicoded tarball + t.plan(3); + + var extract = tar.extract(); + var noEntries = false; + + extract.on('entry', function(header, stream, callback) { + t.deepEqual(header, { + name: 'høstål.txt', + mode: 0644, + uid: 501, + gid: 20, + size: 8, + 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(), 'høllø\n'); + callback(); + })); + }); + + extract.on('finish', function() { + t.ok(noEntries); + }); + + extract.end(fs.readFileSync(fixtures.UNICODE_TAR)); }); \ No newline at end of file diff --git a/test/fixtures/index.js b/test/fixtures/index.js index 7e29b74..4eeeb32 100644 --- a/test/fixtures/index.js +++ b/test/fixtures/index.js @@ -4,3 +4,5 @@ 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'); +exports.UNICODE_BSD_TAR = path.join(__dirname, 'unicode-bsd.tar'); +exports.UNICODE_TAR = path.join(__dirname, 'unicode.tar'); diff --git a/test/fixtures/long-name.tar b/test/fixtures/long-name.tar index ae8c658..3ba3b6f 100644 Binary files a/test/fixtures/long-name.tar and b/test/fixtures/long-name.tar differ diff --git a/test/fixtures/unicode-bsd.tar b/test/fixtures/unicode-bsd.tar new file mode 100644 index 0000000..2f74b5f Binary files /dev/null and b/test/fixtures/unicode-bsd.tar differ diff --git a/test/fixtures/unicode.tar b/test/fixtures/unicode.tar new file mode 100644 index 0000000..4948043 Binary files /dev/null and b/test/fixtures/unicode.tar differ diff --git a/test/pack.js b/test/pack.js index 3133437..69a7680 100644 --- a/test/pack.js +++ b/test/pack.js @@ -110,7 +110,7 @@ test('long-name', function(t) { gname:'staff', uid:501, gid:20 - }, 'hello long name'); + }, 'hello long name\n'); pack.finalize(); @@ -118,4 +118,27 @@ test('long-name', function(t) { t.equal(data.length & 511, 0); t.deepEqual(data, fs.readFileSync(fixtures.LONG_NAME_TAR)); })); +}); + +test('unicode', function(t) { + t.plan(2); + var pack = tar.pack(); + + pack.entry({ + name:'høstål.txt', + mtime:new Date(1387580181000), + type:'file', + mode:0644, + uname:'maf', + gname:'staff', + uid:501, + gid:20 + }, 'høllø\n'); + + pack.finalize(); + + pack.pipe(concat(function(data) { + t.equal(data.length & 511, 0); + t.deepEqual(data, fs.readFileSync(fixtures.UNICODE_TAR)); + })); }); \ No newline at end of file