4 from _typeshed import ReadableBuffer, StrOrBytesPath
6 from typing import Any, Protocol, TextIO, overload
7 from typing_extensions import Literal
9 _ReadBinaryMode = Literal["r", "rb"]
10 _WriteBinaryMode = Literal["a", "ab", "w", "wb", "x", "xb"]
11 _OpenTextMode = Literal["rt", "at", "wt", "xt"]
16 class _ReadableFileobj(Protocol):
17 def read(self, __n: int) -> bytes: ...
18 def seek(self, __n: int) -> Any: ...
19 # The following attributes and methods are optional:
22 # def fileno() -> int: ...
24 class _WritableFileobj(Protocol):
25 def write(self, __b: bytes) -> Any: ...
26 def flush(self) -> Any: ...
27 # The following attributes and methods are optional:
30 # def fileno() -> int: ...
34 filename: StrOrBytesPath | _ReadableFileobj,
35 mode: _ReadBinaryMode = ...,
36 compresslevel: int = ...,
43 filename: StrOrBytesPath | _WritableFileobj,
44 mode: _WriteBinaryMode,
45 compresslevel: int = ...,
52 filename: StrOrBytesPath,
54 compresslevel: int = ...,
55 encoding: str | None = ...,
56 errors: str | None = ...,
57 newline: str | None = ...,
61 filename: StrOrBytesPath | _ReadableFileobj | _WritableFileobj,
63 compresslevel: int = ...,
64 encoding: str | None = ...,
65 errors: str | None = ...,
66 newline: str | None = ...,
67 ) -> GzipFile | TextIO: ...
70 file: _ReadableFileobj
71 def __init__(self, f: _ReadableFileobj, prepend: bytes = ...) -> None: ...
72 def read(self, size: int) -> bytes: ...
73 def prepend(self, prepend: bytes = ...) -> None: ...
74 def seek(self, off: int) -> int: ...
75 def seekable(self) -> bool: ...
77 if sys.version_info >= (3, 8):
78 class BadGzipFile(OSError): ...
80 class GzipFile(_compression.BaseStream):
81 myfileobj: FileIO | None
84 compress: zlib._Compress
85 fileobj: _ReadableFileobj | _WritableFileobj
89 filename: StrOrBytesPath | None,
90 mode: _ReadBinaryMode,
91 compresslevel: int = ...,
92 fileobj: _ReadableFileobj | None = ...,
93 mtime: float | None = ...,
99 mode: _ReadBinaryMode,
100 compresslevel: int = ...,
101 fileobj: _ReadableFileobj | None = ...,
102 mtime: float | None = ...,
107 filename: StrOrBytesPath | None,
108 mode: _WriteBinaryMode,
109 compresslevel: int = ...,
110 fileobj: _WritableFileobj | None = ...,
111 mtime: float | None = ...,
117 mode: _WriteBinaryMode,
118 compresslevel: int = ...,
119 fileobj: _WritableFileobj | None = ...,
120 mtime: float | None = ...,
125 filename: StrOrBytesPath | None = ...,
126 mode: str | None = ...,
127 compresslevel: int = ...,
128 fileobj: _ReadableFileobj | _WritableFileobj | None = ...,
129 mtime: float | None = ...,
132 def filename(self) -> str: ...
134 def mtime(self) -> int | None: ...
136 def write(self, data: ReadableBuffer) -> int: ...
137 def read(self, size: int | None = ...) -> bytes: ...
138 def read1(self, size: int = ...) -> bytes: ...
139 def peek(self, n: int) -> bytes: ...
141 def closed(self) -> bool: ...
142 def close(self) -> None: ...
143 def flush(self, zlib_mode: int = ...) -> None: ...
144 def fileno(self) -> int: ...
145 def rewind(self) -> None: ...
146 def readable(self) -> bool: ...
147 def writable(self) -> bool: ...
148 def seekable(self) -> bool: ...
149 def seek(self, offset: int, whence: int = ...) -> int: ...
150 def readline(self, size: int | None = ...) -> bytes: ...
152 class _GzipReader(_compression.DecompressReader):
153 def __init__(self, fp: _ReadableFileobj) -> None: ...
154 def read(self, size: int = ...) -> bytes: ...
156 if sys.version_info >= (3, 8):
157 def compress(data: bytes, compresslevel: int = ..., *, mtime: float | None = ...) -> bytes: ...
160 def compress(data: bytes, compresslevel: int = ...) -> bytes: ...
162 def decompress(data: bytes) -> bytes: ...