-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunpacker.ts
More file actions
37 lines (33 loc) · 1.07 KB
/
unpacker.ts
File metadata and controls
37 lines (33 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { decompress } from '../../deps.ts';
type UnpackParams = {
downloadDir: string;
archiveFileName: string;
};
export const darwinUnpack = async (params: UnpackParams) => {
console.log('darwinUnpack');
const { downloadDir, archiveFileName } = params;
const unpackedFileName = `${downloadDir}/stackql`;
const commandPath = 'pkgutil';
const commandArgs = ['--expand-full', archiveFileName, unpackedFileName];
const process = new Deno.Command(commandPath, {
args: commandArgs,
stdout: 'piped',
stderr: 'piped',
});
const { code, stdout, stderr } = await process.output();
if (code !== 0) {
const output = new TextDecoder().decode(stdout);
const errorOutput = new TextDecoder().decode(stderr);
console.error('Error executing pkgutil:', output, errorOutput);
throw new Error('Failed to unpack stackql');
}
};
export const unzip = async (params: UnpackParams) => {
console.log('unzip');
try {
await decompress(params.archiveFileName, params.downloadDir);
} catch (error) {
console.log('[unzip] error:', error);
throw new Error('Failed to unpack stackql');
}
};