Format: application/octet-stream
1 import io
2 import sys
3 from _typeshed import AnyPath
4 from typing import IO, Any, Optional, TextIO, TypeVar, Union, overload
5 from typing_extensions import Literal
6
7 _PathOrFile = Union[AnyPath, IO[bytes]]
8 _T = TypeVar("_T")
9
10 def compress(data: bytes, compresslevel: int = ...) -> bytes: ...
11 def decompress(data: bytes) -> bytes: ...
12
13 if sys.version_info >= (3, 3):
14 _OpenBinaryMode = Literal["r", "rb", "w", "wb", "x", "xb", "a", "ab"]
15 _OpenTextMode = Literal["rt", "wt", "xt", "at"]
16 @overload
17 def open(
18 filename: _PathOrFile,
19 mode: _OpenBinaryMode = ...,
20 compresslevel: int = ...,
21 encoding: None = ...,
22 errors: None = ...,
23 newline: None = ...,
24 ) -> BZ2File: ...
25 @overload
26 def open(
27 filename: AnyPath,
28 mode: _OpenTextMode,
29 compresslevel: int = ...,
30 encoding: Optional[str] = ...,
31 errors: Optional[str] = ...,
32 newline: Optional[str] = ...,
33 ) -> TextIO: ...
34 @overload
35 def open(
36 filename: _PathOrFile,
37 mode: str,
38 compresslevel: int = ...,
39 encoding: Optional[str] = ...,
40 errors: Optional[str] = ...,
41 newline: Optional[str] = ...,
42 ) -> Union[BZ2File, TextIO]: ...
43
44 class BZ2File(io.BufferedIOBase, IO[bytes]):
45 def __enter__(self: _T) -> _T: ...
46 if sys.version_info >= (3, 9):
47 def __init__(self, filename: _PathOrFile, mode: str = ..., *, compresslevel: int = ...) -> None: ...
48 else:
49 def __init__(
50 self, filename: _PathOrFile, mode: str = ..., buffering: Optional[Any] = ..., compresslevel: int = ...
51 ) -> None: ...
52
53 class BZ2Compressor(object):
54 def __init__(self, compresslevel: int = ...) -> None: ...
55 def compress(self, data: bytes) -> bytes: ...
56 def flush(self) -> bytes: ...
57
58 class BZ2Decompressor(object):
59 if sys.version_info >= (3, 5):
60 def decompress(self, data: bytes, max_length: int = ...) -> bytes: ...
61 else:
62 def decompress(self, data: bytes) -> bytes: ...
63 if sys.version_info >= (3, 3):
64 @property
65 def eof(self) -> bool: ...
66 if sys.version_info >= (3, 5):
67 @property
68 def needs_input(self) -> bool: ...
69 @property
70 def unused_data(self) -> bytes: ...
71