Debian Codegraph @

src/python/backports/zstd/__init__.pyi

raw symbols SCIP
1 import enum
2 from io import BufferedIOBase, TextIOWrapper, _WrappedBuffer
3 from typing import (
4 Any,
5 Final,
6 Iterable,
7 Literal,
8 Mapping,
9 Protocol,
10 Self,
11 TypeAlias,
12 final,
13 overload,
14 type_check_only,
15 )
16
17 from _typeshed import ReadableBuffer, StrOrBytesPath, SupportsWrite, WriteableBuffer
18
19 @type_check_only
20 class _streams_Reader(Protocol):
21 def read(self, n: int, /) -> bytes: ...
22 def seekable(self) -> bool: ...
23 def seek(self, n: int, /) -> Any: ...
24
25 @type_check_only
26 class _streams_BaseStream(BufferedIOBase): ...
27
28 #
29 # __init__.py
30 #
31
32 __all__ = (
33 # backports.zstd
34 "COMPRESSION_LEVEL_DEFAULT",
35 "compress",
36 "CompressionParameter",
37 "decompress",
38 "DecompressionParameter",
39 "finalize_dict",
40 "get_frame_info",
41 "Strategy",
42 "train_dict",
43 # backports.zstd._shutil
44 "register_shutil",
45 # backports.zstd._zstdfile
46 "open",
47 "ZstdFile",
48 # backports.zstd._zstd
49 "get_frame_size",
50 "zstd_version",
51 "zstd_version_info",
52 "ZstdCompressor",
53 "ZstdDecompressor",
54 "ZstdDict",
55 "ZstdError",
56 )
57
58 zstd_version_info: Final[tuple[int, int, int]]
59 COMPRESSION_LEVEL_DEFAULT: Final[int] = ...
60
61 class FrameInfo:
62 __slots__ = ("decompressed_size", "dictionary_id")
63 decompressed_size: int
64 dictionary_id: int
65 def __init__(self, decompressed_size: int, dictionary_id: int) -> None: ...
66
67 def get_frame_info(frame_buffer: ReadableBuffer) -> FrameInfo: ...
68 def train_dict(samples: Iterable[ReadableBuffer], dict_size: int) -> ZstdDict: ...
69 def finalize_dict(zstd_dict: ZstdDict, /, samples: Iterable[ReadableBuffer], dict_size: int, level: int) -> ZstdDict: ...
70 def compress(
71 data: ReadableBuffer,
72 level: int | None = None,
73 options: Mapping[int, int] | None = None,
74 zstd_dict: ZstdDict | tuple[ZstdDict, int] | None = None,
75 ) -> bytes: ...
76 def decompress(
77 data: ReadableBuffer, zstd_dict: ZstdDict | tuple[ZstdDict, int] | None = None, options: Mapping[int, int] | None = None
78 ) -> bytes: ...
79
80 @final
81 class CompressionParameter(enum.IntEnum):
82 compression_level = ...
83 window_log = ...
84 hash_log = ...
85 chain_log = ...
86 search_log = ...
87 min_match = ...
88 target_length = ...
89 strategy = ...
90 enable_long_distance_matching = ...
91 ldm_hash_log = ...
92 ldm_min_match = ...
93 ldm_bucket_size_log = ...
94 ldm_hash_rate_log = ...
95 content_size_flag = ...
96 checksum_flag = ...
97 dict_id_flag = ...
98 nb_workers = ...
99 job_size = ...
100 overlap_log = ...
101 def bounds(self) -> tuple[int, int]: ...
102
103 @final
104 class DecompressionParameter(enum.IntEnum):
105 window_log_max = ...
106 def bounds(self) -> tuple[int, int]: ...
107
108 @final
109 class Strategy(enum.IntEnum):
110 fast = ...
111 dfast = ...
112 greedy = ...
113 lazy = ...
114 lazy2 = ...
115 btlazy2 = ...
116 btopt = ...
117 btultra = ...
118 btultra2 = ...
119
120 #
121 # _shutil
122 #
123
124 def register_shutil(*, tar: bool = True, zip: bool = True) -> None: ...
125
126 #
127 # _zstdfile
128 #
129
130 _ReadBinaryMode: TypeAlias = Literal["r", "rb"]
131 _WriteBinaryMode: TypeAlias = Literal["w", "wb", "x", "xb", "a", "ab"]
132 _ReadTextMode: TypeAlias = Literal["rt"]
133 _WriteTextMode: TypeAlias = Literal["wt", "xt", "at"]
134
135 @type_check_only
136 class _FileBinaryRead(_streams_Reader, Protocol):
137 def close(self) -> None: ...
138
139 @type_check_only
140 class _FileBinaryWrite(SupportsWrite[bytes], Protocol):
141 def close(self) -> None: ...
142
143 class ZstdFile(_streams_BaseStream):
144 FLUSH_BLOCK = ZstdCompressor.FLUSH_BLOCK
145 FLUSH_FRAME = ZstdCompressor.FLUSH_FRAME
146
147 @overload
148 def __init__(
149 self,
150 file: StrOrBytesPath | _FileBinaryRead,
151 /,
152 mode: _ReadBinaryMode = "r",
153 *,
154 level: None = None,
155 options: Mapping[int, int] | None = None,
156 zstd_dict: ZstdDict | tuple[ZstdDict, int] | None = None,
157 ) -> None: ...
158 @overload
159 def __init__(
160 self,
161 file: StrOrBytesPath | _FileBinaryWrite,
162 /,
163 mode: _WriteBinaryMode,
164 *,
165 level: int | None = None,
166 options: Mapping[int, int] | None = None,
167 zstd_dict: ZstdDict | tuple[ZstdDict, int] | None = None,
168 ) -> None: ...
169
170 def write(self, data: ReadableBuffer, /) -> int: ...
171 def flush(self, mode: _ZstdCompressorFlushBlock | _ZstdCompressorFlushFrame = 1) -> bytes: ... # type: ignore[override]
172 def read(self, size: int | None = -1) -> bytes: ...
173 def read1(self, size: int | None = -1) -> bytes: ...
174 def readinto(self, b: WriteableBuffer) -> int: ...
175 def readinto1(self, b: WriteableBuffer) -> int: ...
176 def readline(self, size: int | None = -1) -> bytes: ...
177 def seek(self, offset: int, whence: int = 0) -> int: ...
178 def peek(self, size: int = -1) -> bytes: ...
179 @property
180 def name(self) -> str | bytes: ...
181 @property
182 def mode(self) -> Literal["rb", "wb"]: ...
183
184 @overload
185 def open(
186 file: StrOrBytesPath | _FileBinaryRead,
187 /,
188 mode: _ReadBinaryMode = "rb",
189 *,
190 level: None = None,
191 options: Mapping[int, int] | None = None,
192 zstd_dict: ZstdDict | tuple[ZstdDict, int] | None = None,
193 encoding: str | None = None,
194 errors: str | None = None,
195 newline: str | None = None,
196 ) -> ZstdFile: ...
197 @overload
198 def open(
199 file: StrOrBytesPath | _FileBinaryWrite,
200 /,
201 mode: _WriteBinaryMode,
202 *,
203 level: int | None = None,
204 options: Mapping[int, int] | None = None,
205 zstd_dict: ZstdDict | tuple[ZstdDict, int] | None = None,
206 encoding: str | None = None,
207 errors: str | None = None,
208 newline: str | None = None,
209 ) -> ZstdFile: ...
210 @overload
211 def open(
212 file: StrOrBytesPath | _WrappedBuffer,
213 /,
214 mode: _ReadTextMode,
215 *,
216 level: None = None,
217 options: Mapping[int, int] | None = None,
218 zstd_dict: ZstdDict | tuple[ZstdDict, int] | None = None,
219 encoding: str | None = None,
220 errors: str | None = None,
221 newline: str | None = None,
222 ) -> TextIOWrapper: ...
223 @overload
224 def open(
225 file: StrOrBytesPath | _WrappedBuffer,
226 /,
227 mode: _WriteTextMode,
228 *,
229 level: int | None = None,
230 options: Mapping[int, int] | None = None,
231 zstd_dict: ZstdDict | tuple[ZstdDict, int] | None = None,
232 encoding: str | None = None,
233 errors: str | None = None,
234 newline: str | None = None,
235 ) -> TextIOWrapper: ...
236
237 #
238 # _zstd
239 #
240
241 _ZstdCompressorContinue: TypeAlias = Literal[0]
242 _ZstdCompressorFlushBlock: TypeAlias = Literal[1]
243 _ZstdCompressorFlushFrame: TypeAlias = Literal[2]
244
245 @final
246 class ZstdCompressor:
247 CONTINUE: Final = 0
248 FLUSH_BLOCK: Final = 1
249 FLUSH_FRAME: Final = 2
250 def __new__(
251 cls,
252 level: int | None = None,
253 options: Mapping[int, int] | None = None,
254 zstd_dict: ZstdDict | tuple[ZstdDict, int] | None = None,
255 ) -> Self: ...
256 def compress(
257 self, /, data: ReadableBuffer, mode: _ZstdCompressorContinue | _ZstdCompressorFlushBlock | _ZstdCompressorFlushFrame = 0
258 ) -> bytes: ...
259 def flush(self, /, mode: _ZstdCompressorFlushBlock | _ZstdCompressorFlushFrame = 2) -> bytes: ...
260 def set_pledged_input_size(self, size: int | None, /) -> None: ...
261 @property
262 def last_mode(self) -> _ZstdCompressorContinue | _ZstdCompressorFlushBlock | _ZstdCompressorFlushFrame: ...
263
264 @final
265 class ZstdDecompressor:
266 def __new__(
267 cls, zstd_dict: ZstdDict | tuple[ZstdDict, int] | None = None, options: Mapping[int, int] | None = None
268 ) -> Self: ...
269 def decompress(self, /, data: ReadableBuffer, max_length: int = -1) -> bytes: ...
270 @property
271 def eof(self) -> bool: ...
272 @property
273 def needs_input(self) -> bool: ...
274 @property
275 def unused_data(self) -> bytes: ...
276
277 @final
278 class ZstdDict:
279 def __new__(cls, dict_content: ReadableBuffer, /, *, is_raw: bool = False) -> Self: ...
280 def __len__(self, /) -> int: ...
281 @property
282 def as_digested_dict(self) -> tuple[Self, int]: ...
283 @property
284 def as_prefix(self) -> tuple[Self, int]: ...
285 @property
286 def as_undigested_dict(self) -> tuple[Self, int]: ...
287 @property
288 def dict_content(self) -> bytes: ...
289 @property
290 def dict_id(self) -> int: ...
291
292 class ZstdError(Exception): ...
293
294 def get_frame_size(frame_buffer: ReadableBuffer) -> int: ...
295
296 zstd_version: Final[str]
297 zstd_version_number: Final[int]