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

Function downloadBinary

cli/release-staging/index.js:310–428  ·  view source on GitHub ↗
(version)

Source from the content-addressed store, hash-verified

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