Skip to content

Commit 96a74d9

Browse files
committed
Fix issue #42: Add missing slash for long filenames in ustar format
1 parent 5a00a3f commit 96a74d9

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

archive/untar.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ let allLocalFiles = null;
2727
let logToConsole = false;
2828

2929
// Progress variables.
30-
let currentFilename = "";
30+
let currentFilename = '';
3131
let currentFileNumber = 0;
3232
let currentBytesUnarchivedInFile = 0;
3333
let currentBytesUnarchived = 0;
@@ -80,16 +80,23 @@ class TarLocalFile {
8080
this.linkname = readCleanString(bstream, 100);
8181
this.maybeMagic = readCleanString(bstream, 6);
8282

83-
if (this.maybeMagic == "ustar") {
83+
if (this.maybeMagic == 'ustar') {
8484
this.version = readCleanString(bstream, 2);
8585
this.uname = readCleanString(bstream, 32);
8686
this.gname = readCleanString(bstream, 32);
8787
this.devmajor = readCleanString(bstream, 8);
8888
this.devminor = readCleanString(bstream, 8);
8989
this.prefix = readCleanString(bstream, 155);
9090

91+
// From https://linux.die.net/man/1/ustar:
92+
// "The name field (100 chars) an inserted slash ('/') and the prefix field (155 chars)
93+
// produce the pathname of the file. When recreating the original filename, name and prefix
94+
// are concatenated, using a slash character in the middle. If a pathname does not fit in the
95+
// space provided or may not be split at a slash character so that the parts will fit into
96+
// 100 + 155 chars, the file may not be archived. Linknames longer than 100 chars may not be
97+
// archived too."
9198
if (this.prefix.length) {
92-
this.name = this.prefix + this.name;
99+
this.name = `${this.prefix}/${this.name}`;
93100
}
94101
bstream.readBytes(12); // 512 - 500
95102
} else {
@@ -103,13 +110,13 @@ class TarLocalFile {
103110
/** @type {Uint8Array} */
104111
this.fileData = null;
105112

106-
info("Untarring file '" + this.filename + "'");
107-
info(" size = " + this.size);
108-
info(" typeflag = " + this.typeflag);
113+
info(`Untarring file '${this.filename}'`);
114+
info(` size = ${this.size}`);
115+
info(` typeflag = ${this.typeflag}`);
109116

110117
// A regular file.
111118
if (this.typeflag == 0) {
112-
info(" This is a regular file.");
119+
info(' This is a regular file.');
113120
const sizeInBytes = parseInt(this.size);
114121
this.fileData = new Uint8Array(bstream.readBytes(sizeInBytes));
115122
bytesRead += sizeInBytes;
@@ -123,7 +130,7 @@ class TarLocalFile {
123130
bstream.readBytes(remaining);
124131
}
125132
} else if (this.typeflag == 5) {
126-
info(" This is a directory.")
133+
info(' This is a directory.')
127134
}
128135
}
129136
}
@@ -172,7 +179,7 @@ onmessage = function (event) {
172179
}
173180

174181
if (unarchiveState === UnarchiveState.NOT_STARTED) {
175-
currentFilename = "";
182+
currentFilename = '';
176183
currentFileNumber = 0;
177184
currentBytesUnarchivedInFile = 0;
178185
currentBytesUnarchived = 0;

0 commit comments

Comments
 (0)