Add more supports for tar extensions (#48)

* added test for extracting .tar.gz

* added ability to extract .tar.xz

* add flags to extract tar

* make use of tempPath

* check file contents and make different content for tar file
This commit is contained in:
Alif Rachmawadi
2019-08-14 01:26:14 +07:00
committed by Danny McCormick
parent 35cd59e8d5
commit 2c3e55b8c9
4 changed files with 63 additions and 2 deletions

View File

@@ -187,16 +187,21 @@ export async function extract7z(
*
* @param file path to the tar
* @param dest destination directory. Optional.
* @param flags flags for the tar. Optional.
* @returns path to the destination directory
*/
export async function extractTar(file: string, dest?: string): Promise<string> {
export async function extractTar(
file: string,
dest?: string,
flags: string = 'xz'
): Promise<string> {
if (!file) {
throw new Error("parameter 'file' is required")
}
dest = dest || (await _createExtractFolder(dest))
const tarPath: string = await io.which('tar', true)
await exec(`"${tarPath}"`, ['xzC', dest, '-f', file])
await exec(`"${tarPath}"`, [flags, '-C', dest, '-f', file])
return dest
}