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 authored and Danny McCormick committed 2019-08-13 14:26:14 -04:00
1 parent d9d4ce38c9
commit e8985d0159
4 files changed
+63 -2

No files matched your search

+7 -2
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
}