(zipPath, extractPath)
| 405 | * @returns The full path of the extracted content |
| 406 | */ |
| 407 | const 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 |
no outgoing calls
no test coverage detected
searching dependent graphs…