swc/bundler/tests/.cache/deno/bb7315de6738611501e96f323ff9519fb4702ff5.ts
강동윤 f8aa0509ce
fix(bundler): Fix stack overflow (#2080)
swc_bundler:
 - Prevent infinite recursions. (#1963)
2021-08-15 02:37:31 +00:00

34 lines
1.1 KiB
TypeScript

// Loaded from https://deno.land/x/compress@v0.3.8/tgz/mod.ts
import * as tar from "../tar/mod.ts";
import { gunzipFile, gzipFile } from "../gzip/gzip_file.ts";
import type { compressInterface } from "../interface.ts";
import { path } from "../deps.ts";
export async function uncompress(src: string, dest: string): Promise<void> {
const filename = path.basename(src);
const extname = path.extname(filename);
const tarFilename = extname === ".tgz"
? filename.slice(0, -3) + "tar"
: (extname === ".gz" ? filename.slice(0, -3) : filename);
const tmpDir = await Deno.makeTempDir();
const tmpPath = path.join(tmpDir, tarFilename);
await gunzipFile(src, tmpPath);
await tar.uncompress(tmpPath, dest);
await Deno.remove(tmpDir, { recursive: true });
}
export async function compress(
src: string,
dest: string,
options?: compressInterface,
): Promise<void> {
const filename = path.basename(src);
const tmpDir = await Deno.makeTempDir();
const tmpPath = path.join(tmpDir, filename);
await tar.compress(src, tmpPath, options);
await gzipFile(tmpPath, dest);
await Deno.remove(tmpDir, { recursive: true });
}