mirror of
https://github.com/python/cpython.git
synced 2025-09-24 17:33:29 +00:00
[3.14] gh-132983: Clean-ups for `_zstd
` (GH-133670) (#133756)
gh-132983: Clean-ups for ``_zstd`` (GH-133670)
(cherry picked from commit c2a5d4b383
)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
This commit is contained in:
parent
bd6aad0ec4
commit
2df021d9dc
5 changed files with 106 additions and 175 deletions
|
@ -28,10 +28,16 @@ __all__ = (
|
|||
|
||||
import _zstd
|
||||
import enum
|
||||
from _zstd import *
|
||||
from _zstd import (ZstdCompressor, ZstdDecompressor, ZstdDict, ZstdError,
|
||||
get_frame_size, zstd_version)
|
||||
from compression.zstd._zstdfile import ZstdFile, open, _nbytes
|
||||
|
||||
COMPRESSION_LEVEL_DEFAULT = _zstd._compressionLevel_values[0]
|
||||
# zstd_version_number is (MAJOR * 100 * 100 + MINOR * 100 + RELEASE)
|
||||
zstd_version_info = (*divmod(_zstd.zstd_version_number // 100, 100),
|
||||
_zstd.zstd_version_number % 100)
|
||||
"""Version number of the runtime zstd library as a tuple of integers."""
|
||||
|
||||
COMPRESSION_LEVEL_DEFAULT = _zstd.ZSTD_CLEVEL_DEFAULT
|
||||
"""The default compression level for Zstandard, currently '3'."""
|
||||
|
||||
|
||||
|
@ -167,28 +173,28 @@ def decompress(data, zstd_dict=None, options=None):
|
|||
class CompressionParameter(enum.IntEnum):
|
||||
"""Compression parameters."""
|
||||
|
||||
compression_level = _zstd._ZSTD_c_compressionLevel
|
||||
window_log = _zstd._ZSTD_c_windowLog
|
||||
hash_log = _zstd._ZSTD_c_hashLog
|
||||
chain_log = _zstd._ZSTD_c_chainLog
|
||||
search_log = _zstd._ZSTD_c_searchLog
|
||||
min_match = _zstd._ZSTD_c_minMatch
|
||||
target_length = _zstd._ZSTD_c_targetLength
|
||||
strategy = _zstd._ZSTD_c_strategy
|
||||
compression_level = _zstd.ZSTD_c_compressionLevel
|
||||
window_log = _zstd.ZSTD_c_windowLog
|
||||
hash_log = _zstd.ZSTD_c_hashLog
|
||||
chain_log = _zstd.ZSTD_c_chainLog
|
||||
search_log = _zstd.ZSTD_c_searchLog
|
||||
min_match = _zstd.ZSTD_c_minMatch
|
||||
target_length = _zstd.ZSTD_c_targetLength
|
||||
strategy = _zstd.ZSTD_c_strategy
|
||||
|
||||
enable_long_distance_matching = _zstd._ZSTD_c_enableLongDistanceMatching
|
||||
ldm_hash_log = _zstd._ZSTD_c_ldmHashLog
|
||||
ldm_min_match = _zstd._ZSTD_c_ldmMinMatch
|
||||
ldm_bucket_size_log = _zstd._ZSTD_c_ldmBucketSizeLog
|
||||
ldm_hash_rate_log = _zstd._ZSTD_c_ldmHashRateLog
|
||||
enable_long_distance_matching = _zstd.ZSTD_c_enableLongDistanceMatching
|
||||
ldm_hash_log = _zstd.ZSTD_c_ldmHashLog
|
||||
ldm_min_match = _zstd.ZSTD_c_ldmMinMatch
|
||||
ldm_bucket_size_log = _zstd.ZSTD_c_ldmBucketSizeLog
|
||||
ldm_hash_rate_log = _zstd.ZSTD_c_ldmHashRateLog
|
||||
|
||||
content_size_flag = _zstd._ZSTD_c_contentSizeFlag
|
||||
checksum_flag = _zstd._ZSTD_c_checksumFlag
|
||||
dict_id_flag = _zstd._ZSTD_c_dictIDFlag
|
||||
content_size_flag = _zstd.ZSTD_c_contentSizeFlag
|
||||
checksum_flag = _zstd.ZSTD_c_checksumFlag
|
||||
dict_id_flag = _zstd.ZSTD_c_dictIDFlag
|
||||
|
||||
nb_workers = _zstd._ZSTD_c_nbWorkers
|
||||
job_size = _zstd._ZSTD_c_jobSize
|
||||
overlap_log = _zstd._ZSTD_c_overlapLog
|
||||
nb_workers = _zstd.ZSTD_c_nbWorkers
|
||||
job_size = _zstd.ZSTD_c_jobSize
|
||||
overlap_log = _zstd.ZSTD_c_overlapLog
|
||||
|
||||
def bounds(self):
|
||||
"""Return the (lower, upper) int bounds of a compression parameter.
|
||||
|
@ -201,7 +207,7 @@ class CompressionParameter(enum.IntEnum):
|
|||
class DecompressionParameter(enum.IntEnum):
|
||||
"""Decompression parameters."""
|
||||
|
||||
window_log_max = _zstd._ZSTD_d_windowLogMax
|
||||
window_log_max = _zstd.ZSTD_d_windowLogMax
|
||||
|
||||
def bounds(self):
|
||||
"""Return the (lower, upper) int bounds of a decompression parameter.
|
||||
|
@ -219,15 +225,15 @@ class Strategy(enum.IntEnum):
|
|||
the numeric value might change.
|
||||
"""
|
||||
|
||||
fast = _zstd._ZSTD_fast
|
||||
dfast = _zstd._ZSTD_dfast
|
||||
greedy = _zstd._ZSTD_greedy
|
||||
lazy = _zstd._ZSTD_lazy
|
||||
lazy2 = _zstd._ZSTD_lazy2
|
||||
btlazy2 = _zstd._ZSTD_btlazy2
|
||||
btopt = _zstd._ZSTD_btopt
|
||||
btultra = _zstd._ZSTD_btultra
|
||||
btultra2 = _zstd._ZSTD_btultra2
|
||||
fast = _zstd.ZSTD_fast
|
||||
dfast = _zstd.ZSTD_dfast
|
||||
greedy = _zstd.ZSTD_greedy
|
||||
lazy = _zstd.ZSTD_lazy
|
||||
lazy2 = _zstd.ZSTD_lazy2
|
||||
btlazy2 = _zstd.ZSTD_btlazy2
|
||||
btopt = _zstd.ZSTD_btopt
|
||||
btultra = _zstd.ZSTD_btultra
|
||||
btultra2 = _zstd.ZSTD_btultra2
|
||||
|
||||
|
||||
# Check validity of the CompressionParameter & DecompressionParameter types
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
import io
|
||||
from os import PathLike
|
||||
from _zstd import (ZstdCompressor, ZstdDecompressor, _ZSTD_DStreamSizes,
|
||||
ZstdError)
|
||||
from _zstd import (ZstdCompressor, ZstdDecompressor, ZstdError,
|
||||
ZSTD_DStreamOutSize)
|
||||
from compression._common import _streams
|
||||
|
||||
__all__ = ("ZstdFile", "open")
|
||||
|
||||
_ZSTD_DStreamOutSize = _ZSTD_DStreamSizes[1]
|
||||
|
||||
_MODE_CLOSED = 0
|
||||
_MODE_READ = 1
|
||||
_MODE_WRITE = 2
|
||||
|
@ -188,7 +186,7 @@ class ZstdFile(_streams.BaseStream):
|
|||
# Note this should *not* be io.DEFAULT_BUFFER_SIZE.
|
||||
# ZSTD_DStreamOutSize is the minimum amount to read guaranteeing
|
||||
# a full block is read.
|
||||
size = _ZSTD_DStreamOutSize
|
||||
size = ZSTD_DStreamOutSize
|
||||
return self._buffer.read1(size)
|
||||
|
||||
def readinto(self, b):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue