Extract the CLI binary from a .zip archive.
(data: bytes, binary_name: str, dest_dir: Path)
| 183 | |
| 184 | |
| 185 | def _extract_zip(data: bytes, binary_name: str, dest_dir: Path) -> Path: |
| 186 | """Extract the CLI binary from a .zip archive.""" |
| 187 | with zipfile.ZipFile(io.BytesIO(data)) as zf: |
| 188 | names = zf.namelist() |
| 189 | target_member = None |
| 190 | for name in names: |
| 191 | if name == binary_name or name.endswith(f"/{binary_name}"): |
| 192 | target_member = name |
| 193 | break |
| 194 | |
| 195 | if target_member is None: |
| 196 | raise RuntimeError( |
| 197 | f"Binary '{binary_name}' not found in archive. Archive contains: {names}" |
| 198 | ) |
| 199 | |
| 200 | dest_path = dest_dir / binary_name |
| 201 | with zf.open(target_member) as src, open(dest_path, "wb") as out: |
| 202 | out.write(src.read()) |
| 203 | |
| 204 | return dest_path |
| 205 | |
| 206 | |
| 207 | def download_cli(version: str | None = None, *, force: bool = False) -> str: |
no test coverage detected
searching dependent graphs…