MCPcopy
hub / github.com/prisma/prisma / downloadBinary

Function downloadBinary

packages/fetch-engine/src/download.ts:389–420  ·  view source on GitHub ↗
(options: DownloadBinaryOptions)

Source from the content-addressed store, hash-verified

387}
388
389async function downloadBinary(options: DownloadBinaryOptions): Promise<void> {
390 const { version, progressCb, targetFilePath, downloadUrl } = options
391
392 const targetDir = path.dirname(targetFilePath)
393
394 try {
395 fs.accessSync(targetDir, fs.constants.W_OK)
396 await ensureDir(targetDir)
397 } catch (e) {
398 if (options.failSilent || (e as NodeJS.ErrnoException).code !== 'EACCES') {
399 return
400 } else {
401 throw new Error(`Can't write to ${targetDir} please make sure you install "prisma" with the right permissions.`)
402 }
403 }
404
405 debug(`Downloading ${downloadUrl} to ${targetFilePath} ...`)
406
407 if (progressCb) {
408 progressCb(0)
409 }
410
411 const { sha256, zippedSha256 } = await downloadZip(downloadUrl, targetFilePath, progressCb)
412 if (progressCb) {
413 progressCb(1)
414 }
415
416 chmodPlusX(targetFilePath)
417
418 // Cache result
419 await saveFileToCache(options, version, sha256, zippedSha256)
420}
421
422async function saveFileToCache(
423 job: BinaryDownloadJob,

Callers 1

downloadFunction · 0.85

Calls 4

downloadZipFunction · 0.90
chmodPlusXFunction · 0.90
debugFunction · 0.85
saveFileToCacheFunction · 0.85

Tested by

no test coverage detected