( zipData: Buffer, )
| 111 | * when this module is reached via the plugin loader chain. |
| 112 | */ |
| 113 | export async function unzipFile( |
| 114 | zipData: Buffer, |
| 115 | ): Promise<Record<string, Uint8Array>> { |
| 116 | const { unzipSync } = await import('fflate') |
| 117 | const compressedSize = zipData.length |
| 118 | |
| 119 | const state: ZipValidationState = { |
| 120 | fileCount: 0, |
| 121 | totalUncompressedSize: 0, |
| 122 | compressedSize: compressedSize, |
| 123 | errors: [], |
| 124 | } |
| 125 | |
| 126 | const result = unzipSync(new Uint8Array(zipData), { |
| 127 | filter: file => { |
| 128 | const validationResult = validateZipFile(file, state) |
| 129 | if (!validationResult.isValid) { |
| 130 | throw new Error(validationResult.error!) |
| 131 | } |
| 132 | return true |
| 133 | }, |
| 134 | }) |
| 135 | |
| 136 | logForDebugging( |
| 137 | `Zip extraction completed: ${state.fileCount} files, ${Math.round(state.totalUncompressedSize / 1024)}KB uncompressed`, |
| 138 | ) |
| 139 | |
| 140 | return result |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Parse Unix file modes from a zip's central directory. |
no test coverage detected