pybase16384 0.3.5__cp310-cp310-win32.whl → 0.3.6__cp310-cp310-win32.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.
Potentially problematic release.
This version of pybase16384 might be problematic. Click here for more details.
- pybase16384/__init__.py +19 -1
- pybase16384/backends/cffi/__init__.py +69 -20
- pybase16384/backends/cffi/_core.pyd +0 -0
- pybase16384/backends/cffi/build.py +36 -0
- pybase16384/backends/cython/__init__.py +9 -0
- pybase16384/backends/cython/_core.c +3070 -769
- pybase16384/backends/cython/_core.pyd +0 -0
- pybase16384/backends/cython/_core.pyx +103 -6
- pybase16384/backends/cython/base16384.pxd +41 -0
- {pybase16384-0.3.5.dist-info → pybase16384-0.3.6.dist-info}/METADATA +1 -1
- pybase16384-0.3.6.dist-info/RECORD +16 -0
- pybase16384-0.3.5.dist-info/RECORD +0 -16
- {pybase16384-0.3.5.dist-info → pybase16384-0.3.6.dist-info}/LICENSE +0 -0
- {pybase16384-0.3.5.dist-info → pybase16384-0.3.6.dist-info}/WHEEL +0 -0
- {pybase16384-0.3.5.dist-info → pybase16384-0.3.6.dist-info}/top_level.txt +0 -0
pybase16384/__init__.py
CHANGED
|
@@ -17,38 +17,56 @@ def _should_use_cffi() -> bool:
|
|
|
17
17
|
|
|
18
18
|
if not _should_use_cffi():
|
|
19
19
|
from pybase16384.backends.cython import (
|
|
20
|
+
DECBUFSZ,
|
|
21
|
+
ENCBUFSZ,
|
|
22
|
+
FLAG_NOHEADER,
|
|
23
|
+
FLAG_SUM_CHECK_ON_REMAIN,
|
|
24
|
+
SIMPLE_SUM_INIT_VALUE,
|
|
20
25
|
_decode,
|
|
21
26
|
_decode_into,
|
|
22
27
|
_encode,
|
|
23
28
|
_encode_into,
|
|
24
29
|
decode_fd,
|
|
30
|
+
decode_fd_detailed,
|
|
25
31
|
decode_file,
|
|
26
32
|
decode_len,
|
|
27
33
|
decode_local_file,
|
|
34
|
+
decode_local_file_detailed,
|
|
28
35
|
encode_fd,
|
|
36
|
+
encode_fd_detailed,
|
|
29
37
|
encode_file,
|
|
30
38
|
encode_len,
|
|
31
39
|
encode_local_file,
|
|
40
|
+
encode_local_file_detailed,
|
|
32
41
|
is_64bits,
|
|
33
42
|
)
|
|
34
43
|
else:
|
|
35
44
|
from pybase16384.backends.cffi import (
|
|
45
|
+
DECBUFSZ,
|
|
46
|
+
ENCBUFSZ,
|
|
47
|
+
FLAG_NOHEADER,
|
|
48
|
+
FLAG_SUM_CHECK_ON_REMAIN,
|
|
49
|
+
SIMPLE_SUM_INIT_VALUE,
|
|
36
50
|
_decode,
|
|
37
51
|
_decode_into,
|
|
38
52
|
_encode,
|
|
39
53
|
_encode_into,
|
|
40
54
|
decode_fd,
|
|
55
|
+
decode_fd_detailed,
|
|
41
56
|
decode_file,
|
|
42
57
|
decode_len,
|
|
43
58
|
decode_local_file,
|
|
59
|
+
decode_local_file_detailed,
|
|
44
60
|
encode_fd,
|
|
61
|
+
encode_fd_detailed,
|
|
45
62
|
encode_file,
|
|
46
63
|
encode_len,
|
|
47
64
|
encode_local_file,
|
|
65
|
+
encode_local_file_detailed,
|
|
48
66
|
is_64bits,
|
|
49
67
|
)
|
|
50
68
|
|
|
51
|
-
__version__ = "0.3.
|
|
69
|
+
__version__ = "0.3.6"
|
|
52
70
|
|
|
53
71
|
|
|
54
72
|
def encode(data: bytes) -> bytes:
|
|
@@ -11,6 +11,12 @@ __version__ = "0.1.0"
|
|
|
11
11
|
encode_len = lib.base16384_encode_len
|
|
12
12
|
decode_len = lib.base16384_decode_len
|
|
13
13
|
|
|
14
|
+
ENCBUFSZ = lib.get_encsize()
|
|
15
|
+
DECBUFSZ = lib.get_decsize()
|
|
16
|
+
FLAG_NOHEADER = lib.BASE16384_FLAG_NOHEADER_()
|
|
17
|
+
FLAG_SUM_CHECK_ON_REMAIN = lib.BASE16384_FLAG_SUM_CHECK_ON_REMAIN_()
|
|
18
|
+
SIMPLE_SUM_INIT_VALUE = lib.BASE16384_SIMPLE_SUM_INIT_VALUE_()
|
|
19
|
+
|
|
14
20
|
|
|
15
21
|
# -----------------low level api------------------------------
|
|
16
22
|
def _encode(data: bytes) -> bytes:
|
|
@@ -24,9 +30,7 @@ def _encode(data: bytes) -> bytes:
|
|
|
24
30
|
|
|
25
31
|
|
|
26
32
|
def _encode_into(data: bytes, out: bytearray) -> int:
|
|
27
|
-
return lib.base16384_encode(
|
|
28
|
-
ffi.from_buffer(data), len(data), ffi.from_buffer(out)
|
|
29
|
-
)
|
|
33
|
+
return lib.base16384_encode(ffi.from_buffer(data), len(data), ffi.from_buffer(out))
|
|
30
34
|
|
|
31
35
|
|
|
32
36
|
def _decode(data: bytes) -> bytes:
|
|
@@ -40,9 +44,7 @@ def _decode(data: bytes) -> bytes:
|
|
|
40
44
|
|
|
41
45
|
|
|
42
46
|
def _decode_into(data: bytes, out: bytearray) -> int:
|
|
43
|
-
return lib.base16384_decode(
|
|
44
|
-
ffi.from_buffer(data), len(data), ffi.from_buffer(out)
|
|
45
|
-
)
|
|
47
|
+
return lib.base16384_decode(ffi.from_buffer(data), len(data), ffi.from_buffer(out))
|
|
46
48
|
|
|
47
49
|
|
|
48
50
|
def is_64bits() -> bool:
|
|
@@ -92,9 +94,7 @@ def encode_file(input: IO, output: IO, write_head: bool = False, buf_rate: int =
|
|
|
92
94
|
input.seek(-size, 1)
|
|
93
95
|
continue
|
|
94
96
|
|
|
95
|
-
count = lib.base16384_encode(
|
|
96
|
-
ffi.from_buffer(chunk), size, output_buf
|
|
97
|
-
)
|
|
97
|
+
count = lib.base16384_encode(ffi.from_buffer(chunk), size, output_buf)
|
|
98
98
|
output.write(ffi.unpack(output_buf, count))
|
|
99
99
|
if size < 7:
|
|
100
100
|
break
|
|
@@ -146,9 +146,7 @@ def decode_file(input: IO, output: IO, buf_rate: int = 10):
|
|
|
146
146
|
else:
|
|
147
147
|
input.seek(-2, 1)
|
|
148
148
|
|
|
149
|
-
count = lib.base16384_decode(
|
|
150
|
-
ffi.from_buffer(chunk), size, output_buf
|
|
151
|
-
)
|
|
149
|
+
count = lib.base16384_decode(ffi.from_buffer(chunk), size, output_buf)
|
|
152
150
|
output.write(ffi.unpack(output_buf, count))
|
|
153
151
|
|
|
154
152
|
|
|
@@ -176,13 +174,23 @@ def err_to_str(ret) -> str:
|
|
|
176
174
|
return "base16384_err_open_input_file"
|
|
177
175
|
elif ret == lib.base16384_err_map_input_file:
|
|
178
176
|
return "base16384_err_map_input_file"
|
|
177
|
+
elif ret == lib.base16384_err_read_file:
|
|
178
|
+
return "base16384_err_read_file"
|
|
179
|
+
elif ret == lib.base16384_err_invalid_file_name:
|
|
180
|
+
return "base16384_err_invalid_file_name"
|
|
181
|
+
elif ret == lib.base16384_err_invalid_file_name:
|
|
182
|
+
return "base16384_err_invalid_file_name"
|
|
183
|
+
elif ret == lib.base16384_err_invalid_commandline_parameter:
|
|
184
|
+
return "base16384_err_invalid_commandline_parameter"
|
|
185
|
+
elif ret == lib.base16384_err_invalid_decoding_checksum:
|
|
186
|
+
return "base16384_err_invalid_decoding_checksum"
|
|
179
187
|
|
|
180
188
|
|
|
181
189
|
def encode_local_file(inp, out) -> None:
|
|
182
190
|
inp_name: bytes = ensure_bytes(inp)
|
|
183
191
|
out_name: bytes = ensure_bytes(out)
|
|
184
|
-
encbuf = ffi.new(f"char[{
|
|
185
|
-
decbuf = ffi.new(f"char[{
|
|
192
|
+
encbuf = ffi.new(f"char[{ENCBUFSZ}]")
|
|
193
|
+
decbuf = ffi.new(f"char[{DECBUFSZ}]")
|
|
186
194
|
ret = lib.base16384_encode_file(
|
|
187
195
|
ffi.from_buffer(inp_name), ffi.from_buffer(out_name), encbuf, decbuf
|
|
188
196
|
)
|
|
@@ -193,8 +201,8 @@ def encode_local_file(inp, out) -> None:
|
|
|
193
201
|
def decode_local_file(inp, out) -> None:
|
|
194
202
|
inp_name: bytes = ensure_bytes(inp)
|
|
195
203
|
out_name: bytes = ensure_bytes(out)
|
|
196
|
-
encbuf = ffi.new(f"char[{
|
|
197
|
-
decbuf = ffi.new(f"char[{
|
|
204
|
+
encbuf = ffi.new(f"char[{ENCBUFSZ}]")
|
|
205
|
+
decbuf = ffi.new(f"char[{DECBUFSZ}]")
|
|
198
206
|
ret = lib.base16384_decode_file(
|
|
199
207
|
ffi.from_buffer(inp_name), ffi.from_buffer(out_name), encbuf, decbuf
|
|
200
208
|
)
|
|
@@ -203,16 +211,57 @@ def decode_local_file(inp, out) -> None:
|
|
|
203
211
|
|
|
204
212
|
|
|
205
213
|
def encode_fd(inp: int, out: int) -> None:
|
|
206
|
-
encbuf = ffi.new(f"char[{
|
|
207
|
-
decbuf = ffi.new(f"char[{
|
|
214
|
+
encbuf = ffi.new(f"char[{ENCBUFSZ}]")
|
|
215
|
+
decbuf = ffi.new(f"char[{DECBUFSZ}]")
|
|
208
216
|
ret = lib.base16384_encode_fd(inp, out, encbuf, decbuf)
|
|
209
217
|
if ret != lib.base16384_err_ok:
|
|
210
218
|
raise ValueError(err_to_str(ret))
|
|
211
219
|
|
|
212
220
|
|
|
213
221
|
def decode_fd(inp: int, out: int) -> None:
|
|
214
|
-
encbuf = ffi.new(f"char[{
|
|
215
|
-
decbuf = ffi.new(f"char[{
|
|
222
|
+
encbuf = ffi.new(f"char[{ENCBUFSZ}]")
|
|
223
|
+
decbuf = ffi.new(f"char[{DECBUFSZ}]")
|
|
216
224
|
ret = lib.base16384_decode_fd(inp, out, encbuf, decbuf)
|
|
217
225
|
if ret != lib.base16384_err_ok:
|
|
218
226
|
raise ValueError(err_to_str(ret))
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
# detail
|
|
230
|
+
def encode_local_file_detailed(inp, out, flag: int) -> None:
|
|
231
|
+
inp_name: bytes = ensure_bytes(inp)
|
|
232
|
+
out_name: bytes = ensure_bytes(out)
|
|
233
|
+
encbuf = ffi.new(f"char[{ENCBUFSZ}]")
|
|
234
|
+
decbuf = ffi.new(f"char[{DECBUFSZ}]")
|
|
235
|
+
ret = lib.base16384_encode_file_detailed(
|
|
236
|
+
ffi.from_buffer(inp_name), ffi.from_buffer(out_name), encbuf, decbuf, flag
|
|
237
|
+
)
|
|
238
|
+
if ret != lib.base16384_err_ok:
|
|
239
|
+
raise ValueError(err_to_str(ret))
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def decode_local_file_detailed(inp, out, flag: int) -> None:
|
|
243
|
+
inp_name: bytes = ensure_bytes(inp)
|
|
244
|
+
out_name: bytes = ensure_bytes(out)
|
|
245
|
+
encbuf = ffi.new(f"char[{ENCBUFSZ}]")
|
|
246
|
+
decbuf = ffi.new(f"char[{DECBUFSZ}]")
|
|
247
|
+
ret = lib.base16384_decode_file_detailed(
|
|
248
|
+
ffi.from_buffer(inp_name), ffi.from_buffer(out_name), encbuf, decbuf, flag
|
|
249
|
+
)
|
|
250
|
+
if ret != lib.base16384_err_ok:
|
|
251
|
+
raise ValueError(err_to_str(ret))
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def encode_fd_detailed(inp: int, out: int, flag: int) -> None:
|
|
255
|
+
encbuf = ffi.new(f"char[{ENCBUFSZ}]")
|
|
256
|
+
decbuf = ffi.new(f"char[{DECBUFSZ}]")
|
|
257
|
+
ret = lib.base16384_encode_fd_detailed(inp, out, encbuf, decbuf, flag)
|
|
258
|
+
if ret != lib.base16384_err_ok:
|
|
259
|
+
raise ValueError(err_to_str(ret))
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def decode_fd_detailed(inp: int, out: int, flag: int) -> None:
|
|
263
|
+
encbuf = ffi.new(f"char[{ENCBUFSZ}]")
|
|
264
|
+
decbuf = ffi.new(f"char[{DECBUFSZ}]")
|
|
265
|
+
ret = lib.base16384_decode_fd_detailed(inp, out, encbuf, decbuf, flag)
|
|
266
|
+
if ret != lib.base16384_err_ok:
|
|
267
|
+
raise ValueError(err_to_str(ret))
|
|
Binary file
|
|
@@ -26,6 +26,7 @@ if sys.byteorder != "little":
|
|
|
26
26
|
|
|
27
27
|
if CPUBIT == 64:
|
|
28
28
|
macro_base.append(("CPUBIT64", None))
|
|
29
|
+
macro_base.append(("IS_64BIT_PROCESSOR", None))
|
|
29
30
|
else:
|
|
30
31
|
macro_base.append(("CPUBIT32", None))
|
|
31
32
|
|
|
@@ -41,6 +42,10 @@ enum base16384_err_t {
|
|
|
41
42
|
base16384_err_write_file,
|
|
42
43
|
base16384_err_open_input_file,
|
|
43
44
|
base16384_err_map_input_file,
|
|
45
|
+
base16384_err_read_file,
|
|
46
|
+
base16384_err_invalid_file_name,
|
|
47
|
+
base16384_err_invalid_commandline_parameter,
|
|
48
|
+
base16384_err_invalid_decoding_checksum
|
|
44
49
|
};
|
|
45
50
|
// base16384_err_t is the return value of base16384_en/decode_file
|
|
46
51
|
typedef enum base16384_err_t base16384_err_t;
|
|
@@ -67,11 +72,27 @@ base16384_err_t base16384_decode_fp(FILE* input, FILE* output, char* encbuf, cha
|
|
|
67
72
|
// encbuf & decbuf must be no less than BASE16384_ENCBUFSZ & BASE16384_DECBUFSZ
|
|
68
73
|
base16384_err_t base16384_decode_fd(int input, int output, char* encbuf, char* decbuf);
|
|
69
74
|
|
|
75
|
+
int base16384_encode_unsafe(const char * data, int dlen, char * buf);
|
|
76
|
+
int base16384_decode_unsafe(const char * data, int dlen, char * buf);
|
|
77
|
+
|
|
78
|
+
base16384_err_t base16384_encode_file_detailed(const char* input, const char* output, char* encbuf, char* decbuf, int flag);
|
|
79
|
+
base16384_err_t base16384_decode_file_detailed(const char* input, const char* output, char* encbuf, char* decbuf, int flag);
|
|
80
|
+
base16384_err_t base16384_encode_fd_detailed(int input, int output, char* encbuf, char* decbuf, int flag);
|
|
81
|
+
base16384_err_t base16384_decode_fd_detailed(int input, int output, char* encbuf, char* decbuf, int flag);
|
|
82
|
+
base16384_err_t base16384_encode_fp_detailed(FILE* input, FILE* output, char* encbuf, char* decbuf, int flag);
|
|
83
|
+
base16384_err_t base16384_decode_fp_detailed(FILE* input, FILE* output, char* encbuf, char* decbuf, int flag);
|
|
84
|
+
|
|
70
85
|
int32_t pybase16384_64bits();
|
|
71
86
|
|
|
72
87
|
int get_encsize();
|
|
73
88
|
|
|
74
89
|
int get_decsize();
|
|
90
|
+
|
|
91
|
+
int BASE16384_FLAG_NOHEADER_();
|
|
92
|
+
|
|
93
|
+
int BASE16384_FLAG_SUM_CHECK_ON_REMAIN_();
|
|
94
|
+
|
|
95
|
+
int BASE16384_SIMPLE_SUM_INIT_VALUE_();
|
|
75
96
|
"""
|
|
76
97
|
)
|
|
77
98
|
|
|
@@ -93,6 +114,21 @@ int get_decsize()
|
|
|
93
114
|
{
|
|
94
115
|
return BASE16384_DECBUFSZ;
|
|
95
116
|
}
|
|
117
|
+
|
|
118
|
+
int BASE16384_FLAG_NOHEADER_()
|
|
119
|
+
{
|
|
120
|
+
return BASE16384_FLAG_NOHEADER;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
int BASE16384_FLAG_SUM_CHECK_ON_REMAIN_()
|
|
124
|
+
{
|
|
125
|
+
return BASE16384_FLAG_SUM_CHECK_ON_REMAIN;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
int BASE16384_SIMPLE_SUM_INIT_VALUE_()
|
|
129
|
+
{
|
|
130
|
+
return BASE16384_SIMPLE_SUM_INIT_VALUE;
|
|
131
|
+
}
|
|
96
132
|
"""
|
|
97
133
|
|
|
98
134
|
ffibuilder.set_source(
|
|
@@ -2,17 +2,26 @@
|
|
|
2
2
|
Copyright (c) 2008-2021 synodriver <synodriver@gmail.com>
|
|
3
3
|
"""
|
|
4
4
|
from pybase16384.backends.cython._core import (
|
|
5
|
+
DECBUFSZ,
|
|
6
|
+
ENCBUFSZ,
|
|
7
|
+
FLAG_NOHEADER,
|
|
8
|
+
FLAG_SUM_CHECK_ON_REMAIN,
|
|
9
|
+
SIMPLE_SUM_INIT_VALUE,
|
|
5
10
|
_decode,
|
|
6
11
|
_decode_into,
|
|
7
12
|
_encode,
|
|
8
13
|
_encode_into,
|
|
9
14
|
decode_fd,
|
|
15
|
+
decode_fd_detailed,
|
|
10
16
|
decode_file,
|
|
11
17
|
decode_len,
|
|
12
18
|
decode_local_file,
|
|
19
|
+
decode_local_file_detailed,
|
|
13
20
|
encode_fd,
|
|
21
|
+
encode_fd_detailed,
|
|
14
22
|
encode_file,
|
|
15
23
|
encode_len,
|
|
16
24
|
encode_local_file,
|
|
25
|
+
encode_local_file_detailed,
|
|
17
26
|
is_64bits,
|
|
18
27
|
)
|