MCPcopy
hub / github.com/claude-code-best/claude-code / downloadAndExtract

Function downloadAndExtract

scripts/postinstall.cjs:309–375  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

307// --- Main ---
308
309async function downloadAndExtract() {
310 const { target, ext } = getPlatformMapping()
311 const assetName = `ripgrep-v${RG_VERSION}-${target}.${ext}`
312
313 const binaryPath = getBinaryPath()
314 const binaryDir = path.dirname(binaryPath)
315
316 const force = process.argv.includes('--force')
317 if (!force && existsSync(binaryPath)) {
318 const stat = statSync(binaryPath)
319 if (stat.size > 0) {
320 console.log(`[ripgrep] Binary already exists at ${binaryPath}, skipping.`)
321 return
322 }
323 }
324
325 console.log(`[ripgrep] Downloading v${RG_VERSION} for ${target}...`)
326
327 const extractedBinary = process.platform === 'win32' ? 'rg.exe' : 'rg'
328
329 const mirrors = [RELEASE_BASE]
330 if (RELEASE_BASE === DEFAULT_RELEASE_BASE.replace(/\/$/, '')) {
331 mirrors.push(MIRROR_RELEASE_BASE.replace(/\/$/, ''))
332 }
333
334 let buffer
335 let lastError
336 for (const base of mirrors) {
337 const url = `${base}/${assetName}`
338 try {
339 console.log(`[ripgrep] Trying ${url}`)
340 buffer = await downloadUrlToBufferWithFallback(url)
341 break
342 } catch (e) {
343 console.warn(
344 `[ripgrep] Download from ${base} failed: ${e instanceof Error ? e.message : e}`,
345 )
346 lastError = e
347 }
348 }
349 if (!buffer) {
350 throw lastError
351 }
352
353 try {
354 console.log(`[ripgrep] Downloaded ${Math.round(buffer.length / 1024)} KB`)
355
356 mkdirSync(binaryDir, { recursive: true })
357
358 if (ext === 'tar.gz') {
359 await extractTarGz(buffer, binaryPath, extractedBinary, assetName)
360 } else {
361 await extractZip(buffer, binaryPath, extractedBinary)
362 }
363
364 if (process.platform !== 'win32') {
365 chmodSync(binaryPath, 0o755)
366 }

Callers 1

mainFunction · 0.85

Calls 10

getPlatformMappingFunction · 0.85
getBinaryPathFunction · 0.85
existsSyncFunction · 0.85
statSyncFunction · 0.85
mkdirSyncFunction · 0.85
extractTarGzFunction · 0.85
extractZipFunction · 0.85
warnMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected