(buffer, binaryPath, extractedBinary, assetName)
| 281 | } |
| 282 | |
| 283 | async function extractTarGz(buffer, binaryPath, extractedBinary, assetName) { |
| 284 | const binaryDir = path.dirname(binaryPath) |
| 285 | const tmpDir = path.join(binaryDir, '.tmp-download') |
| 286 | rmSync(tmpDir, { recursive: true, force: true }) |
| 287 | mkdirSync(tmpDir, { recursive: true }) |
| 288 | try { |
| 289 | const archivePath = path.join(tmpDir, assetName) |
| 290 | writeFileSync(archivePath, buffer) |
| 291 | const result = spawnSync('tar', ['xzf', archivePath, '-C', tmpDir], { |
| 292 | stdio: 'pipe', |
| 293 | }) |
| 294 | if (result.status !== 0) { |
| 295 | throw new Error(`tar extract failed: ${result.stderr?.toString()}`) |
| 296 | } |
| 297 | const srcBinary = path.join(tmpDir, extractedBinary) |
| 298 | if (!existsSync(srcBinary)) { |
| 299 | throw new Error(`Binary not found at expected path: ${srcBinary}`) |
| 300 | } |
| 301 | renameSync(srcBinary, binaryPath) |
| 302 | } finally { |
| 303 | rmSync(tmpDir, { recursive: true, force: true }) |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | // --- Main --- |
| 308 |
no test coverage detected