MCPcopy Index your code
hub / github.com/serverless/serverless / unzipFile

Function unzipFile

packages/sf-core/src/utils/fs/index.js:407–431  ·  view source on GitHub ↗
(zipPath, extractPath)

Source from the content-addressed store, hash-verified

405 * @returns The full path of the extracted content
406 */
407const unzipFile = async (zipPath, extractPath) => {
408 const zip = new AdmZip(zipPath)
409 const zipEntries = zip.getEntries()
410
411 // Extract the ZIP file
412 zip.extractAllTo(extractPath, true)
413
414 // Find the common base path (parent folder) in the ZIP file
415 let commonBasePath = zipEntries.reduce((commonPath, entry) => {
416 const entryPath = entry.entryName.split('/').slice(0, -1).join('/')
417 if (commonPath === null) return entryPath
418 if (commonPath.startsWith(entryPath)) return entryPath
419 if (entryPath.startsWith(commonPath)) return commonPath
420 return ''
421 }, null)
422
423 // If the common base path is the empty string or only consists of '.', there is no common parent folder
424 if (!commonBasePath || commonBasePath === '.') {
425 commonBasePath = ''
426 }
427
428 // Combine the extractPath with the commonBasePath
429 const extractedContentsPath = path.join(extractPath, commonBasePath)
430 return extractedContentsPath
431}
432
433/**
434 * Get .{basePath} file path in the current working directory. This can be used

Callers 1

downloadTemplateFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…