-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathfastar.pyi
More file actions
174 lines (137 loc) · 5.35 KB
/
Copy pathfastar.pyi
File metadata and controls
174 lines (137 loc) · 5.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
from os import PathLike
from pathlib import Path
from typing import Literal, overload
from typing_extensions import Self
class FastarError(Exception):
"""Base exception for all fastar errors."""
class ArchiveClosedError(FastarError):
"""Exception raised when attempting to use a closed archive."""
class ArchiveUnpackingError(FastarError):
"""Exception raised when unpacking an archive fails."""
class ArchiveAppendingError(FastarError):
"""Exception raised when appending to an archive fails."""
class NameDerivationError(ArchiveAppendingError):
"""Exception raised when a file name cannot be derived from a path."""
class ArchiveWriter:
"""A tar archive writer that supports compressed and uncompressed formats."""
@classmethod
def open(
cls,
path: str | Path | PathLike[str],
mode: Literal["w", "w:gz", "w:zst"],
*,
sparse: bool = True,
) -> Self:
"""
Open a tar archive for writing.
Args:
path: Path to the archive file to create
mode: Write mode - 'w' for uncompressed, 'w:gz' for gzip compressed, 'w:zst' for zstd compressed
sparse: When true and supported by the underlying filesystem, sparse file information is read from disk and empty segments are omitted from the archive.
Returns:
An ArchiveWriter instance
Raises:
ValueError: If an unsupported mode is provided
OSError: If the file cannot be opened
"""
def append(
self,
path: str | Path | PathLike[str],
arcname: str | Path | PathLike[str] | None = None,
recursive: bool = True,
dereference: bool = False,
) -> None:
"""
Append a file or directory to the archive.
Args:
path: Path to the file or directory to append
arcname: Name to use in the archive (defaults to the filename)
recursive: If True and path is a directory, append all contents recursively
dereference: If True, append the target of symlinks instead of the symlink itself
Raises:
ArchiveClosedError: If the archive is already closed
ArchiveAppendingError: If the target cannot be appended to the archive
OSError: If there's an error reading the target file or directory
"""
def close(self) -> None:
"""
Close the archive and flush all pending writes.
Raises:
OSError: If there's an error flushing the archive
"""
def __enter__(self) -> Self:
"""Enter the context manager."""
def __exit__(self, exc_type, exc_value, traceback) -> bool:
"""Exit the context manager, closing the archive."""
class ArchiveReader:
"""A tar archive reader that supports compressed and uncompressed formats."""
@classmethod
def open(
cls,
path: str | Path | PathLike[str],
mode: Literal["r", "r:", "r:gz", "r:zst"],
) -> Self:
"""
Open a tar archive for reading.
Args:
path: Path to the archive file to read
mode: Read mode - 'r' for transparent compression, 'r:gz' for gzip compressed, 'r:zst' for zstd compressed
Returns:
An ArchiveReader instance
Raises:
ValueError: If an unsupported mode is provided
OSError: If the file cannot be opened
"""
def unpack(
self, to: str | Path | PathLike[str], preserve_mtime: bool = True
) -> None:
"""
Unpack all contents of the archive and put them into the specified directory.
Args:
to: Destination directory path
preserve_mtime: whether to preserve file modification times
Raises:
ArchiveClosedError: If the archive is already closed
ArchiveUnpackingError: If the archive cannot be unpacked
OSError: If unpacking fails due to I/O errors
"""
def close(self) -> None:
"""Close the archive."""
def __enter__(self) -> Self:
"""Enter the context manager."""
def __exit__(self, exc_type, exc_value, traceback) -> bool:
"""Exit the context manager, closing the archive."""
@overload
def open(
path: str | Path | PathLike[str],
mode: Literal["w", "w:gz", "w:zst"],
*,
sparse: bool = True,
) -> ArchiveWriter:
"""
Open a tar archive for writing.
Args:
path: Path to the archive file to create
mode: Write mode - 'w' for uncompressed, 'w:gz' for gzip compressed, 'w:zst' for zstd compressed
sparse: When true and supported by the underlying filesystem, sparse file information is read from disk and empty segments are omitted from the archive.
Returns:
An ArchiveWriter instance
Raises:
ValueError: If an unsupported mode is provided
OSError: If the file cannot be opened
"""
@overload
def open(
path: str | Path | PathLike[str], mode: Literal["r", "r:", "r:gz", "r:zst"]
) -> ArchiveReader:
"""
Open a tar archive for reading.
Args:
path: Path to the archive file to read
mode: Read mode - 'r' for transparent compression, 'r:gz' for gzip compressed, 'r:zst' for zstd compressed
Returns:
An ArchiveReader instance
Raises:
ValueError: If an unsupported mode is provided
OSError: If the file cannot be opened
"""