MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / downloadBinary

Function downloadBinary

cli/release/index.js:309–448  ·  view source on GitHub ↗
(version)

Source from the content-addressed store, hash-verified

307}
308
309async function downloadBinary(version) {
310 const platformKey = `${process.platform}-${process.arch}`
311 const fileName = PLATFORM_TARGETS[platformKey]
312
313 if (!fileName) {
314 const error = new Error(`Unsupported platform: ${process.platform} ${process.arch}`)
315 trackUpdateFailed(error.message, version, { stage: 'platform_check' })
316 throw error
317 }
318
319 const downloadUrl = `${
320 process.env.NEXT_PUBLIC_CODEBUFF_APP_URL || 'https://codebuff.com'
321 }/api/releases/download/${version}/${fileName}`
322
323 // Ensure config directory exists
324 fs.mkdirSync(CONFIG.configDir, { recursive: true })
325
326 // Clean up any previous temp download directory
327 if (fs.existsSync(CONFIG.tempDownloadDir)) {
328 fs.rmSync(CONFIG.tempDownloadDir, { recursive: true })
329 }
330 fs.mkdirSync(CONFIG.tempDownloadDir, { recursive: true })
331
332 term.write('Downloading...')
333
334 const res = await httpGet(downloadUrl)
335
336 if (res.statusCode !== 200) {
337 fs.rmSync(CONFIG.tempDownloadDir, { recursive: true })
338 const error = new Error(`Download failed: HTTP ${res.statusCode}`)
339 trackUpdateFailed(error.message, version, { stage: 'http_download', statusCode: res.statusCode })
340 throw error
341 }
342
343 const totalSize = parseInt(res.headers['content-length'] || '0', 10)
344 let downloadedSize = 0
345 let lastProgressTime = Date.now()
346
347 res.on('data', (chunk) => {
348 downloadedSize += chunk.length
349 const now = Date.now()
350 if (now - lastProgressTime >= 100 || downloadedSize === totalSize) {
351 lastProgressTime = now
352 if (totalSize > 0) {
353 const pct = Math.round((downloadedSize / totalSize) * 100)
354 term.write(
355 `Downloading... ${createProgressBar(pct)} ${pct}% of ${formatBytes(
356 totalSize,
357 )}`,
358 )
359 } else {
360 term.write(`Downloading... ${formatBytes(downloadedSize)}`)
361 }
362 }
363 })
364
365 // Extract to temp directory
366 await new Promise((resolve, reject) => {

Callers 2

ensureBinaryExistsFunction · 0.70
checkForUpdatesFunction · 0.70

Calls 5

trackUpdateFailedFunction · 0.70
httpGetFunction · 0.70
createProgressBarFunction · 0.70
formatBytesFunction · 0.70
onMethod · 0.65

Tested by

no test coverage detected