MCPcopy Create free account
hub / github.com/github/copilot-sdk / _extract_tar_gz

Function _extract_tar_gz

python/copilot/_cli_download.py:157–182  ·  view source on GitHub ↗

Extract the CLI binary from a .tar.gz archive.

(data: bytes, binary_name: str, dest_dir: Path)

Source from the content-addressed store, hash-verified

155
156
157def _extract_tar_gz(data: bytes, binary_name: str, dest_dir: Path) -> Path:
158 """Extract the CLI binary from a .tar.gz archive."""
159 with tarfile.open(fileobj=io.BytesIO(data), mode="r:gz") as tf:
160 # Find the binary in the archive (may be at top level or in a subdirectory)
161 members = tf.getnames()
162 target_member = None
163 for name in members:
164 if name == binary_name or name.endswith(f"/{binary_name}"):
165 target_member = name
166 break
167
168 if target_member is None:
169 raise RuntimeError(
170 f"Binary '{binary_name}' not found in archive. Archive contains: {members}"
171 )
172
173 member = tf.getmember(target_member)
174 f = tf.extractfile(member)
175 if f is None:
176 raise RuntimeError(f"Could not extract '{target_member}' from archive")
177
178 dest_path = dest_dir / binary_name
179 with open(dest_path, "wb") as out:
180 out.write(f.read())
181
182 return dest_path
183
184
185def _extract_zip(data: bytes, binary_name: str, dest_dir: Path) -> Path:

Callers 1

download_cliFunction · 0.85

Calls 3

openMethod · 0.65
writeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…