Skip to content

Commit

Permalink
feat: support bz2 #3
Browse files Browse the repository at this point in the history
  • Loading branch information
tjx666 committed Mar 8, 2024
1 parent 5c75b5d commit d5f9d95
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 20 deletions.
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"type": "extensionHost",
"request": "launch",
"args": [
"--disable-extensions",
"--extensionDevelopmentPath=${workspaceFolder}",
"${workspaceFolder}/test-workspace"
],
Expand Down
20 changes: 17 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
{
"command": "vscode-archive.compressToVsix",
"title": "vsix"
},
{
"command": "vscode-archive.compressToBz2",
"title": "bz2"
}
],
"menus": {
Expand Down Expand Up @@ -104,12 +108,16 @@
{
"command": "vscode-archive.compressToVsix",
"when": "false"
},
{
"command": "vscode-archive.compressToBz2",
"when": "false"
}
],
"explorer/context": [
{
"command": "vscode-archive.decompress",
"when": "!explorerResourceIsFolder && resourceFilename =~ /.+\\.(zip|vsix|crx|asar|tgz|gzip|gz|tar|br)$/i",
"when": "!explorerResourceIsFolder && resourceFilename =~ /.+\\.(zip|vsix|crx|asar|tgz|gzip|gz|tar|br|bz2)$/i",
"group": "navigation@0"
},
{
Expand All @@ -129,12 +137,12 @@
},
{
"command": "vscode-archive.compressToGzip",
"group": "compress@3",
"group": "compress@2",
"when": "!explorerResourceIsFolder"
},
{
"command": "vscode-archive.compressToBr",
"group": "compress@6",
"group": "compress@3",
"when": "!explorerResourceIsFolder"
},
{
Expand All @@ -149,6 +157,11 @@
"command": "vscode-archive.compressToVsix",
"group": "compress@6",
"when": "explorerResourceIsFolder"
},
{
"command": "vscode-archive.compressToBz2",
"group": "compress@7",
"when": "!explorerResourceIsFolder"
}
]
},
Expand Down Expand Up @@ -183,6 +196,7 @@
"dependencies": {
"asar": "^3.2.0",
"compressing": "^1.10.0",
"execa": "^8.0.1",
"jszip": "^3.10.1",
"pretty-bytes": "^6.1.1"
},
Expand Down
20 changes: 3 additions & 17 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/compress/compressBz2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { execa } from 'execa';

export async function compressBz2(archivePath: string) {
await execa('bzip2', ['--keep', archivePath]);
}
3 changes: 3 additions & 0 deletions src/compress/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import asar from 'asar';
import compressing from 'compressing';

import { compressBr } from './compressBr';
import { compressBz2 } from './compressBz2';
import { analyzeCompress, getFileStats } from '../fsUtils';
import { logger } from '../logger';

Expand Down Expand Up @@ -47,6 +48,8 @@ export async function compress(sourcePath: string, archivePath: string) {
case 'asar':
await asar.createPackage(sourcePath, archivePath);
break;
case 'bz2':
await compressBz2(sourcePath);
}

logger.info(await analyzeCompress(sourcePath, archivePath));
Expand Down
5 changes: 5 additions & 0 deletions src/decompress/decompressBz2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { execa } from 'execa';

export async function decompressBz2(archivePath: string) {
await execa('bzip2', ['--keep', '--decompress', archivePath]);
}
4 changes: 4 additions & 0 deletions src/decompress/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import asar from 'asar';
import compressing from 'compressing';

import { decompressBr } from './decompressBr';
import { decompressBz2 } from './decompressBz2';
import { decompressCrx } from './decompressCrx';
import { analyzeDecompress } from '../fsUtils';
import { logger } from '../logger';
Expand Down Expand Up @@ -37,6 +38,9 @@ export async function decompress(archivePath: string, dest: string) {
case 'crx':
await decompressCrx(archivePath, dest);
break;
case 'bz2':
await decompressBz2(archivePath);
break;
}

logger.info(await analyzeDecompress(archivePath, dest));
Expand Down
3 changes: 3 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export function activate(context: vscode.ExtensionContext) {
vscode.commands.registerCommand('vscode-archive.compressToVsix', (uri) =>
handleCompress(uri, 'vsix'),
),
vscode.commands.registerCommand('vscode-archive.compressToBz2', (uri) =>
handleCompress(uri, 'bz2'),
),
);
}

Expand Down

0 comments on commit d5f9d95

Please sign in to comment.