Skip to content

Commit a54b371

Browse files
committed
chore: use modern tar
1 parent ef4d786 commit a54b371

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

npm-install/postinstall.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { createWriteStream } from "fs";
2-
import * as fs from "fs/promises";
3-
import { pipeline } from "stream/promises";
4-
import tar from "tar";
5-
import { execSync } from "child_process";
1+
import { createReadStream, createWriteStream } from "node:fs";
2+
import * as fs from "node:fs/promises";
3+
import { pipeline } from "node:stream/promises";
4+
import { execSync } from "node:child_process";
5+
import { createGunzip } from "node:zlib";
6+
import { unpackTar } from "modern-tar/fs";
67

78
import { ARCH_MAPPING, CONFIG, PLATFORM_MAPPING } from "./config.js";
89

@@ -34,15 +35,18 @@ async function install() {
3435

3536
console.log('fetching from URL', url)
3637
const response = await fetch(url);
37-
if (!response.ok) {
38+
if (!response.ok || !response.body) {
3839
throw new Error("Failed fetching the binary: " + response.statusText);
3940
}
4041

4142
const tarFile = "downloaded.tar.gz";
4243

4344
await fs.mkdir(binPath, { recursive: true });
4445
await pipeline(response.body, createWriteStream(tarFile));
45-
await tar.x({ file: tarFile, cwd: binPath });
46+
47+
const readStream = createReadStream(tarFile);
48+
await pipeline(readStream, createGunzip(), unpackTar(binPath));
49+
4650
await fs.rm(tarFile);
4751
}
4852

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
],
2525
"dependencies": {
2626
"adm-zip": "^0.5.10",
27-
"tar": "^6.1.11"
27+
"modern-tar": "^0.3.4"
2828
},
2929
"bugs": {
3030
"url": "https://github.com/pb33f/openapi-changes/issues"

0 commit comments

Comments
 (0)