MCPcopy
hub / github.com/wkentaro/gdown / extractall

Function extractall

gdown/extractall.py:17–51  ·  view source on GitHub ↗

Extract archive file. Parameters ---------- path: Path of archive file to be extracted. to: Directory to which the archive file will be extracted. If None, it will be set to the parent directory of the archive file. Raises ------ ValueError

(path: str, to: str | None = None)

Source from the content-addressed store, hash-verified

15
16
17def extractall(path: str, to: str | None = None) -> list[str]:
18 """Extract archive file.
19
20 Parameters
21 ----------
22 path:
23 Path of archive file to be extracted.
24 to:
25 Directory to which the archive file will be extracted.
26 If None, it will be set to the parent directory of the archive file.
27
28 Raises
29 ------
30 ValueError
31 If the archive format is unsupported, or if an archive member would
32 extract outside the target directory.
33 """
34 if to is None:
35 to = osp.dirname(path)
36
37 if path.endswith(".zip"):
38 return _extractall_zip(path=path, to=to)
39
40 if path.endswith(".tar"):
41 tar_mode = "r"
42 elif path.endswith(".tar.gz") or path.endswith(".tgz"):
43 tar_mode = "r:gz"
44 elif path.endswith(".tar.bz2") or path.endswith(".tbz"):
45 tar_mode = "r:bz2"
46 else:
47 raise ValueError(
48 f"Could not extract '{path}' as no appropriate extractor is found"
49 )
50
51 return _extractall_tar(path=path, to=to, tar_mode=tar_mode)
52
53
54def _extractall_zip(path: str, to: str) -> list[str]:

Callers 9

test_zip_normalFunction · 0.90
test_tar_normalFunction · 0.90
test_zip_path_traversalFunction · 0.90
test_zip_absolute_pathFunction · 0.90
test_tar_absolute_pathFunction · 0.90
test_tar_path_traversalFunction · 0.90

Calls 2

_extractall_zipFunction · 0.85
_extractall_tarFunction · 0.85

Tested by 9

test_zip_normalFunction · 0.72
test_tar_normalFunction · 0.72
test_zip_path_traversalFunction · 0.72
test_zip_absolute_pathFunction · 0.72
test_tar_absolute_pathFunction · 0.72
test_tar_path_traversalFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…