|
| 1 | +from _typeshed import ReadableBuffer, StrOrBytesPath, SupportsWrite, WriteableBuffer |
| 2 | +from collections.abc import Mapping |
| 3 | +from compression._common import _streams |
| 4 | +from compression.zstd import ZstdDict |
| 5 | +from io import TextIOWrapper, _WrappedBuffer |
| 6 | +from typing import Literal, overload, type_check_only |
| 7 | +from typing_extensions import TypeAlias |
| 8 | + |
| 9 | +from _zstd import ZstdCompressor, _ZstdCompressorFlushBlock, _ZstdCompressorFlushFrame |
| 10 | + |
| 11 | +__all__ = ("ZstdFile", "open") |
| 12 | + |
| 13 | +_ReadBinaryMode: TypeAlias = Literal["r", "rb"] |
| 14 | +_WriteBinaryMode: TypeAlias = Literal["w", "wb", "x", "xb", "a", "ab"] |
| 15 | +_ReadTextMode: TypeAlias = Literal["rt"] |
| 16 | +_WriteTextMode: TypeAlias = Literal["wt", "xt", "at"] |
| 17 | + |
| 18 | +@type_check_only |
| 19 | +class _FileBinaryRead(_streams._Reader): |
| 20 | + def close(self) -> None: ... |
| 21 | + |
| 22 | +@type_check_only |
| 23 | +class _FileBinaryWrite(SupportsWrite[bytes]): |
| 24 | + def close(self) -> None: ... |
| 25 | + |
| 26 | +class ZstdFile(_streams.BaseStream): |
| 27 | + FLUSH_BLOCK = ZstdCompressor.FLUSH_BLOCK |
| 28 | + FLUSH_FRAME = ZstdCompressor.FLUSH_FRAME |
| 29 | + |
| 30 | + @overload |
| 31 | + def __init__( |
| 32 | + self, |
| 33 | + file: StrOrBytesPath | _FileBinaryRead, |
| 34 | + /, |
| 35 | + mode: _ReadBinaryMode = "r", |
| 36 | + *, |
| 37 | + level: None = None, |
| 38 | + options: Mapping[int, int] | None = None, |
| 39 | + zstd_dict: ZstdDict | None = None, |
| 40 | + ) -> None: ... |
| 41 | + @overload |
| 42 | + def __init__( |
| 43 | + self, |
| 44 | + file: StrOrBytesPath | _FileBinaryWrite, |
| 45 | + /, |
| 46 | + mode: _WriteBinaryMode, |
| 47 | + *, |
| 48 | + level: int | None = None, |
| 49 | + options: Mapping[int, int] | None = None, |
| 50 | + zstd_dict: ZstdDict | None = None, |
| 51 | + ) -> None: ... |
| 52 | + def write(self, data: ReadableBuffer, /) -> int: ... |
| 53 | + def flush(self, mode: _ZstdCompressorFlushBlock | _ZstdCompressorFlushFrame = 1) -> bytes: ... # type: ignore[override] |
| 54 | + def read(self, size: int | None = -1) -> bytes: ... |
| 55 | + def read1(self, size: int | None = -1) -> bytes: ... |
| 56 | + def readinto(self, b: WriteableBuffer) -> int: ... |
| 57 | + def readinto1(self, b: WriteableBuffer) -> int: ... |
| 58 | + def readline(self, size: int | None = -1) -> bytes: ... |
| 59 | + def seek(self, offset: int, whence: int = 0) -> int: ... |
| 60 | + def peek(self, size: int = -1) -> bytes: ... |
| 61 | + @property |
| 62 | + def name(self) -> str | bytes: ... |
| 63 | + @property |
| 64 | + def mode(self) -> Literal["rb", "wb"]: ... |
| 65 | + |
| 66 | +@overload |
| 67 | +def open( |
| 68 | + file: StrOrBytesPath | _FileBinaryRead, |
| 69 | + /, |
| 70 | + mode: _ReadBinaryMode = "rb", |
| 71 | + *, |
| 72 | + level: None = None, |
| 73 | + options: Mapping[int, int] | None = None, |
| 74 | + zstd_dict: ZstdDict | None = None, |
| 75 | + encoding: str | None = None, |
| 76 | + errors: str | None = None, |
| 77 | + newline: str | None = None, |
| 78 | +) -> ZstdFile: ... |
| 79 | +@overload |
| 80 | +def open( |
| 81 | + file: StrOrBytesPath | _FileBinaryWrite, |
| 82 | + /, |
| 83 | + mode: _WriteBinaryMode, |
| 84 | + *, |
| 85 | + level: int | None = None, |
| 86 | + options: Mapping[int, int] | None = None, |
| 87 | + zstd_dict: ZstdDict | None = None, |
| 88 | + encoding: str | None = None, |
| 89 | + errors: str | None = None, |
| 90 | + newline: str | None = None, |
| 91 | +) -> ZstdFile: ... |
| 92 | +@overload |
| 93 | +def open( |
| 94 | + file: StrOrBytesPath | _WrappedBuffer, |
| 95 | + /, |
| 96 | + mode: _ReadTextMode, |
| 97 | + *, |
| 98 | + level: None = None, |
| 99 | + options: Mapping[int, int] | None = None, |
| 100 | + zstd_dict: ZstdDict | None = None, |
| 101 | + encoding: str | None = None, |
| 102 | + errors: str | None = None, |
| 103 | + newline: str | None = None, |
| 104 | +) -> TextIOWrapper: ... |
| 105 | +@overload |
| 106 | +def open( |
| 107 | + file: StrOrBytesPath | _WrappedBuffer, |
| 108 | + /, |
| 109 | + mode: _WriteTextMode, |
| 110 | + *, |
| 111 | + level: int | None = None, |
| 112 | + options: Mapping[int, int] | None = None, |
| 113 | + zstd_dict: ZstdDict | None = None, |
| 114 | + encoding: str | None = None, |
| 115 | + errors: str | None = None, |
| 116 | + newline: str | None = None, |
| 117 | +) -> TextIOWrapper: ... |
0 commit comments