Skip to content

Commit

Permalink
Fix filenames in USTAR format with long names
Browse files Browse the repository at this point in the history
  • Loading branch information
korya committed Mar 5, 2018
1 parent b279526 commit c035bb8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
Binary file added spec/data/test-ustar-with-prefix.tar
Binary file not shown.
Binary file added spec/data/test-ustar.tar
Binary file not shown.
34 changes: 34 additions & 0 deletions spec/untar-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ define(["lodash", "untar", "../build/dist/untar"], function(_, untarDev, untarDi
return loadFile("base/spec/data/test-pax.tar");
}

function loadTestFile(filename) {
return loadFile("base/spec/data/" + filename);
}

var fileNames = [
"1.txt",
"2.txt",
Expand Down Expand Up @@ -102,6 +106,36 @@ define(["lodash", "untar", "../build/dist/untar"], function(_, untarDev, untarDi
);
}, 10000);

it("should support USTAR format", function(done) {
loadTestFile("test-ustar.tar").then(
function(buffer) {
return untar(buffer)
.then(function(files) {
expect(files.length).toBe(1);
expect(files[0].name).toBe("foo");
})
.then(done, done.fail);
},
done.fail
);
}, 10000);

it("should support USTAR format with long names", function(done) {
loadTestFile("test-ustar-with-prefix.tar").then(
function(buffer) {
return untar(buffer)
.then(function(files) {
expect(files.length).toBe(1);
expect(files[0].name).toBe(
"directory-000/directory-001/directory-002/directory-003/directory-004/directory-005/directory-006/foo.txt"
);
})
.then(done, done.fail);
},
done.fail
);
}, 10000);

describe("UntarFile", function() {

describe("readAsString()", function() {
Expand Down
2 changes: 1 addition & 1 deletion src/untar-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ UntarFileStream.prototype = {
file.namePrefix = stream.readString(155);

if (file.namePrefix.length > 0) {
file.name = file.namePrefix + file.name;
file.name = file.namePrefix + "/" + file.name;
}
}

Expand Down

0 comments on commit c035bb8

Please sign in to comment.