(buffer, binaryPath, extractedBinary, assetName)
| 152 | } |
| 153 | |
| 154 | async function extractTarGz(buffer, binaryPath, extractedBinary, assetName) { |
| 155 | const dir = path.dirname(binaryPath) |
| 156 | const tmpDir = path.join(dir, '.tmp-download') |
| 157 | rmSync(tmpDir, { recursive: true, force: true }) |
| 158 | mkdirSync(tmpDir, { recursive: true }) |
| 159 | try { |
| 160 | const archivePath = path.join(tmpDir, assetName) |
| 161 | writeFileSync(archivePath, buffer) |
| 162 | const result = spawnSync('tar', ['xzf', archivePath, '-C', tmpDir], { stdio: 'pipe' }) |
| 163 | if (result.status !== 0) throw new Error(`tar extract failed: ${result.stderr?.toString()}`) |
| 164 | const srcBinary = path.join(tmpDir, extractedBinary) |
| 165 | if (!existsSync(srcBinary)) throw new Error(`Binary not found at expected path: ${srcBinary}`) |
| 166 | renameSync(srcBinary, binaryPath) |
| 167 | } finally { |
| 168 | rmSync(tmpDir, { recursive: true, force: true }) |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | async function main() { |
| 173 | const { target, ext } = getPlatformMapping() |
no test coverage detected