Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@
throw error;
}

const strip = opts.strip ? Number(opts.strip) : 0;
// Strip is handled here in makeUncompressFn, so remove it from opts to avoid passing to UncompressStream
delete opts.strip;

return new Promise((resolve, reject) => {
fs.mkdir(destDir, { recursive: true }, err => {

Check warning on line 96 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 18)

Use 'fs.promises.mkdir()' instead

Check warning on line 96 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 18)

Use 'fs.promises.mkdir()' instead

Check warning on line 96 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 20)

Use 'fs.promises.mkdir()' instead

Check warning on line 96 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 20)

Use 'fs.promises.mkdir()' instead

Check warning on line 96 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 24)

Use 'fs.promises.mkdir()' instead

Check warning on line 96 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 24)

Use 'fs.promises.mkdir()' instead

Check warning on line 96 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 22)

Use 'fs.promises.mkdir()' instead

Check warning on line 96 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 22)

Use 'fs.promises.mkdir()' instead

Check warning on line 96 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 18)

Use 'fs.promises.mkdir()' instead

Check warning on line 96 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 18)

Use 'fs.promises.mkdir()' instead

Check warning on line 96 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 22)

Use 'fs.promises.mkdir()' instead

Check warning on line 96 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 22)

Use 'fs.promises.mkdir()' instead

Check warning on line 96 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 20)

Use 'fs.promises.mkdir()' instead

Check warning on line 96 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 20)

Use 'fs.promises.mkdir()' instead

Check warning on line 96 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 20)

Use 'fs.promises.mkdir()' instead

Check warning on line 96 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 20)

Use 'fs.promises.mkdir()' instead

Check warning on line 96 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 22)

Use 'fs.promises.mkdir()' instead

Check warning on line 96 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 22)

Use 'fs.promises.mkdir()' instead

Check warning on line 96 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 24)

Use 'fs.promises.mkdir()' instead

Check warning on line 96 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 24)

Use 'fs.promises.mkdir()' instead

Check warning on line 96 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 18)

Use 'fs.promises.mkdir()' instead

Check warning on line 96 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 18)

Use 'fs.promises.mkdir()' instead

Check warning on line 96 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 24)

Use 'fs.promises.mkdir()' instead

Check warning on line 96 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 24)

Use 'fs.promises.mkdir()' instead
if (err) return reject(err);

let entryCount = 0;
Expand All @@ -108,11 +112,10 @@
.on('error', reject)
.on('entry', (header, stream, next) => {
stream.on('end', next);
const destFilePath = path.join(destDir, header.name);

const destFilePath = path.join(destDir, stripFileName(strip, header.name, header.type));
if (header.type === 'file') {
const dir = path.dirname(destFilePath);
fs.mkdir(dir, { recursive: true }, err => {

Check warning on line 118 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 18)

Use 'fs.promises.mkdir()' instead

Check warning on line 118 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 18)

Use 'fs.promises.mkdir()' instead

Check warning on line 118 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 20)

Use 'fs.promises.mkdir()' instead

Check warning on line 118 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 20)

Use 'fs.promises.mkdir()' instead

Check warning on line 118 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 24)

Use 'fs.promises.mkdir()' instead

Check warning on line 118 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 24)

Use 'fs.promises.mkdir()' instead

Check warning on line 118 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 22)

Use 'fs.promises.mkdir()' instead

Check warning on line 118 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 22)

Use 'fs.promises.mkdir()' instead

Check warning on line 118 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 18)

Use 'fs.promises.mkdir()' instead

Check warning on line 118 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 18)

Use 'fs.promises.mkdir()' instead

Check warning on line 118 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 22)

Use 'fs.promises.mkdir()' instead

Check warning on line 118 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 22)

Use 'fs.promises.mkdir()' instead

Check warning on line 118 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 20)

Use 'fs.promises.mkdir()' instead

Check warning on line 118 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 20)

Use 'fs.promises.mkdir()' instead

Check warning on line 118 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 20)

Use 'fs.promises.mkdir()' instead

Check warning on line 118 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 20)

Use 'fs.promises.mkdir()' instead

Check warning on line 118 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 22)

Use 'fs.promises.mkdir()' instead

Check warning on line 118 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 22)

Use 'fs.promises.mkdir()' instead

Check warning on line 118 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 24)

Use 'fs.promises.mkdir()' instead

Check warning on line 118 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 24)

Use 'fs.promises.mkdir()' instead

Check warning on line 118 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 18)

Use 'fs.promises.mkdir()' instead

Check warning on line 118 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 18)

Use 'fs.promises.mkdir()' instead

Check warning on line 118 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 24)

Use 'fs.promises.mkdir()' instead

Check warning on line 118 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 24)

Use 'fs.promises.mkdir()' instead
if (err) return reject(err);

entryCount++;
Expand All @@ -127,18 +130,18 @@
const target = path.resolve(dir, header.linkname);
entryCount++;

fs.mkdir(dir, { recursive: true }, err => {

Check warning on line 133 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 18)

Use 'fs.promises.mkdir()' instead

Check warning on line 133 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 18)

Use 'fs.promises.mkdir()' instead

Check warning on line 133 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 20)

Use 'fs.promises.mkdir()' instead

Check warning on line 133 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 20)

Use 'fs.promises.mkdir()' instead

Check warning on line 133 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 24)

Use 'fs.promises.mkdir()' instead

Check warning on line 133 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 24)

Use 'fs.promises.mkdir()' instead

Check warning on line 133 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 22)

Use 'fs.promises.mkdir()' instead

Check warning on line 133 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 22)

Use 'fs.promises.mkdir()' instead

Check warning on line 133 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 18)

Use 'fs.promises.mkdir()' instead

Check warning on line 133 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 18)

Use 'fs.promises.mkdir()' instead

Check warning on line 133 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 22)

Use 'fs.promises.mkdir()' instead

Check warning on line 133 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 22)

Use 'fs.promises.mkdir()' instead

Check warning on line 133 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 20)

Use 'fs.promises.mkdir()' instead

Check warning on line 133 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 20)

Use 'fs.promises.mkdir()' instead

Check warning on line 133 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 20)

Use 'fs.promises.mkdir()' instead

Check warning on line 133 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 20)

Use 'fs.promises.mkdir()' instead

Check warning on line 133 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 22)

Use 'fs.promises.mkdir()' instead

Check warning on line 133 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 22)

Use 'fs.promises.mkdir()' instead

Check warning on line 133 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 24)

Use 'fs.promises.mkdir()' instead

Check warning on line 133 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 24)

Use 'fs.promises.mkdir()' instead

Check warning on line 133 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 18)

Use 'fs.promises.mkdir()' instead

Check warning on line 133 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 18)

Use 'fs.promises.mkdir()' instead

Check warning on line 133 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 24)

Use 'fs.promises.mkdir()' instead

Check warning on line 133 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 24)

Use 'fs.promises.mkdir()' instead
if (err) return reject(err);

const relativeTarget = path.relative(dir, target);
fs.symlink(relativeTarget, destFilePath, err => {

Check warning on line 137 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 18)

Use 'fs.promises.symlink()' instead

Check warning on line 137 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 18)

Use 'fs.promises.symlink()' instead

Check warning on line 137 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 20)

Use 'fs.promises.symlink()' instead

Check warning on line 137 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 20)

Use 'fs.promises.symlink()' instead

Check warning on line 137 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 24)

Use 'fs.promises.symlink()' instead

Check warning on line 137 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 24)

Use 'fs.promises.symlink()' instead

Check warning on line 137 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 22)

Use 'fs.promises.symlink()' instead

Check warning on line 137 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 22)

Use 'fs.promises.symlink()' instead

Check warning on line 137 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 18)

Use 'fs.promises.symlink()' instead

Check warning on line 137 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 18)

Use 'fs.promises.symlink()' instead

Check warning on line 137 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 22)

Use 'fs.promises.symlink()' instead

Check warning on line 137 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 22)

Use 'fs.promises.symlink()' instead

Check warning on line 137 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 20)

Use 'fs.promises.symlink()' instead

Check warning on line 137 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 20)

Use 'fs.promises.symlink()' instead

Check warning on line 137 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 20)

Use 'fs.promises.symlink()' instead

Check warning on line 137 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 20)

Use 'fs.promises.symlink()' instead

Check warning on line 137 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 22)

Use 'fs.promises.symlink()' instead

Check warning on line 137 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 22)

Use 'fs.promises.symlink()' instead

Check warning on line 137 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 24)

Use 'fs.promises.symlink()' instead

Check warning on line 137 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 24)

Use 'fs.promises.symlink()' instead

Check warning on line 137 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 18)

Use 'fs.promises.symlink()' instead

Check warning on line 137 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 18)

Use 'fs.promises.symlink()' instead

Check warning on line 137 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 24)

Use 'fs.promises.symlink()' instead

Check warning on line 137 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 24)

Use 'fs.promises.symlink()' instead
if (err) return reject(err);
successCount++;
stream.resume();
});
});
} else { // directory
fs.mkdir(destFilePath, { recursive: true }, err => {

Check warning on line 144 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 18)

Use 'fs.promises.mkdir()' instead

Check warning on line 144 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 18)

Use 'fs.promises.mkdir()' instead

Check warning on line 144 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 20)

Use 'fs.promises.mkdir()' instead

Check warning on line 144 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 20)

Use 'fs.promises.mkdir()' instead

Check warning on line 144 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 24)

Use 'fs.promises.mkdir()' instead

Check warning on line 144 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 24)

Use 'fs.promises.mkdir()' instead

Check warning on line 144 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 22)

Use 'fs.promises.mkdir()' instead

Check warning on line 144 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 22)

Use 'fs.promises.mkdir()' instead

Check warning on line 144 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 18)

Use 'fs.promises.mkdir()' instead

Check warning on line 144 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 18)

Use 'fs.promises.mkdir()' instead

Check warning on line 144 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 22)

Use 'fs.promises.mkdir()' instead

Check warning on line 144 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 22)

Use 'fs.promises.mkdir()' instead

Check warning on line 144 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 20)

Use 'fs.promises.mkdir()' instead

Check warning on line 144 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (macos-latest, 20)

Use 'fs.promises.mkdir()' instead

Check warning on line 144 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 20)

Use 'fs.promises.mkdir()' instead

Check warning on line 144 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 20)

Use 'fs.promises.mkdir()' instead

Check warning on line 144 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 22)

Use 'fs.promises.mkdir()' instead

Check warning on line 144 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 22)

Use 'fs.promises.mkdir()' instead

Check warning on line 144 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 24)

Use 'fs.promises.mkdir()' instead

Check warning on line 144 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 24)

Use 'fs.promises.mkdir()' instead

Check warning on line 144 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 18)

Use 'fs.promises.mkdir()' instead

Check warning on line 144 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (windows-latest, 18)

Use 'fs.promises.mkdir()' instead

Check warning on line 144 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 24)

Use 'fs.promises.mkdir()' instead

Check warning on line 144 in lib/utils.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 24)

Use 'fs.promises.mkdir()' instead
if (err) return reject(err);
stream.resume();
});
Expand Down
23 changes: 23 additions & 0 deletions test/tar/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,5 +226,28 @@ describe('test/tar/index.test.js', () => {
assert(originStat.mode);
assert(destStat.mode);
});

it('tar.uncompress(sourceFile, destDir) with strip 1', async () => {
const sourceFile = path.join(__dirname, '..', 'fixtures', 'xxx.tar');
const destDir = path.join(os.tmpdir(), uuid.v4());
const originalDir = path.join(__dirname, '..', 'fixtures', 'xxx');
await compressing.tar.uncompress(sourceFile, destDir, { strip: 1 });
const res = dircompare.compareSync(originalDir, destDir);
assert.equal(res.distinct, 0, 'distinct files count mismatch');
assert.equal(res.equal, 5, 'equal files count mismatch');
assert(res.totalFiles === 4);
assert(res.totalDirs === 1);
});

it('tar.uncompress(sourceFile, destDir) with strip 2', async () => {
const sourceFile = path.join(__dirname, '..', 'fixtures', 'xxx.tar');
const destDir = path.join(os.tmpdir(), uuid.v4());
await compressing.tar.uncompress(sourceFile, destDir, { strip: 2 });
const res = dircompare.compareSync(path.join(__dirname, '..', 'fixtures', 'xxx-strip2'), destDir);
assert.equal(res.distinct, 0);
assert.equal(res.equal, 4);
assert(res.totalFiles === 4);
assert(res.totalDirs === 0);
});
});
});
23 changes: 23 additions & 0 deletions test/tgz/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,28 @@ describe('test/tgz/index.test.js', () => {
assert(res.totalFiles === 4);
assert(res.totalDirs === 1);
});

it('tgz.uncompress(sourceFile, destDir) with strip 1', async () => {
const sourceFile = path.join(__dirname, '..', 'fixtures', 'xxx.tgz');
const destDir = path.join(os.tmpdir(), uuid.v4());
const originalDir = path.join(__dirname, '..', 'fixtures', 'xxx');
await compressing.tgz.uncompress(sourceFile, destDir, { strip: 1 });
const res = dircompare.compareSync(originalDir, destDir);
assert.equal(res.distinct, 0, 'distinct files count mismatch');
assert.equal(res.equal, 5, 'equal files count mismatch');
assert(res.totalFiles === 4);
assert(res.totalDirs === 1);
});

it('tgz.uncompress(sourceFile, destDir) with strip 2', async () => {
const sourceFile = path.join(__dirname, '..', 'fixtures', 'xxx.tgz');
const destDir = path.join(os.tmpdir(), uuid.v4());
await compressing.tgz.uncompress(sourceFile, destDir, { strip: 2 });
const res = dircompare.compareSync(path.join(__dirname, '..', 'fixtures', 'xxx-strip2'), destDir);
assert.equal(res.distinct, 0);
assert.equal(res.equal, 4);
assert(res.totalFiles === 4);
assert(res.totalDirs === 0);
});
});
});
2 changes: 1 addition & 1 deletion test/zip/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ describe('test/zip/index.test.js', () => {
fs.mkdirSync(destDir, { recursive: true });
await compressing.zip.uncompress(destFile, destDir);
const stat = fs.statSync(path.join(destDir, 'bin'));
assert(stat.mode === originStat.mode);
assert.equal(stat.mode, originStat.mode, 'file mode should be same after uncompress');
// console.log(destDir);
});
});
Loading