| 1 |
# Copyright (c) 2016-present, Gregory Szorc |
| 2 |
# All rights reserved. |
| 3 |
# |
| 4 |
# This software may be modified and distributed under the terms |
| 5 |
# of the BSD license. See the LICENSE file for details. |
| 6 |
|
| 7 |
import os |
| 8 |
|
| 9 |
from typing import ( |
| 10 |
BinaryIO, |
| 11 |
ByteString, |
| 12 |
Generator, |
| 13 |
IO, |
| 14 |
Iterable, |
| 15 |
List, |
| 16 |
Optional, |
| 17 |
Set, |
| 18 |
Tuple, |
| 19 |
Union, |
| 20 |
) |
| 21 |
|
| 22 |
FLUSH_BLOCK: int |
| 23 |
FLUSH_FRAME: int |
| 24 |
|
| 25 |
COMPRESSOBJ_FLUSH_FINISH: int |
| 26 |
COMPRESSOBJ_FLUSH_BLOCK: int |
| 27 |
|
| 28 |
CONTENTSIZE_UNKNOWN: int |
| 29 |
CONTENTSIZE_ERROR: int |
| 30 |
|
| 31 |
MAX_COMPRESSION_LEVEL: int |
| 32 |
|
| 33 |
COMPRESSION_RECOMMENDED_INPUT_SIZE: int |
| 34 |
COMPRESSION_RECOMMENDED_OUTPUT_SIZE: int |
| 35 |
|
| 36 |
DECOMPRESSION_RECOMMENDED_INPUT_SIZE: int |
| 37 |
DECOMPRESSION_RECOMMENDED_OUTPUT_SIZE: int |
| 38 |
|
| 39 |
BLOCKSIZELOG_MAX: int |
| 40 |
BLOCKSIZE_MAX: int |
| 41 |
|
| 42 |
WINDOWLOG_MIN: int |
| 43 |
WINDOWLOG_MAX: int |
| 44 |
|
| 45 |
CHAINLOG_MIN: int |
| 46 |
CHAINLOG_MAX: int |
| 47 |
HASHLOG_MIN: int |
| 48 |
HASHLOG_MAX: int |
| 49 |
MINMATCH_MIN: int |
| 50 |
MINMATCH_MAX: int |
| 51 |
SEARCHLOG_MIN: int |
| 52 |
SEARCHLOG_MAX: int |
| 53 |
SEARCHLENGTH_MIN: int |
| 54 |
SEARCHLENGTH_MAX: int |
| 55 |
TARGETLENGTH_MIN: int |
| 56 |
TARGETLENGTH_MAX: int |
| 57 |
LDM_MINMATCH_MIN: int |
| 58 |
LDM_MINMATCH_MAX: int |
| 59 |
LDM_BUCKETSIZELOG_MAX: int |
| 60 |
|
| 61 |
STRATEGY_FAST: int |
| 62 |
STRATEGY_DFAST: int |
| 63 |
STRATEGY_GREEDY: int |
| 64 |
STRATEGY_LAZY: int |
| 65 |
STRATEGY_LAZY2: int |
| 66 |
STRATEGY_BTLAZY2: int |
| 67 |
STRATEGY_BTOPT: int |
| 68 |
STRATEGY_BTULTRA: int |
| 69 |
STRATEGY_BTULTRA2: int |
| 70 |
|
| 71 |
DICT_TYPE_AUTO: int |
| 72 |
DICT_TYPE_RAWCONTENT: int |
| 73 |
DICT_TYPE_FULLDICT: int |
| 74 |
|
| 75 |
FORMAT_ZSTD1: int |
| 76 |
FORMAT_ZSTD1_MAGICLESS: int |
| 77 |
|
| 78 |
ZSTD_VERSION: Tuple[int, int, int] |
| 79 |
FRAME_HEADER: bytes |
| 80 |
MAGIC_NUMBER: int |
| 81 |
|
| 82 |
backend: str |
| 83 |
backend_features: Set[str] |
| 84 |
__version__: str |
| 85 |
|
| 86 |
class ZstdError(Exception): ... |
| 87 |
|
| 88 |
class BufferSegment(object): |
| 89 |
offset: int |
| 90 |
def __len__(self) -> int: ... |
| 91 |
def tobytes(self) -> bytes: ... |
| 92 |
|
| 93 |
class BufferSegments(object): |
| 94 |
def __len__(self) -> int: ... |
| 95 |
def __getitem__(self, i: int) -> BufferSegment: ... |
| 96 |
|
| 97 |
class BufferWithSegments(object): |
| 98 |
size: int |
| 99 |
def __init__(self, data: ByteString, segments: ByteString): ... |
| 100 |
def __len__(self) -> int: ... |
| 101 |
def __getitem__(self, i: int) -> BufferSegment: ... |
| 102 |
def segments(self): ... |
| 103 |
def tobytes(self) -> bytes: ... |
| 104 |
|
| 105 |
class BufferWithSegmentsCollection(object): |
| 106 |
def __init__(self, *args): ... |
| 107 |
def __len__(self) -> int: ... |
| 108 |
def __getitem__(self, i: int) -> BufferSegment: ... |
| 109 |
def size(self) -> int: ... |
| 110 |
|
| 111 |
class ZstdCompressionParameters(object): |
| 112 |
@staticmethod |
| 113 |
def from_level( |
| 114 |
level: int, source_size: int = ..., dict_size: int = ..., **kwargs |
| 115 |
) -> "ZstdCompressionParameters": ... |
| 116 |
def __init__( |
| 117 |
self, |
| 118 |
format: int = ..., |
| 119 |
compression_level: int = ..., |
| 120 |
window_log: int = ..., |
| 121 |
hash_log: int = ..., |
| 122 |
chain_log: int = ..., |
| 123 |
search_log: int = ..., |
| 124 |
min_match: int = ..., |
| 125 |
target_length: int = ..., |
| 126 |
strategy: int = ..., |
| 127 |
write_content_size: int = ..., |
| 128 |
write_checksum: int = ..., |
| 129 |
write_dict_id: int = ..., |
| 130 |
job_size: int = ..., |
| 131 |
overlap_log: int = ..., |
| 132 |
force_max_window: int = ..., |
| 133 |
enable_ldm: int = ..., |
| 134 |
ldm_hash_log: int = ..., |
| 135 |
ldm_min_match: int = ..., |
| 136 |
ldm_bucket_size_log: int = ..., |
| 137 |
ldm_hash_rate_log: int = ..., |
| 138 |
threads: int = ..., |
| 139 |
): ... |
| 140 |
@property |
| 141 |
def format(self) -> int: ... |
| 142 |
@property |
| 143 |
def compression_level(self) -> int: ... |
| 144 |
@property |
| 145 |
def window_log(self) -> int: ... |
| 146 |
@property |
| 147 |
def hash_log(self) -> int: ... |
| 148 |
@property |
| 149 |
def chain_log(self) -> int: ... |
| 150 |
@property |
| 151 |
def search_log(self) -> int: ... |
| 152 |
@property |
| 153 |
def min_match(self) -> int: ... |
| 154 |
@property |
| 155 |
def target_length(self) -> int: ... |
| 156 |
@property |
| 157 |
def strategy(self) -> int: ... |
| 158 |
@property |
| 159 |
def write_content_size(self) -> int: ... |
| 160 |
@property |
| 161 |
def write_checksum(self) -> int: ... |
| 162 |
@property |
| 163 |
def write_dict_id(self) -> int: ... |
| 164 |
@property |
| 165 |
def job_size(self) -> int: ... |
| 166 |
@property |
| 167 |
def overlap_log(self) -> int: ... |
| 168 |
@property |
| 169 |
def force_max_window(self) -> int: ... |
| 170 |
@property |
| 171 |
def enable_ldm(self) -> int: ... |
| 172 |
@property |
| 173 |
def ldm_hash_log(self) -> int: ... |
| 174 |
@property |
| 175 |
def ldm_min_match(self) -> int: ... |
| 176 |
@property |
| 177 |
def ldm_bucket_size_log(self) -> int: ... |
| 178 |
@property |
| 179 |
def ldm_hash_rate_log(self) -> int: ... |
| 180 |
@property |
| 181 |
def threads(self) -> int: ... |
| 182 |
def estimated_compression_context_size(self) -> int: ... |
| 183 |
|
| 184 |
class CompressionParameters(ZstdCompressionParameters): ... |
| 185 |
|
| 186 |
class ZstdCompressionDict(object): |
| 187 |
k: int |
| 188 |
d: int |
| 189 |
def __init__( |
| 190 |
self, |
| 191 |
data: ByteString, |
| 192 |
dict_type: int = ..., |
| 193 |
k: int = ..., |
| 194 |
d: int = ..., |
| 195 |
): ... |
| 196 |
def __len__(self) -> int: ... |
| 197 |
def dict_id(self) -> int: ... |
| 198 |
def as_bytes(self) -> bytes: ... |
| 199 |
def precompute_compress( |
| 200 |
self, |
| 201 |
level: int = ..., |
| 202 |
compression_params: ZstdCompressionParameters = ..., |
| 203 |
): ... |
| 204 |
|
| 205 |
class ZstdCompressionObj(object): |
| 206 |
def compress(self, data: ByteString) -> bytes: ... |
| 207 |
def flush(self, flush_mode: int = ...) -> bytes: ... |
| 208 |
|
| 209 |
class ZstdCompressionChunker(object): |
| 210 |
def compress(self, data: ByteString): ... |
| 211 |
def flush(self): ... |
| 212 |
def finish(self): ... |
| 213 |
|
| 214 |
class ZstdCompressionReader(BinaryIO): |
| 215 |
def __enter__(self) -> "ZstdCompressionReader": ... |
| 216 |
def __exit__(self, exc_type, exc_value, exc_tb): ... |
| 217 |
def readable(self) -> bool: ... |
| 218 |
def writable(self) -> bool: ... |
| 219 |
def seekable(self) -> bool: ... |
| 220 |
def readline(self, limit: int = ...) -> bytes: ... |
| 221 |
def readlines(self, hint: int = ...) -> List[bytes]: ... |
| 222 |
def write(self, data: ByteString): ... |
| 223 |
def writelines(self, data: Iterable[bytes]): ... |
| 224 |
def isatty(self) -> bool: ... |
| 225 |
def flush(self): ... |
| 226 |
def close(self): ... |
| 227 |
@property |
| 228 |
def closed(self) -> bool: ... |
| 229 |
def tell(self) -> int: ... |
| 230 |
def readall(self) -> bytes: ... |
| 231 |
def __iter__(self): ... |
| 232 |
def __next__(self): ... |
| 233 |
def next(self): ... |
| 234 |
def read(self, size: int = ...) -> bytes: ... |
| 235 |
def read1(self, size: int = ...) -> bytes: ... |
| 236 |
def readinto(self, b) -> int: ... |
| 237 |
def readinto1(self, b) -> int: ... |
| 238 |
|
| 239 |
class ZstdCompressionWriter(BinaryIO): |
| 240 |
def __enter__(self) -> "ZstdCompressionWriter": ... |
| 241 |
def __exit__(self, exc_type, exc_value, exc_tb): ... |
| 242 |
def memory_size(self) -> int: ... |
| 243 |
def fileno(self) -> int: ... |
| 244 |
def close(self): ... |
| 245 |
@property |
| 246 |
def closed(self) -> bool: ... |
| 247 |
def isatty(self) -> bool: ... |
| 248 |
def readable(self) -> bool: ... |
| 249 |
def readline(self, size: int = ...) -> bytes: ... |
| 250 |
def readlines(self, hint: int = ...) -> List[bytes]: ... |
| 251 |
def seek(self, offset: int, whence: int = ...): ... |
| 252 |
def seekable(self) -> bool: ... |
| 253 |
def truncate(self, size: int = ...): ... |
| 254 |
def writable(self) -> bool: ... |
| 255 |
def writelines(self, lines: Iterable[bytes]): ... |
| 256 |
def read(self, size: int = ...) -> bytes: ... |
| 257 |
def readall(self) -> bytes: ... |
| 258 |
def readinto(self, b): ... |
| 259 |
def write(self, data: ByteString) -> int: ... |
| 260 |
def flush(self, flush_mode: int = ...) -> int: ... |
| 261 |
def tell(self) -> int: ... |
| 262 |
|
| 263 |
class ZstdCompressor(object): |
| 264 |
def __init__( |
| 265 |
self, |
| 266 |
level: int = ..., |
| 267 |
dict_data: Optional[ZstdCompressionDict] = ..., |
| 268 |
compression_params: Optional[ZstdCompressionParameters] = ..., |
| 269 |
write_checksum: Optional[bool] = ..., |
| 270 |
write_content_size: Optional[bool] = ..., |
| 271 |
write_dict_id: Optional[bool] = ..., |
| 272 |
threads: int = ..., |
| 273 |
): ... |
| 274 |
def memory_size(self) -> int: ... |
| 275 |
def compress(self, data: ByteString) -> bytes: ... |
| 276 |
def compressobj(self, size: int = ...) -> ZstdCompressionObj: ... |
| 277 |
def chunker( |
| 278 |
self, size: int = ..., chunk_size: int = ... |
| 279 |
) -> ZstdCompressionChunker: ... |
| 280 |
def copy_stream( |
| 281 |
self, |
| 282 |
ifh: IO[bytes], |
| 283 |
ofh: IO[bytes], |
| 284 |
size: int = ..., |
| 285 |
read_size: int = ..., |
| 286 |
write_size: int = ..., |
| 287 |
) -> Tuple[int, int]: ... |
| 288 |
def stream_reader( |
| 289 |
self, |
| 290 |
source: Union[IO[bytes], ByteString], |
| 291 |
size: int = ..., |
| 292 |
read_size: int = ..., |
| 293 |
*, |
| 294 |
closefd: bool = ..., |
| 295 |
) -> ZstdCompressionReader: ... |
| 296 |
def stream_writer( |
| 297 |
self, |
| 298 |
writer: IO[bytes], |
| 299 |
size: int = ..., |
| 300 |
write_size: int = ..., |
| 301 |
write_return_read: bool = ..., |
| 302 |
*, |
| 303 |
closefd: bool = ..., |
| 304 |
) -> ZstdCompressionWriter: ... |
| 305 |
def read_to_iter( |
| 306 |
self, |
| 307 |
reader: Union[IO[bytes], ByteString], |
| 308 |
size: int = ..., |
| 309 |
read_size: int = ..., |
| 310 |
write_size: int = ..., |
| 311 |
) -> Generator[bytes, None, None]: ... |
| 312 |
def frame_progression(self) -> Tuple[int, int, int]: ... |
| 313 |
def multi_compress_to_buffer( |
| 314 |
self, |
| 315 |
data: Union[ |
| 316 |
BufferWithSegments, |
| 317 |
BufferWithSegmentsCollection, |
| 318 |
List[ByteString], |
| 319 |
], |
| 320 |
threads: int = ..., |
| 321 |
) -> BufferWithSegmentsCollection: ... |
| 322 |
|
| 323 |
class ZstdDecompressionObj(object): |
| 324 |
def decompress(self, data: ByteString) -> bytes: ... |
| 325 |
def flush(self, length: int = ...) -> bytes: ... |
| 326 |
@property |
| 327 |
def unused_data(self) -> bytes: ... |
| 328 |
@property |
| 329 |
def unconsumed_tail(self) -> bytes: ... |
| 330 |
@property |
| 331 |
def eof(self) -> bool: ... |
| 332 |
|
| 333 |
class ZstdDecompressionReader(BinaryIO): |
| 334 |
def __enter__(self) -> "ZstdDecompressionReader": ... |
| 335 |
def __exit__(self, exc_type, exc_value, exc_tb): ... |
| 336 |
def readable(self) -> bool: ... |
| 337 |
def writable(self) -> bool: ... |
| 338 |
def seekable(self) -> bool: ... |
| 339 |
def readline(self, size: int = ...): ... |
| 340 |
def readlines(self, hint: int = ...): ... |
| 341 |
def write(self, data: ByteString): ... |
| 342 |
def writelines(self, lines: Iterable[bytes]): ... |
| 343 |
def isatty(self) -> bool: ... |
| 344 |
def flush(self): ... |
| 345 |
def close(self): ... |
| 346 |
@property |
| 347 |
def closed(self) -> bool: ... |
| 348 |
def tell(self) -> int: ... |
| 349 |
def readall(self) -> bytes: ... |
| 350 |
def __iter__(self): ... |
| 351 |
def __next__(self): ... |
| 352 |
def next(self): ... |
| 353 |
def read(self, size: int = ...) -> bytes: ... |
| 354 |
def readinto(self, b) -> int: ... |
| 355 |
def read1(self, size: int = ...) -> bytes: ... |
| 356 |
def readinto1(self, b) -> int: ... |
| 357 |
def seek(self, pos: int, whence: int = ...) -> int: ... |
| 358 |
|
| 359 |
class ZstdDecompressionWriter(BinaryIO): |
| 360 |
def __enter__(self) -> "ZstdDecompressionWriter": ... |
| 361 |
def __exit__(self, exc_type, exc_value, exc_tb): ... |
| 362 |
def memory_size(self) -> int: ... |
| 363 |
def close(self): ... |
| 364 |
@property |
| 365 |
def closed(self) -> bool: ... |
| 366 |
def fileno(self) -> int: ... |
| 367 |
def flush(self): ... |
| 368 |
def isatty(self) -> bool: ... |
| 369 |
def readable(self) -> bool: ... |
| 370 |
def readline(self, size: int = ...): ... |
| 371 |
def readlines(self, hint: int = ...): ... |
| 372 |
def seek(self, offset: int, whence: int = ...): ... |
| 373 |
def seekable(self) -> bool: ... |
| 374 |
def tell(self): ... |
| 375 |
def truncate(self, size: int = ...): ... |
| 376 |
def writable(self) -> bool: ... |
| 377 |
def writelines(self, lines: Iterable[bytes]): ... |
| 378 |
def read(self, size: int = ...): ... |
| 379 |
def readall(self): ... |
| 380 |
def readinto(self, b): ... |
| 381 |
def write(self, data: ByteString) -> int: ... |
| 382 |
|
| 383 |
class ZstdDecompressor(object): |
| 384 |
def __init__( |
| 385 |
self, |
| 386 |
dict_data: Optional[ZstdCompressionDict] = ..., |
| 387 |
max_window_size: int = ..., |
| 388 |
format: int = ..., |
| 389 |
): ... |
| 390 |
def memory_size(self) -> int: ... |
| 391 |
def decompress( |
| 392 |
self, |
| 393 |
data: ByteString, |
| 394 |
max_output_size: int = ..., |
| 395 |
read_across_frames: bool = ..., |
| 396 |
allow_extra_data: bool = ..., |
| 397 |
) -> bytes: ... |
| 398 |
def stream_reader( |
| 399 |
self, |
| 400 |
source: Union[IO[bytes], ByteString], |
| 401 |
read_size: int = ..., |
| 402 |
read_across_frames: bool = ..., |
| 403 |
*, |
| 404 |
closefd=False, |
| 405 |
) -> ZstdDecompressionReader: ... |
| 406 |
def decompressobj( |
| 407 |
self, write_size: int = ..., read_across_frames: bool = False |
| 408 |
) -> ZstdDecompressionObj: ... |
| 409 |
def read_to_iter( |
| 410 |
self, |
| 411 |
reader: Union[IO[bytes], ByteString], |
| 412 |
read_size: int = ..., |
| 413 |
write_size: int = ..., |
| 414 |
skip_bytes: int = ..., |
| 415 |
) -> Generator[bytes, None, None]: ... |
| 416 |
def stream_writer( |
| 417 |
self, |
| 418 |
writer: IO[bytes], |
| 419 |
write_size: int = ..., |
| 420 |
write_return_read: bool = ..., |
| 421 |
*, |
| 422 |
closefd: bool = ..., |
| 423 |
) -> ZstdDecompressionWriter: ... |
| 424 |
def copy_stream( |
| 425 |
self, |
| 426 |
ifh: IO[bytes], |
| 427 |
ofh: IO[bytes], |
| 428 |
read_size: int = ..., |
| 429 |
write_size: int = ..., |
| 430 |
) -> Tuple[int, int]: ... |
| 431 |
def decompress_content_dict_chain( |
| 432 |
self, frames: list[ByteString] |
| 433 |
) -> bytes: ... |
| 434 |
def multi_decompress_to_buffer( |
| 435 |
self, |
| 436 |
frames: Union[ |
| 437 |
BufferWithSegments, |
| 438 |
BufferWithSegmentsCollection, |
| 439 |
List[ByteString], |
| 440 |
], |
| 441 |
decompressed_sizes: ByteString = ..., |
| 442 |
threads: int = ..., |
| 443 |
) -> BufferWithSegmentsCollection: ... |
| 444 |
|
| 445 |
class FrameParameters(object): |
| 446 |
content_size: int |
| 447 |
window_size: int |
| 448 |
dict_id: int |
| 449 |
has_checksum: bool |
| 450 |
|
| 451 |
def estimate_decompression_context_size() -> int: ... |
| 452 |
def frame_content_size(data: ByteString) -> int: ... |
| 453 |
def frame_header_size(data: ByteString) -> int: ... |
| 454 |
def get_frame_parameters(data: ByteString) -> FrameParameters: ... |
| 455 |
def train_dictionary( |
| 456 |
dict_size: int, |
| 457 |
samples: list[ByteString], |
| 458 |
k: int = ..., |
| 459 |
d: int = ..., |
| 460 |
f: int = ..., |
| 461 |
split_point: float = ..., |
| 462 |
accel: int = ..., |
| 463 |
notifications: int = ..., |
| 464 |
dict_id: int = ..., |
| 465 |
level: int = ..., |
| 466 |
steps: int = ..., |
| 467 |
threads: int = ..., |
| 468 |
) -> ZstdCompressionDict: ... |
| 469 |
def open( |
| 470 |
filename: Union[bytes, str, os.PathLike, BinaryIO], |
| 471 |
mode: str = ..., |
| 472 |
cctx: Optional[ZstdCompressor] = ..., |
| 473 |
dctx: Optional[ZstdDecompressor] = ..., |
| 474 |
encoding: Optional[str] = ..., |
| 475 |
errors: Optional[str] = ..., |
| 476 |
newline: Optional[str] = ..., |
| 477 |
closefd: bool = ..., |
| 478 |
): ... |
| 479 |
def compress(data: ByteString, level: int = ...) -> bytes: ... |
| 480 |
def decompress(data: ByteString, max_output_size: int = ...) -> bytes: ... |