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
5 changes: 4 additions & 1 deletion .gitignore
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ node_modules
dist
.vscode
**/*.tar.gz
!test.tar.gz
**/*.zip
**/*.7z
!test.tar.gz
!test.zip
!test.7z
coverage/
3 changes: 2 additions & 1 deletion README.md
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ await extractTarball('foo.tar.gz');

## Roadmap

* Support more types of compression (`zip`, `bz2`, `7z`, etc.)
* Support more types of compression (~~`zip`~~, `bz2`, ~~`7z`~~, etc.)
* Extraction goes along with those
* **NOTE:** There is no good package to work with 7zip files, so this is being put on the backlog.
* Support extracting to a specific directory
* Support extracting more than 1 file at a time

Expand Down
52 changes: 52 additions & 0 deletions __tests__/compress.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { readdir, remove, pathExists } from "fs-extra";
import { dirname } from "path";
import { compressFiles } from "../src/compress";
import { ArchiveType } from "../src/utils";

describe('compress', () => {
beforeEach(() => {
process.chdir(dirname(__filename));
});

afterEach(async () => {
const files = await readdir('.');
files.filter(x => {
return !x.endsWith('spec.ts') &&
!x.includes('test.tar.gz') &&
!x.includes('test.zip') &&
!x.includes('test.7z');
}).forEach(async z => {
await remove(z);
});
});

it('should compress a list of files to .tar.gz', async () => {
const out = 'app.spec.ts.tar.gz';
await compressFiles(ArchiveType["tar.gz"], out, 'index.spec.ts');
const ex = await pathExists(out);
expect(ex).toBeTruthy();
await remove(out);
});

it('should fail if file does not exist', async () => {
try {
await compressFiles(ArchiveType["tar.gz"], 'out.tar.gz', 'foo.bar');
} catch (err) {
expect(err).toBeDefined();
}
});

it('should compress a list of files to .zip', async () => {
const out = 'index.spec.ts.zip';
await compressFiles(ArchiveType.zip, out, 'index.spec.ts');
const ex = await pathExists(out);
expect(ex).toBeTruthy();
});

it('should compress a list of files to .7z', async () => {
const out = 'index.spec.ts.7z';
await compressFiles(ArchiveType["7z"], out, 'index.spec.ts');
const ex = await pathExists(out);
expect(ex).toBeTruthy();
});
});
40 changes: 40 additions & 0 deletions __tests__/extract.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { readdir, remove, pathExists } from "fs-extra";
import { dirname } from "path";
import { extractArchive } from "../src/extract";
import { ArchiveType } from "../src/utils";

describe('extract', () => {
beforeEach(() => {
process.chdir(dirname(__filename));
});

afterEach(async () => {
const files = await readdir('.');
files.filter(x => {
return !x.endsWith('spec.ts') &&
!x.includes('test.tar.gz') &&
!x.includes('test.zip') &&
!x.includes('test.7z');
}).forEach(async z => {
await remove(z);
});
});

it('should extract a single tarball', async () => {
await extractArchive(ArchiveType["tar.gz"], 'test.tar.gz');
const ex = await pathExists('LICENSE');
expect(ex).toBeTruthy();
});

it('should extract a single .zip', async () => {
await extractArchive(ArchiveType.zip, 'test.zip');
const ex = await pathExists('LICENSE');
expect(ex).toBeTruthy();
});

it('should extract a single .7z', async () => {
await extractArchive(ArchiveType["7z"], 'test.7z');
const ex = await pathExists('LICENSE');
expect(ex).toBeTruthy();
});
});
Loading