MCPcopy Create free account
hub / github.com/claude-code-internals/claude-code-runnable / extractZip

Function extractZip

scripts/postinstall.cjs:116–152  ·  view source on GitHub ↗
(buffer, binaryPath, extractedBinary)

Source from the content-addressed store, hash-verified

114}
115
116async function extractZip(buffer, binaryPath, extractedBinary) {
117 const dir = path.dirname(binaryPath)
118 let fflateError
119 try {
120 const { unzipSync } = require('fflate')
121 const unzipped = unzipSync(new Uint8Array(buffer))
122 const key = findZipEntryKey(unzipped, extractedBinary)
123 if (!key) throw new Error(`Binary ${extractedBinary} not found in zip`)
124 writeFileSync(binaryPath, Buffer.from(unzipped[key]))
125 return
126 } catch (e) { fflateError = e }
127 const tmpDir = path.join(dir, '.tmp-download')
128 rmSync(tmpDir, { recursive: true, force: true })
129 mkdirSync(tmpDir, { recursive: true })
130 try {
131 const archivePath = path.join(tmpDir, 'archive.zip')
132 writeFileSync(archivePath, buffer)
133 let extracted = false
134 if (process.platform === 'win32') {
135 const psCmd = `Expand-Archive -Path '${archivePath.replace(/'/g, "''")}' -DestinationPath '${tmpDir.replace(/'/g, "''")}' -Force`
136 const r = spawnSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-Command', psCmd], { stdio: 'pipe', windowsHide: true })
137 if (r.status === 0) extracted = true
138 }
139 if (!extracted) {
140 const r = spawnSync('unzip', ['-o', archivePath, '-d', tmpDir], { stdio: 'pipe' })
141 if (r.status !== 0) {
142 const unzipErr = r.stderr?.toString().trim() || 'command not found'
143 throw new Error(`zip extraction failed (fflate: ${fflateError instanceof Error ? fflateError.message : String(fflateError)}; unzip: ${unzipErr})`)
144 }
145 }
146 const srcBinary = path.join(tmpDir, extractedBinary)
147 if (!existsSync(srcBinary)) throw new Error(`Binary not found at expected path: ${srcBinary}`)
148 renameSync(srcBinary, binaryPath)
149 } finally {
150 rmSync(tmpDir, { recursive: true, force: true })
151 }
152}
153
154async function extractTarGz(buffer, binaryPath, extractedBinary, assetName) {
155 const dir = path.dirname(binaryPath)

Callers 1

mainFunction · 0.85

Calls 6

findZipEntryKeyFunction · 0.85
rmSyncFunction · 0.85
mkdirSyncFunction · 0.85
existsSyncFunction · 0.85
renameSyncFunction · 0.85
toStringMethod · 0.65

Tested by

no test coverage detected