|
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"; |
6 | 7 |
|
7 | 8 | import { ARCH_MAPPING, CONFIG, PLATFORM_MAPPING } from "./config.js"; |
8 | 9 |
|
@@ -34,15 +35,18 @@ async function install() { |
34 | 35 |
|
35 | 36 | console.log('fetching from URL', url) |
36 | 37 | const response = await fetch(url); |
37 | | - if (!response.ok) { |
| 38 | + if (!response.ok || !response.body) { |
38 | 39 | throw new Error("Failed fetching the binary: " + response.statusText); |
39 | 40 | } |
40 | 41 |
|
41 | 42 | const tarFile = "downloaded.tar.gz"; |
42 | 43 |
|
43 | 44 | await fs.mkdir(binPath, { recursive: true }); |
44 | 45 | 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 | + |
46 | 50 | await fs.rm(tarFile); |
47 | 51 | } |
48 | 52 |
|
|
0 commit comments