pyfastcdc 0.3.1__cp315-cp315-win_arm64.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.
- pyfastcdc/__init__.py +20 -0
- pyfastcdc/__init__.pyi +157 -0
- pyfastcdc/common.py +15 -0
- pyfastcdc/cy/__init__.py +7 -0
- pyfastcdc/cy/chunk.c +12156 -0
- pyfastcdc/cy/chunk.cp315-win_arm64.pyd +0 -0
- pyfastcdc/cy/chunk.pxd +10 -0
- pyfastcdc/cy/chunk.pyx +21 -0
- pyfastcdc/cy/constants.c +4880 -0
- pyfastcdc/cy/constants.cp315-win_arm64.pyd +0 -0
- pyfastcdc/cy/constants.pxd +5 -0
- pyfastcdc/cy/constants.pyx +164 -0
- pyfastcdc/cy/fastcdc.c +38644 -0
- pyfastcdc/cy/fastcdc.cp315-win_arm64.pyd +0 -0
- pyfastcdc/cy/fastcdc.pyx +305 -0
- pyfastcdc/py/__init__.py +7 -0
- pyfastcdc/py/chunk.py +11 -0
- pyfastcdc/py/constants.py +166 -0
- pyfastcdc/py/fastcdc.py +268 -0
- pyfastcdc/py.typed +0 -0
- pyfastcdc/utils.py +65 -0
- pyfastcdc-0.3.1.dist-info/METADATA +192 -0
- pyfastcdc-0.3.1.dist-info/RECORD +26 -0
- pyfastcdc-0.3.1.dist-info/WHEEL +5 -0
- pyfastcdc-0.3.1.dist-info/licenses/LICENSE +21 -0
- pyfastcdc-0.3.1.dist-info/top_level.txt +1 -0
pyfastcdc/__init__.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
__version__ = '0.3.1'
|
|
2
|
+
|
|
3
|
+
__all__ = [
|
|
4
|
+
'BinaryStreamReader',
|
|
5
|
+
'Chunk',
|
|
6
|
+
'FastCDC',
|
|
7
|
+
'NormalizedChunking',
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
from pyfastcdc.common import (
|
|
11
|
+
BinaryStreamReader,
|
|
12
|
+
NormalizedChunking,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
try:
|
|
16
|
+
from pyfastcdc.cy import FastCDC, Chunk
|
|
17
|
+
except ImportError:
|
|
18
|
+
from pyfastcdc.py import FastCDC, Chunk
|
|
19
|
+
import warnings
|
|
20
|
+
warnings.warn('Failed to import pyfastcdc cython extension, fallback to pure python implementation with is a lot slower.')
|
pyfastcdc/__init__.pyi
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import Optional, Union, Iterator
|
|
3
|
+
|
|
4
|
+
from typing_extensions import Protocol, Literal
|
|
5
|
+
|
|
6
|
+
__version__: str
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class _BinaryStreamReaderWithRead(Protocol):
|
|
10
|
+
def read(self, n: int) -> bytes: ...
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class _BinaryStreamReaderWithReadinto(Protocol):
|
|
14
|
+
def readinto(self, b: memoryview) -> int: ...
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
BinaryStreamReader = Union[_BinaryStreamReaderWithRead, _BinaryStreamReaderWithReadinto]
|
|
18
|
+
"""
|
|
19
|
+
A reader object that supports ``read()`` or ``readinto()`` methods.
|
|
20
|
+
``readinto()`` is preferred since it's faster than ``read()``
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
NormalizedChunking = Literal[0, 1, 2, 3]
|
|
24
|
+
"""
|
|
25
|
+
The normalized chunking parameter (NC) from the paper
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class FastCDC:
|
|
30
|
+
"""
|
|
31
|
+
The FastCDC 2020 chunker implementation
|
|
32
|
+
|
|
33
|
+
The object is not concurrent-proof, avoid using it concurrently
|
|
34
|
+
|
|
35
|
+
Paper: https://ieeexplore.ieee.org/document/9055082
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
def __init__(
|
|
39
|
+
self,
|
|
40
|
+
avg_size: int = 16384,
|
|
41
|
+
*,
|
|
42
|
+
min_size: Optional[int] = None,
|
|
43
|
+
max_size: Optional[int] = None,
|
|
44
|
+
normalized_chunking: NormalizedChunking = 1,
|
|
45
|
+
seed: int = 0,
|
|
46
|
+
):
|
|
47
|
+
"""
|
|
48
|
+
Construct a FastCDC instance for chunking. The instance can be reused for multiple chunking operations
|
|
49
|
+
|
|
50
|
+
:param avg_size: Specifies the average output chunk size. Suggested to be a power of 2.
|
|
51
|
+
Note: The actual output average chunk size is ``avg_size + min_size``,
|
|
52
|
+
as described in the paper section 3.4 "Cut-Point Skipping".
|
|
53
|
+
Default is 16384, should be within [256, 4194304]
|
|
54
|
+
:keyword min_size: Specifies the minimum constraint for the output chunk size.
|
|
55
|
+
Default is None, meaning ``avg_size // 4``. The value should be within [64, 1048576]
|
|
56
|
+
:keyword max_size: Specifies the maximum constraint for the output chunk size.
|
|
57
|
+
Default is None, meaning ``avg_size * 4``. The value should be within [1024, 16777216]
|
|
58
|
+
:keyword normalized_chunking: Defines the normalized chunking parameter (NC) from the paper.
|
|
59
|
+
Increasing the value will decrease the number of too-small / too-big chunks
|
|
60
|
+
and might also decrease the deduplication ratio if NC is set to too high.
|
|
61
|
+
The default NC value is 1, aligning with https://github.com/nlfiedler/fastcdc-rs.
|
|
62
|
+
See the paper for more details:
|
|
63
|
+
1. Section 3.5 "Normalized Chunking" on how NC works
|
|
64
|
+
2. Section 4.4 "Evaluation of Normalized Chunking" on evaluation results for different NC values
|
|
65
|
+
:keyword seed: Provides an optional seed value to alternate the gear table.
|
|
66
|
+
Default is 0, meaning using the default gear table from the C reference repository from the paper
|
|
67
|
+
(https://github.com/HIT-HSSL/destor/blob/master/src/chunking/fascdc_chunking.c)
|
|
68
|
+
will be used
|
|
69
|
+
"""
|
|
70
|
+
...
|
|
71
|
+
|
|
72
|
+
def cut_buf(self, buf: Union[bytes, bytearray, memoryview]) -> Iterator[Chunk]:
|
|
73
|
+
"""
|
|
74
|
+
Cut the given buffer with FastCDC algorithm
|
|
75
|
+
|
|
76
|
+
:param buf: The input buffer to be processed
|
|
77
|
+
:return: An iterator that yields ``Chunk`` objects
|
|
78
|
+
"""
|
|
79
|
+
...
|
|
80
|
+
|
|
81
|
+
def cut_file(self, file_path: Union[str, bytes, Path]) -> Iterator[Chunk]:
|
|
82
|
+
"""
|
|
83
|
+
Cut the given file with FastCDC algorithm
|
|
84
|
+
|
|
85
|
+
:param file_path: Path to the file to be processed. It should be a readable regular file
|
|
86
|
+
:return: An iterator that yields ``Chunk`` objects
|
|
87
|
+
"""
|
|
88
|
+
...
|
|
89
|
+
|
|
90
|
+
def cut_stream(self, stream: BinaryStreamReader) -> Iterator[Chunk]:
|
|
91
|
+
"""
|
|
92
|
+
Cut the given stream with FastCDC algorithm
|
|
93
|
+
|
|
94
|
+
.. caution::
|
|
95
|
+
|
|
96
|
+
All chunks generated by this method have their `.data` fields guaranteed to be valid before and only before the next chunk is generated
|
|
97
|
+
|
|
98
|
+
:param stream: The input stream to be processed. It needs to have any of the following methods:
|
|
99
|
+
|
|
100
|
+
* ``read(self, n: int) -> bytes``
|
|
101
|
+
* ``readinto(self, b: memoryview) -> int`` (preferred)
|
|
102
|
+
|
|
103
|
+
:return: An iterator that yields ``Chunk`` objects
|
|
104
|
+
"""
|
|
105
|
+
...
|
|
106
|
+
|
|
107
|
+
@property
|
|
108
|
+
def avg_size(self) -> int:
|
|
109
|
+
...
|
|
110
|
+
|
|
111
|
+
@property
|
|
112
|
+
def min_size(self) -> int:
|
|
113
|
+
...
|
|
114
|
+
|
|
115
|
+
@property
|
|
116
|
+
def max_size(self) -> int:
|
|
117
|
+
...
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
class Chunk:
|
|
121
|
+
"""
|
|
122
|
+
Represents a chunk of data generated by FastCDC algorithm
|
|
123
|
+
"""
|
|
124
|
+
|
|
125
|
+
offset: int
|
|
126
|
+
"""
|
|
127
|
+
The offset of the chunk in bytes from the beginning of the input
|
|
128
|
+
"""
|
|
129
|
+
|
|
130
|
+
length: int
|
|
131
|
+
"""
|
|
132
|
+
The length of the chunk in bytes. The same as ``len(data)``
|
|
133
|
+
"""
|
|
134
|
+
|
|
135
|
+
data: memoryview
|
|
136
|
+
"""
|
|
137
|
+
Memory view of the chunk data
|
|
138
|
+
|
|
139
|
+
.. caution::
|
|
140
|
+
|
|
141
|
+
For chunks generated from ``cut_stream()``, this memory view is only guaranteed to be valid before the next chunk is generated
|
|
142
|
+
|
|
143
|
+
.. note::
|
|
144
|
+
|
|
145
|
+
For chunks generated from ``cut_files()``, this memory view will be pointed to part of an mmap object of the input file,
|
|
146
|
+
which means the mmap object won't be released until all references to the generated chunk objects are released
|
|
147
|
+
"""
|
|
148
|
+
|
|
149
|
+
gear_hash: int
|
|
150
|
+
"""
|
|
151
|
+
FastCDC's gear hash for this chunk, range within uint64
|
|
152
|
+
|
|
153
|
+
You should not use this hash for actual data deduplication since it's not guaranteed to be high quality
|
|
154
|
+
"""
|
|
155
|
+
|
|
156
|
+
def __init__(self, offset: int, length: int, data: memoryview, gear_hash: int):
|
|
157
|
+
...
|
pyfastcdc/common.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from typing import Union
|
|
2
|
+
|
|
3
|
+
from typing_extensions import Literal, Protocol
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class _BinaryStreamReaderWithRead(Protocol):
|
|
7
|
+
def read(self, n: int) -> bytes: ...
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class _BinaryStreamReaderWithReadinto(Protocol):
|
|
11
|
+
def readinto(self, b: memoryview) -> int: ...
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
BinaryStreamReader = Union[_BinaryStreamReaderWithRead, _BinaryStreamReaderWithReadinto]
|
|
15
|
+
NormalizedChunking = Literal[0, 1, 2, 3]
|