hdiffpatch 1.1.0__cp314-cp314-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hdiffpatch/__init__.py +80 -0
- hdiffpatch/_base_config.py +56 -0
- hdiffpatch/_bzip2_config.py +84 -0
- hdiffpatch/_c_extension.cp314-win_amd64.pyd +0 -0
- hdiffpatch/_c_extension.pyi +121 -0
- hdiffpatch/_lzma_config.py +213 -0
- hdiffpatch/_tamp_config.py +83 -0
- hdiffpatch/_zlib_config.py +177 -0
- hdiffpatch/_zstd_config.py +113 -0
- hdiffpatch/py.typed +0 -0
- hdiffpatch-1.1.0.dist-info/DELVEWHEEL +2 -0
- hdiffpatch-1.1.0.dist-info/METADATA +377 -0
- hdiffpatch-1.1.0.dist-info/RECORD +19 -0
- hdiffpatch-1.1.0.dist-info/WHEEL +5 -0
- hdiffpatch-1.1.0.dist-info/licenses/LICENSE +201 -0
- hdiffpatch-1.1.0.dist-info/scm_file_list.json +2282 -0
- hdiffpatch-1.1.0.dist-info/scm_version.json +8 -0
- hdiffpatch-1.1.0.dist-info/top_level.txt +1 -0
- hdiffpatch.libs/msvcp140-a4c2229bdc2a2a630acdc095b4d86008.dll +0 -0
hdiffpatch/__init__.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Don't manually change, let setuptools-scm handle it.
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# start delvewheel patch
|
|
5
|
+
def _delvewheel_patch_1_13_0():
|
|
6
|
+
import os
|
|
7
|
+
if os.path.isdir(libs_dir := os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, 'hdiffpatch.libs'))):
|
|
8
|
+
os.add_dll_directory(libs_dir)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
_delvewheel_patch_1_13_0()
|
|
12
|
+
del _delvewheel_patch_1_13_0
|
|
13
|
+
# end delvewheel patch
|
|
14
|
+
|
|
15
|
+
__version__ = "0.0.0"
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
# Types and constants
|
|
19
|
+
"COMPRESSION_BZIP2",
|
|
20
|
+
"COMPRESSION_LZMA",
|
|
21
|
+
"COMPRESSION_LZMA2",
|
|
22
|
+
"COMPRESSION_NONE",
|
|
23
|
+
"COMPRESSION_TAMP",
|
|
24
|
+
"COMPRESSION_ZLIB",
|
|
25
|
+
"COMPRESSION_ZSTD",
|
|
26
|
+
"CompressionType",
|
|
27
|
+
# Exceptions
|
|
28
|
+
"HDiffPatchError",
|
|
29
|
+
# Core functions
|
|
30
|
+
"diff",
|
|
31
|
+
"apply",
|
|
32
|
+
"recompress",
|
|
33
|
+
# Configuration classes
|
|
34
|
+
"BaseConfig",
|
|
35
|
+
"BZip2Config",
|
|
36
|
+
"ZlibConfig",
|
|
37
|
+
"ZlibStrategy",
|
|
38
|
+
"LzmaConfig",
|
|
39
|
+
"Lzma2Config",
|
|
40
|
+
"TampConfig",
|
|
41
|
+
"ZStdConfig",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
from ._base_config import (
|
|
45
|
+
BaseConfig,
|
|
46
|
+
)
|
|
47
|
+
from ._bzip2_config import (
|
|
48
|
+
BZip2Config,
|
|
49
|
+
)
|
|
50
|
+
from ._c_extension import (
|
|
51
|
+
# Types and constants
|
|
52
|
+
COMPRESSION_BZIP2,
|
|
53
|
+
COMPRESSION_LZMA,
|
|
54
|
+
COMPRESSION_LZMA2,
|
|
55
|
+
COMPRESSION_NONE,
|
|
56
|
+
COMPRESSION_TAMP,
|
|
57
|
+
COMPRESSION_ZLIB,
|
|
58
|
+
COMPRESSION_ZSTD,
|
|
59
|
+
CompressionType,
|
|
60
|
+
# Exceptions
|
|
61
|
+
HDiffPatchError,
|
|
62
|
+
# Core functions
|
|
63
|
+
apply,
|
|
64
|
+
diff,
|
|
65
|
+
recompress,
|
|
66
|
+
)
|
|
67
|
+
from ._lzma_config import (
|
|
68
|
+
Lzma2Config,
|
|
69
|
+
LzmaConfig,
|
|
70
|
+
)
|
|
71
|
+
from ._tamp_config import (
|
|
72
|
+
TampConfig,
|
|
73
|
+
)
|
|
74
|
+
from ._zlib_config import (
|
|
75
|
+
ZlibConfig,
|
|
76
|
+
ZlibStrategy,
|
|
77
|
+
)
|
|
78
|
+
from ._zstd_config import (
|
|
79
|
+
ZStdConfig,
|
|
80
|
+
)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""Base configuration class for compression configs."""
|
|
2
|
+
|
|
3
|
+
import attrs
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@attrs.frozen
|
|
7
|
+
class BaseConfig:
|
|
8
|
+
"""Base class for all compression configuration classes.
|
|
9
|
+
|
|
10
|
+
This class provides common functionality for all compression configurations,
|
|
11
|
+
including standardized classmethods for creating common configuration presets.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
@classmethod
|
|
15
|
+
def fast(cls):
|
|
16
|
+
"""Create a config optimized for speed.
|
|
17
|
+
|
|
18
|
+
Returns
|
|
19
|
+
-------
|
|
20
|
+
BaseConfig
|
|
21
|
+
Configuration optimized for speed
|
|
22
|
+
"""
|
|
23
|
+
raise NotImplementedError(f"{cls.__name__} does not implement fast() classmethod")
|
|
24
|
+
|
|
25
|
+
@classmethod
|
|
26
|
+
def balanced(cls):
|
|
27
|
+
"""Create a config with balanced speed/compression.
|
|
28
|
+
|
|
29
|
+
Returns
|
|
30
|
+
-------
|
|
31
|
+
BaseConfig
|
|
32
|
+
Configuration with balanced speed/compression tradeoff
|
|
33
|
+
"""
|
|
34
|
+
raise NotImplementedError(f"{cls.__name__} does not implement balanced() classmethod")
|
|
35
|
+
|
|
36
|
+
@classmethod
|
|
37
|
+
def best_compression(cls):
|
|
38
|
+
"""Create a config optimized for best compression.
|
|
39
|
+
|
|
40
|
+
Returns
|
|
41
|
+
-------
|
|
42
|
+
BaseConfig
|
|
43
|
+
Configuration optimized for best compression
|
|
44
|
+
"""
|
|
45
|
+
raise NotImplementedError(f"{cls.__name__} does not implement best_compression() classmethod")
|
|
46
|
+
|
|
47
|
+
@classmethod
|
|
48
|
+
def minimal_memory(cls):
|
|
49
|
+
"""Create a config with minimal memory usage.
|
|
50
|
+
|
|
51
|
+
Returns
|
|
52
|
+
-------
|
|
53
|
+
BaseConfig
|
|
54
|
+
Configuration with minimal memory usage
|
|
55
|
+
"""
|
|
56
|
+
raise NotImplementedError(f"{cls.__name__} does not implement minimal_memory() classmethod")
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""BZip2Config class for configuring bzip2 compression parameters."""
|
|
2
|
+
|
|
3
|
+
import attrs
|
|
4
|
+
|
|
5
|
+
from ._base_config import BaseConfig
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@attrs.frozen
|
|
9
|
+
class BZip2Config(BaseConfig):
|
|
10
|
+
"""Configuration for bzip2 compression parameters.
|
|
11
|
+
|
|
12
|
+
This class allows control over bzip2 compression behavior via the
|
|
13
|
+
compression level, which trades speed for compression ratio and
|
|
14
|
+
memory usage.
|
|
15
|
+
|
|
16
|
+
Parameters
|
|
17
|
+
----------
|
|
18
|
+
level : int, default=9
|
|
19
|
+
Compression level (1-9). Higher values give better
|
|
20
|
+
compression but are slower. 1 = fastest, 9 = best compression.
|
|
21
|
+
|
|
22
|
+
Examples
|
|
23
|
+
--------
|
|
24
|
+
Fast compression
|
|
25
|
+
|
|
26
|
+
>>> config = BZip2Config(level=1)
|
|
27
|
+
|
|
28
|
+
Best compression
|
|
29
|
+
|
|
30
|
+
>>> config = BZip2Config(level=9)
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
level: int = attrs.field(
|
|
34
|
+
default=9,
|
|
35
|
+
validator=attrs.validators.and_(
|
|
36
|
+
attrs.validators.instance_of(int),
|
|
37
|
+
attrs.validators.ge(1),
|
|
38
|
+
attrs.validators.le(9),
|
|
39
|
+
),
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
@classmethod
|
|
43
|
+
def fast(cls) -> "BZip2Config":
|
|
44
|
+
"""Create a BZip2Config optimized for speed.
|
|
45
|
+
|
|
46
|
+
Returns
|
|
47
|
+
-------
|
|
48
|
+
BZip2Config
|
|
49
|
+
Configuration optimized for speed
|
|
50
|
+
"""
|
|
51
|
+
return cls(level=1)
|
|
52
|
+
|
|
53
|
+
@classmethod
|
|
54
|
+
def balanced(cls) -> "BZip2Config":
|
|
55
|
+
"""Create a BZip2Config with balanced speed/compression.
|
|
56
|
+
|
|
57
|
+
Returns
|
|
58
|
+
-------
|
|
59
|
+
BZip2Config
|
|
60
|
+
Configuration with balanced speed/compression tradeoff
|
|
61
|
+
"""
|
|
62
|
+
return cls(level=6)
|
|
63
|
+
|
|
64
|
+
@classmethod
|
|
65
|
+
def best_compression(cls) -> "BZip2Config":
|
|
66
|
+
"""Create a BZip2Config optimized for best compression.
|
|
67
|
+
|
|
68
|
+
Returns
|
|
69
|
+
-------
|
|
70
|
+
BZip2Config
|
|
71
|
+
Configuration optimized for best compression
|
|
72
|
+
"""
|
|
73
|
+
return cls(level=9)
|
|
74
|
+
|
|
75
|
+
@classmethod
|
|
76
|
+
def minimal_memory(cls) -> "BZip2Config":
|
|
77
|
+
"""Create a BZip2Config with minimal memory usage.
|
|
78
|
+
|
|
79
|
+
Returns
|
|
80
|
+
-------
|
|
81
|
+
BZip2Config
|
|
82
|
+
Configuration with minimal memory usage
|
|
83
|
+
"""
|
|
84
|
+
return cls(level=1)
|
|
Binary file
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
from typing import TYPE_CHECKING, Literal, Union
|
|
2
|
+
|
|
3
|
+
if TYPE_CHECKING:
|
|
4
|
+
from ._base_config import BaseConfig
|
|
5
|
+
|
|
6
|
+
CompressionType = Literal["none", "zlib", "lzma", "lzma2", "zstd", "bzip2", "tamp"]
|
|
7
|
+
|
|
8
|
+
# Constants for convenience
|
|
9
|
+
COMPRESSION_NONE: CompressionType = "none"
|
|
10
|
+
COMPRESSION_ZLIB: CompressionType = "zlib"
|
|
11
|
+
COMPRESSION_LZMA: CompressionType = "lzma"
|
|
12
|
+
COMPRESSION_LZMA2: CompressionType = "lzma2"
|
|
13
|
+
COMPRESSION_ZSTD: CompressionType = "zstd"
|
|
14
|
+
COMPRESSION_BZIP2: CompressionType = "bzip2"
|
|
15
|
+
COMPRESSION_TAMP: CompressionType = "tamp"
|
|
16
|
+
|
|
17
|
+
class HDiffPatchError(Exception):
|
|
18
|
+
"""Base exception for HDiffPatch operations."""
|
|
19
|
+
|
|
20
|
+
...
|
|
21
|
+
|
|
22
|
+
def diff(
|
|
23
|
+
old_data: bytes,
|
|
24
|
+
new_data: bytes,
|
|
25
|
+
compression: Union[CompressionType, BaseConfig, None] = None,
|
|
26
|
+
*,
|
|
27
|
+
validate: bool = True,
|
|
28
|
+
) -> bytes:
|
|
29
|
+
"""Create a binary diff between old and new data using HDiffPatch.
|
|
30
|
+
|
|
31
|
+
Parameters
|
|
32
|
+
----------
|
|
33
|
+
old_data : bytes
|
|
34
|
+
The original data
|
|
35
|
+
new_data : bytes
|
|
36
|
+
The new data to diff against
|
|
37
|
+
compression : CompressionType, BaseConfig, or None, default=None
|
|
38
|
+
Compression algorithm to use
|
|
39
|
+
validate : bool, default=True
|
|
40
|
+
If True, validates that applying the diff to old_data produces new_data
|
|
41
|
+
|
|
42
|
+
Returns
|
|
43
|
+
-------
|
|
44
|
+
bytes
|
|
45
|
+
The diff data as bytes
|
|
46
|
+
|
|
47
|
+
Raises
|
|
48
|
+
------
|
|
49
|
+
TypeError
|
|
50
|
+
If old_data or new_data are not bytes
|
|
51
|
+
HDiffPatchError
|
|
52
|
+
If diff creation fails or roundtrip validation fails
|
|
53
|
+
"""
|
|
54
|
+
...
|
|
55
|
+
|
|
56
|
+
def apply(
|
|
57
|
+
old_data: bytes,
|
|
58
|
+
diff_data: bytes,
|
|
59
|
+
) -> bytes:
|
|
60
|
+
"""Apply a patch to old data to produce new data using HDiffPatch.
|
|
61
|
+
|
|
62
|
+
The compression type is automatically detected from the diff data header.
|
|
63
|
+
|
|
64
|
+
Parameters
|
|
65
|
+
----------
|
|
66
|
+
old_data : bytes
|
|
67
|
+
The original data
|
|
68
|
+
diff_data : bytes
|
|
69
|
+
The diff/patch data
|
|
70
|
+
|
|
71
|
+
Returns
|
|
72
|
+
-------
|
|
73
|
+
bytes
|
|
74
|
+
The patched data as bytes
|
|
75
|
+
|
|
76
|
+
Raises
|
|
77
|
+
------
|
|
78
|
+
TypeError
|
|
79
|
+
If old_data or diff_data are not bytes
|
|
80
|
+
HDiffPatchError
|
|
81
|
+
If patch application fails
|
|
82
|
+
MemoryError
|
|
83
|
+
If memory allocation fails
|
|
84
|
+
"""
|
|
85
|
+
...
|
|
86
|
+
|
|
87
|
+
def recompress(
|
|
88
|
+
diff_data: bytes,
|
|
89
|
+
compression: Union[CompressionType, BaseConfig, None] = None,
|
|
90
|
+
) -> bytes:
|
|
91
|
+
"""Recompress a diff with a different compression algorithm.
|
|
92
|
+
|
|
93
|
+
This function can recompress diffs in HDiffPatch's compressed diff format, which includes
|
|
94
|
+
diffs created by hdiffz (both compressed and uncompressed). The input format is automatically
|
|
95
|
+
detected and the diff is recompressed with the specified compression algorithm.
|
|
96
|
+
|
|
97
|
+
Supports both single-compressed and regular compressed diff formats. Works with diffs
|
|
98
|
+
created by hdiffz tool and the hdiffpatch.diff() function when explicit compression is used.
|
|
99
|
+
|
|
100
|
+
Parameters
|
|
101
|
+
----------
|
|
102
|
+
diff_data : bytes
|
|
103
|
+
The diff data to recompress
|
|
104
|
+
compression : CompressionType, BaseConfig, or None, default=None
|
|
105
|
+
Target compression algorithm to use
|
|
106
|
+
|
|
107
|
+
Returns
|
|
108
|
+
-------
|
|
109
|
+
bytes
|
|
110
|
+
The recompressed diff data
|
|
111
|
+
|
|
112
|
+
Raises
|
|
113
|
+
------
|
|
114
|
+
TypeError
|
|
115
|
+
If diff_data is not bytes
|
|
116
|
+
HDiffPatchError
|
|
117
|
+
If recompression fails or input format is unsupported
|
|
118
|
+
ValueError
|
|
119
|
+
If compression type is invalid
|
|
120
|
+
"""
|
|
121
|
+
...
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"""LzmaConfig and Lzma2Config classes for configuring LZMA compression parameters."""
|
|
2
|
+
|
|
3
|
+
import attrs
|
|
4
|
+
|
|
5
|
+
from ._base_config import BaseConfig
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@attrs.frozen
|
|
9
|
+
class LzmaConfig(BaseConfig):
|
|
10
|
+
"""Configuration for LZMA compression parameters.
|
|
11
|
+
|
|
12
|
+
This class allows fine-grained control over LZMA compression behavior,
|
|
13
|
+
including compression level, dictionary size, and thread usage.
|
|
14
|
+
|
|
15
|
+
Parameters
|
|
16
|
+
----------
|
|
17
|
+
level : int, default=9
|
|
18
|
+
Compression level (0-9). Higher values give better
|
|
19
|
+
compression but are slower. 0 = no compression, 9 = best compression.
|
|
20
|
+
window : int, default=23
|
|
21
|
+
Window size as log2. Must be between 12 and 30.
|
|
22
|
+
Larger windows give better compression but use more memory.
|
|
23
|
+
(23 = 8MB window)
|
|
24
|
+
thread_num : int, default=1
|
|
25
|
+
Number of threads (1-2). LZMA supports up to 2 threads.
|
|
26
|
+
|
|
27
|
+
Examples
|
|
28
|
+
--------
|
|
29
|
+
Fast compression with minimal memory usage (4KB window)
|
|
30
|
+
|
|
31
|
+
>>> config = LzmaConfig(level=1, window=12, thread_num=1)
|
|
32
|
+
|
|
33
|
+
Best compression for large files (32MB window)
|
|
34
|
+
|
|
35
|
+
>>> config = LzmaConfig(level=9, window=25, thread_num=2)
|
|
36
|
+
|
|
37
|
+
Balanced compression (8MB window)
|
|
38
|
+
|
|
39
|
+
>>> config = LzmaConfig(level=6, window=23, thread_num=1)
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
level: int = attrs.field(
|
|
43
|
+
default=9,
|
|
44
|
+
validator=attrs.validators.and_(
|
|
45
|
+
attrs.validators.instance_of(int),
|
|
46
|
+
attrs.validators.ge(0),
|
|
47
|
+
attrs.validators.le(9),
|
|
48
|
+
),
|
|
49
|
+
)
|
|
50
|
+
window: int = attrs.field(
|
|
51
|
+
default=23, # 8MB (2^23)
|
|
52
|
+
validator=attrs.validators.and_(
|
|
53
|
+
attrs.validators.instance_of(int),
|
|
54
|
+
attrs.validators.ge(12),
|
|
55
|
+
attrs.validators.le(30),
|
|
56
|
+
),
|
|
57
|
+
)
|
|
58
|
+
thread_num: int = attrs.field(
|
|
59
|
+
default=1,
|
|
60
|
+
validator=attrs.validators.and_(
|
|
61
|
+
attrs.validators.instance_of(int),
|
|
62
|
+
attrs.validators.ge(1),
|
|
63
|
+
attrs.validators.le(2),
|
|
64
|
+
),
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
@classmethod
|
|
68
|
+
def fast(cls) -> "LzmaConfig":
|
|
69
|
+
"""Create an LzmaConfig optimized for speed.
|
|
70
|
+
|
|
71
|
+
Returns
|
|
72
|
+
-------
|
|
73
|
+
LzmaConfig
|
|
74
|
+
Configuration optimized for speed
|
|
75
|
+
"""
|
|
76
|
+
return cls(level=1, window=12, thread_num=1)
|
|
77
|
+
|
|
78
|
+
@classmethod
|
|
79
|
+
def balanced(cls) -> "LzmaConfig":
|
|
80
|
+
"""Create an LzmaConfig with balanced speed/compression.
|
|
81
|
+
|
|
82
|
+
Returns
|
|
83
|
+
-------
|
|
84
|
+
LzmaConfig
|
|
85
|
+
Configuration with balanced speed/compression tradeoff
|
|
86
|
+
"""
|
|
87
|
+
return cls(level=6, window=23, thread_num=1)
|
|
88
|
+
|
|
89
|
+
@classmethod
|
|
90
|
+
def best_compression(cls) -> "LzmaConfig":
|
|
91
|
+
"""Create an LzmaConfig optimized for best compression.
|
|
92
|
+
|
|
93
|
+
Returns
|
|
94
|
+
-------
|
|
95
|
+
LzmaConfig
|
|
96
|
+
Configuration optimized for best compression
|
|
97
|
+
"""
|
|
98
|
+
return cls(level=9, window=25, thread_num=2)
|
|
99
|
+
|
|
100
|
+
@classmethod
|
|
101
|
+
def minimal_memory(cls) -> "LzmaConfig":
|
|
102
|
+
"""Create an LzmaConfig with minimal memory usage.
|
|
103
|
+
|
|
104
|
+
Returns
|
|
105
|
+
-------
|
|
106
|
+
LzmaConfig
|
|
107
|
+
Configuration with minimal memory usage
|
|
108
|
+
"""
|
|
109
|
+
return cls(level=6, window=12, thread_num=1)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
@attrs.frozen
|
|
113
|
+
class Lzma2Config(BaseConfig):
|
|
114
|
+
"""Configuration for LZMA2 compression parameters.
|
|
115
|
+
|
|
116
|
+
This class allows fine-grained control over LZMA2 compression behavior,
|
|
117
|
+
including compression level, dictionary size, and thread usage.
|
|
118
|
+
|
|
119
|
+
Parameters
|
|
120
|
+
----------
|
|
121
|
+
level : int, default=9
|
|
122
|
+
Compression level (0-9). Higher values give better
|
|
123
|
+
compression but are slower. 0 = no compression, 9 = best compression.
|
|
124
|
+
window : int, default=23
|
|
125
|
+
Window size as log2. Must be between 12 and 30.
|
|
126
|
+
Larger windows give better compression but use more memory.
|
|
127
|
+
(23 = 8MB window)
|
|
128
|
+
thread_num : int, default=1
|
|
129
|
+
Number of threads (1-64). LZMA2 supports up to 64 threads.
|
|
130
|
+
|
|
131
|
+
Examples
|
|
132
|
+
--------
|
|
133
|
+
Fast compression with minimal memory usage (4KB window)
|
|
134
|
+
|
|
135
|
+
>>> config = Lzma2Config(level=1, window=12, thread_num=1)
|
|
136
|
+
|
|
137
|
+
Best compression for large files with multiple threads (32MB window)
|
|
138
|
+
|
|
139
|
+
>>> config = Lzma2Config(level=9, window=25, thread_num=8)
|
|
140
|
+
|
|
141
|
+
Balanced compression with moderate threading (8MB window)
|
|
142
|
+
|
|
143
|
+
>>> config = Lzma2Config(level=6, window=23, thread_num=4)
|
|
144
|
+
"""
|
|
145
|
+
|
|
146
|
+
level: int = attrs.field(
|
|
147
|
+
default=9,
|
|
148
|
+
validator=attrs.validators.and_(
|
|
149
|
+
attrs.validators.instance_of(int),
|
|
150
|
+
attrs.validators.ge(0),
|
|
151
|
+
attrs.validators.le(9),
|
|
152
|
+
),
|
|
153
|
+
)
|
|
154
|
+
window: int = attrs.field(
|
|
155
|
+
default=23, # 8MB (2^23)
|
|
156
|
+
validator=attrs.validators.and_(
|
|
157
|
+
attrs.validators.instance_of(int),
|
|
158
|
+
attrs.validators.ge(12),
|
|
159
|
+
attrs.validators.le(30),
|
|
160
|
+
),
|
|
161
|
+
)
|
|
162
|
+
thread_num: int = attrs.field(
|
|
163
|
+
default=1,
|
|
164
|
+
validator=attrs.validators.and_(
|
|
165
|
+
attrs.validators.instance_of(int),
|
|
166
|
+
attrs.validators.ge(1),
|
|
167
|
+
attrs.validators.le(64),
|
|
168
|
+
),
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
@classmethod
|
|
172
|
+
def fast(cls) -> "Lzma2Config":
|
|
173
|
+
"""Create an Lzma2Config optimized for speed.
|
|
174
|
+
|
|
175
|
+
Returns
|
|
176
|
+
-------
|
|
177
|
+
Lzma2Config
|
|
178
|
+
Configuration optimized for speed
|
|
179
|
+
"""
|
|
180
|
+
return cls(level=1, window=12, thread_num=1)
|
|
181
|
+
|
|
182
|
+
@classmethod
|
|
183
|
+
def balanced(cls) -> "Lzma2Config":
|
|
184
|
+
"""Create an Lzma2Config with balanced speed/compression.
|
|
185
|
+
|
|
186
|
+
Returns
|
|
187
|
+
-------
|
|
188
|
+
Lzma2Config
|
|
189
|
+
Configuration with balanced speed/compression tradeoff
|
|
190
|
+
"""
|
|
191
|
+
return cls(level=6, window=23, thread_num=4)
|
|
192
|
+
|
|
193
|
+
@classmethod
|
|
194
|
+
def best_compression(cls) -> "Lzma2Config":
|
|
195
|
+
"""Create an Lzma2Config optimized for best compression.
|
|
196
|
+
|
|
197
|
+
Returns
|
|
198
|
+
-------
|
|
199
|
+
Lzma2Config
|
|
200
|
+
Configuration optimized for best compression
|
|
201
|
+
"""
|
|
202
|
+
return cls(level=9, window=25, thread_num=8)
|
|
203
|
+
|
|
204
|
+
@classmethod
|
|
205
|
+
def minimal_memory(cls) -> "Lzma2Config":
|
|
206
|
+
"""Create an Lzma2Config with minimal memory usage.
|
|
207
|
+
|
|
208
|
+
Returns
|
|
209
|
+
-------
|
|
210
|
+
Lzma2Config
|
|
211
|
+
Configuration with minimal memory usage
|
|
212
|
+
"""
|
|
213
|
+
return cls(level=6, window=12, thread_num=1)
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""TampConfig class for configuring tamp compression parameters."""
|
|
2
|
+
|
|
3
|
+
import attrs
|
|
4
|
+
|
|
5
|
+
from ._base_config import BaseConfig
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@attrs.frozen
|
|
9
|
+
class TampConfig(BaseConfig):
|
|
10
|
+
"""Configuration for tamp compression parameters.
|
|
11
|
+
|
|
12
|
+
This class allows control over tamp compression behavior,
|
|
13
|
+
including window size and custom dictionary support.
|
|
14
|
+
|
|
15
|
+
Parameters
|
|
16
|
+
----------
|
|
17
|
+
window : int, default=10
|
|
18
|
+
Window size as power of 2 (8-15). Larger windows give
|
|
19
|
+
better compression but use more memory. (1KB window)
|
|
20
|
+
|
|
21
|
+
Examples
|
|
22
|
+
--------
|
|
23
|
+
Default configuration
|
|
24
|
+
|
|
25
|
+
>>> config = TampConfig()
|
|
26
|
+
|
|
27
|
+
Custom window size
|
|
28
|
+
|
|
29
|
+
>>> config = TampConfig(window=12)
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
window: int = attrs.field(
|
|
33
|
+
default=10,
|
|
34
|
+
validator=attrs.validators.and_(
|
|
35
|
+
attrs.validators.instance_of(int),
|
|
36
|
+
attrs.validators.ge(8),
|
|
37
|
+
attrs.validators.le(15),
|
|
38
|
+
),
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
@classmethod
|
|
42
|
+
def fast(cls) -> "TampConfig":
|
|
43
|
+
"""Create a TampConfig optimized for speed.
|
|
44
|
+
|
|
45
|
+
Returns
|
|
46
|
+
-------
|
|
47
|
+
TampConfig
|
|
48
|
+
Configuration optimized for speed
|
|
49
|
+
"""
|
|
50
|
+
return cls(window=8)
|
|
51
|
+
|
|
52
|
+
@classmethod
|
|
53
|
+
def balanced(cls) -> "TampConfig":
|
|
54
|
+
"""Create a TampConfig with balanced speed/compression.
|
|
55
|
+
|
|
56
|
+
Returns
|
|
57
|
+
-------
|
|
58
|
+
TampConfig
|
|
59
|
+
Configuration with balanced speed/compression tradeoff
|
|
60
|
+
"""
|
|
61
|
+
return cls(window=10)
|
|
62
|
+
|
|
63
|
+
@classmethod
|
|
64
|
+
def best_compression(cls) -> "TampConfig":
|
|
65
|
+
"""Create a TampConfig optimized for best compression.
|
|
66
|
+
|
|
67
|
+
Returns
|
|
68
|
+
-------
|
|
69
|
+
TampConfig
|
|
70
|
+
Configuration optimized for best compression
|
|
71
|
+
"""
|
|
72
|
+
return cls(window=15)
|
|
73
|
+
|
|
74
|
+
@classmethod
|
|
75
|
+
def minimal_memory(cls) -> "TampConfig":
|
|
76
|
+
"""Create a TampConfig with minimal memory usage.
|
|
77
|
+
|
|
78
|
+
Returns
|
|
79
|
+
-------
|
|
80
|
+
TampConfig
|
|
81
|
+
Configuration with minimal memory usage
|
|
82
|
+
"""
|
|
83
|
+
return cls(window=8)
|