pybase16384 0.3.6__cp38-cp38-macosx_10_9_universal2.whl → 0.3.8__cp38-cp38-macosx_10_9_universal2.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 +79 -3
- pybase16384/backends/cffi/__init__.py +200 -4
- pybase16384/backends/cffi/_core.abi3.so +0 -0
- pybase16384/backends/cffi/build.py +46 -6
- pybase16384/backends/cython/__init__.py +10 -1
- pybase16384/backends/cython/_core.abi3.so +0 -0
- pybase16384/backends/cython/_core.c +15978 -12446
- pybase16384/backends/cython/_core.pyx +241 -12
- pybase16384/backends/cython/base16384.pxd +21 -3
- {pybase16384-0.3.6.dist-info → pybase16384-0.3.8.dist-info}/METADATA +62 -10
- pybase16384-0.3.8.dist-info/RECORD +16 -0
- {pybase16384-0.3.6.dist-info → pybase16384-0.3.8.dist-info}/WHEEL +1 -1
- pybase16384-0.3.6.dist-info/RECORD +0 -16
- {pybase16384-0.3.6.dist-info → pybase16384-0.3.8.dist-info}/LICENSE +0 -0
- {pybase16384-0.3.6.dist-info → pybase16384-0.3.8.dist-info}/top_level.txt +0 -0
|
@@ -1,23 +1,29 @@
|
|
|
1
1
|
# cython: language_level=3
|
|
2
2
|
# cython: cdivision=True
|
|
3
|
-
from cpython.bytes cimport PyBytes_AS_STRING, PyBytes_Check,
|
|
3
|
+
from cpython.bytes cimport (PyBytes_AS_STRING, PyBytes_Check,
|
|
4
|
+
PyBytes_FromStringAndSize, PyBytes_GET_SIZE)
|
|
4
5
|
from cpython.mem cimport PyMem_Free, PyMem_Malloc
|
|
5
|
-
from cpython.object cimport PyObject_HasAttrString
|
|
6
|
+
from cpython.object cimport PyObject, PyObject_HasAttrString
|
|
6
7
|
from libc.stdint cimport int32_t, uint8_t
|
|
8
|
+
from libc.string cimport memcpy
|
|
7
9
|
|
|
8
10
|
from pybase16384.backends.cython.base16384 cimport (
|
|
9
|
-
BASE16384_DECBUFSZ, BASE16384_ENCBUFSZ,
|
|
10
|
-
|
|
11
|
-
b14_decode, b14_decode_fd,
|
|
12
|
-
|
|
11
|
+
BASE16384_DECBUFSZ, BASE16384_ENCBUFSZ,
|
|
12
|
+
BASE16384_FLAG_DO_SUM_CHECK_FORCELY, BASE16384_FLAG_NOHEADER,
|
|
13
|
+
BASE16384_FLAG_SUM_CHECK_ON_REMAIN, b14_decode, b14_decode_fd,
|
|
14
|
+
b14_decode_fd_detailed, b14_decode_file, b14_decode_file_detailed,
|
|
15
|
+
b14_decode_len, b14_decode_safe, b14_decode_stream,
|
|
16
|
+
b14_decode_stream_detailed, b14_encode, b14_encode_fd,
|
|
13
17
|
b14_encode_fd_detailed, b14_encode_file, b14_encode_file_detailed,
|
|
14
|
-
b14_encode_len,
|
|
18
|
+
b14_encode_len, b14_encode_safe, b14_encode_stream,
|
|
19
|
+
b14_encode_stream_detailed, base16384_err_fopen_input_file,
|
|
15
20
|
base16384_err_fopen_output_file, base16384_err_get_file_size,
|
|
16
21
|
base16384_err_invalid_commandline_parameter,
|
|
17
22
|
base16384_err_invalid_decoding_checksum, base16384_err_invalid_file_name,
|
|
18
23
|
base16384_err_map_input_file, base16384_err_ok,
|
|
19
24
|
base16384_err_open_input_file, base16384_err_read_file, base16384_err_t,
|
|
20
|
-
base16384_err_write_file,
|
|
25
|
+
base16384_err_write_file, base16384_io_function_t, base16384_stream_t,
|
|
26
|
+
pybase16384_64bits)
|
|
21
27
|
|
|
22
28
|
from pathlib import Path
|
|
23
29
|
|
|
@@ -25,7 +31,7 @@ ENCBUFSZ = BASE16384_ENCBUFSZ
|
|
|
25
31
|
DECBUFSZ = BASE16384_DECBUFSZ
|
|
26
32
|
FLAG_NOHEADER = BASE16384_FLAG_NOHEADER
|
|
27
33
|
FLAG_SUM_CHECK_ON_REMAIN = BASE16384_FLAG_SUM_CHECK_ON_REMAIN
|
|
28
|
-
|
|
34
|
+
FLAG_DO_SUM_CHECK_FORCELY = BASE16384_FLAG_DO_SUM_CHECK_FORCELY
|
|
29
35
|
|
|
30
36
|
cdef inline bytes ensure_bytes(object inp):
|
|
31
37
|
if isinstance(inp, unicode):
|
|
@@ -65,6 +71,22 @@ cpdef inline bytes _encode(const uint8_t[::1] data):
|
|
|
65
71
|
finally:
|
|
66
72
|
PyMem_Free(output_buf)
|
|
67
73
|
|
|
74
|
+
cpdef inline bytes _encode_safe(const uint8_t[::1] data):
|
|
75
|
+
cdef size_t length = data.shape[0]
|
|
76
|
+
cdef size_t output_size = <size_t> b14_encode_len(<int>length)
|
|
77
|
+
cdef char *output_buf = <char*>PyMem_Malloc(output_size)
|
|
78
|
+
if output_buf == NULL:
|
|
79
|
+
raise MemoryError
|
|
80
|
+
cdef int count
|
|
81
|
+
with nogil:
|
|
82
|
+
count = b14_encode_safe(<const char*> &data[0],
|
|
83
|
+
<int>length,
|
|
84
|
+
output_buf) # encode 整数倍的那个
|
|
85
|
+
try:
|
|
86
|
+
return <bytes>output_buf[:count]
|
|
87
|
+
finally:
|
|
88
|
+
PyMem_Free(output_buf)
|
|
89
|
+
|
|
68
90
|
cpdef inline bytes _decode(const uint8_t[::1] data):
|
|
69
91
|
cdef size_t length = data.shape[0]
|
|
70
92
|
cdef size_t output_size = <size_t> b14_decode_len(<int>length, 0) + 16
|
|
@@ -81,6 +103,22 @@ cpdef inline bytes _decode(const uint8_t[::1] data):
|
|
|
81
103
|
finally:
|
|
82
104
|
PyMem_Free(output_buf)
|
|
83
105
|
|
|
106
|
+
cpdef inline bytes _decode_safe(const uint8_t[::1] data):
|
|
107
|
+
cdef size_t length = data.shape[0]
|
|
108
|
+
cdef size_t output_size = <size_t> b14_decode_len(<int>length, 0)
|
|
109
|
+
cdef char *output_buf = <char *> PyMem_Malloc(output_size)
|
|
110
|
+
if output_buf == NULL:
|
|
111
|
+
raise MemoryError
|
|
112
|
+
cdef int count
|
|
113
|
+
with nogil:
|
|
114
|
+
count = b14_decode_safe(<const char *> &data[0],
|
|
115
|
+
<int> length,
|
|
116
|
+
output_buf) # decode
|
|
117
|
+
try:
|
|
118
|
+
return <bytes> output_buf[:count]
|
|
119
|
+
finally:
|
|
120
|
+
PyMem_Free(output_buf)
|
|
121
|
+
|
|
84
122
|
cpdef inline int _encode_into(const uint8_t[::1] data, uint8_t[::1] dest) except -1:
|
|
85
123
|
cdef size_t input_size = data.shape[0]
|
|
86
124
|
cdef size_t output_size = <size_t> b14_encode_len(<int> input_size)
|
|
@@ -92,6 +130,17 @@ cpdef inline int _encode_into(const uint8_t[::1] data, uint8_t[::1] dest) except
|
|
|
92
130
|
<int> input_size,
|
|
93
131
|
<char *> &dest[0])
|
|
94
132
|
|
|
133
|
+
cpdef inline int _encode_into_safe(const uint8_t[::1] data, uint8_t[::1] dest) except -1:
|
|
134
|
+
cdef size_t input_size = data.shape[0]
|
|
135
|
+
cdef size_t output_size = <size_t> b14_encode_len(<int> input_size)
|
|
136
|
+
cdef size_t output_buf_size = dest.shape[0]
|
|
137
|
+
if output_buf_size < output_size:
|
|
138
|
+
raise ValueError("Buffer is too small to hold result")
|
|
139
|
+
with nogil:
|
|
140
|
+
return b14_encode_safe(<const char *> &data[0],
|
|
141
|
+
<int> input_size,
|
|
142
|
+
<char *> &dest[0])
|
|
143
|
+
|
|
95
144
|
cpdef inline int _decode_into(const uint8_t[::1] data, uint8_t[::1] dest) except -1:
|
|
96
145
|
cdef size_t input_size = data.shape[0]
|
|
97
146
|
cdef size_t output_size = <size_t> b14_decode_len(<int> input_size, 0)
|
|
@@ -103,6 +152,16 @@ cpdef inline int _decode_into(const uint8_t[::1] data, uint8_t[::1] dest) except
|
|
|
103
152
|
<int> input_size,
|
|
104
153
|
<char *> &dest[0])
|
|
105
154
|
|
|
155
|
+
cpdef inline int _decode_into_safe(const uint8_t[::1] data, uint8_t[::1] dest) except -1:
|
|
156
|
+
cdef size_t input_size = data.shape[0]
|
|
157
|
+
cdef size_t output_size = <size_t> b14_decode_len(<int> input_size, 0)
|
|
158
|
+
cdef size_t output_buf_size = dest.shape[0]
|
|
159
|
+
if output_buf_size < output_size:
|
|
160
|
+
raise ValueError("Buffer is too small to hold result")
|
|
161
|
+
with nogil:
|
|
162
|
+
return b14_decode_safe(<const char *> &data[0],
|
|
163
|
+
<int> input_size,
|
|
164
|
+
<char *> &dest[0])
|
|
106
165
|
|
|
107
166
|
def encode_file(object input,
|
|
108
167
|
object output,
|
|
@@ -135,7 +194,7 @@ def encode_file(object input,
|
|
|
135
194
|
first_check = 0
|
|
136
195
|
if not PyBytes_Check(chunk):
|
|
137
196
|
raise TypeError(f"input must be a file-like rb object, got {type(input).__name__}")
|
|
138
|
-
size =
|
|
197
|
+
size = PyBytes_GET_SIZE(chunk)
|
|
139
198
|
if <int32_t> size < current_buf_len: # 数据不够了 要减小一次读取的量
|
|
140
199
|
if buf_rate > 1: # 重新设置一次读取的大小 重新设置流的位置 当然要是已经是一次读取7字节了 那就不能再变小了 直接encode吧
|
|
141
200
|
buf_rate = buf_rate / 2
|
|
@@ -151,6 +210,53 @@ def encode_file(object input,
|
|
|
151
210
|
finally:
|
|
152
211
|
PyMem_Free(output_buf)
|
|
153
212
|
|
|
213
|
+
def encode_file_safe(object input,
|
|
214
|
+
object output,
|
|
215
|
+
bint write_head = False,
|
|
216
|
+
int32_t buf_rate = 10):
|
|
217
|
+
if not PyFile_Check(input):
|
|
218
|
+
raise TypeError("input except a file-like object, got %s" % type(input).__name__)
|
|
219
|
+
if not PyFile_Check(output):
|
|
220
|
+
raise TypeError("output except a file-like object, got %s" % type(output).__name__)
|
|
221
|
+
if buf_rate <= 0:
|
|
222
|
+
buf_rate = 1
|
|
223
|
+
|
|
224
|
+
if write_head:
|
|
225
|
+
output.write(b'\xfe\xff')
|
|
226
|
+
|
|
227
|
+
cdef int32_t current_buf_len = buf_rate * 7 # 一次读取这么多字节
|
|
228
|
+
cdef size_t output_size = <size_t> b14_encode_len(<int> current_buf_len) # 因为encode_len不是单调的 这16备用
|
|
229
|
+
cdef char *output_buf = <char *> PyMem_Malloc(output_size)
|
|
230
|
+
if output_buf == NULL:
|
|
231
|
+
raise MemoryError
|
|
232
|
+
|
|
233
|
+
cdef Py_ssize_t size
|
|
234
|
+
cdef uint8_t first_check = 1 # 检查一次就行了 怎么可能出现第一次读出来是bytes 以后又变卦了的对象呢 不会吧不会吧
|
|
235
|
+
cdef int count = 0
|
|
236
|
+
cdef const char *chunk_ptr
|
|
237
|
+
try:
|
|
238
|
+
while True:
|
|
239
|
+
chunk = input.read(current_buf_len)
|
|
240
|
+
if first_check:
|
|
241
|
+
first_check = 0
|
|
242
|
+
if not PyBytes_Check(chunk):
|
|
243
|
+
raise TypeError(f"input must be a file-like rb object, got {type(input).__name__}")
|
|
244
|
+
size = PyBytes_GET_SIZE(chunk)
|
|
245
|
+
if <int32_t> size < current_buf_len: # 数据不够了 要减小一次读取的量
|
|
246
|
+
if buf_rate > 1: # 重新设置一次读取的大小 重新设置流的位置 当然要是已经是一次读取7字节了 那就不能再变小了 直接encode吧
|
|
247
|
+
buf_rate = buf_rate / 2
|
|
248
|
+
current_buf_len = buf_rate * 7
|
|
249
|
+
input.seek(-size, 1)
|
|
250
|
+
continue
|
|
251
|
+
chunk_ptr = <const char*>PyBytes_AS_STRING(chunk)
|
|
252
|
+
with nogil:
|
|
253
|
+
count = b14_encode_safe(chunk_ptr, <int>size, output_buf)
|
|
254
|
+
output.write(<bytes>output_buf[:count])
|
|
255
|
+
if size < 7:
|
|
256
|
+
break
|
|
257
|
+
finally:
|
|
258
|
+
PyMem_Free(output_buf)
|
|
259
|
+
|
|
154
260
|
def decode_file(object input,
|
|
155
261
|
object output,
|
|
156
262
|
int32_t buf_rate = 10):
|
|
@@ -180,7 +286,7 @@ def decode_file(object input,
|
|
|
180
286
|
try:
|
|
181
287
|
while True:
|
|
182
288
|
chunk = input.read(current_buf_len) # 8的倍数
|
|
183
|
-
size =
|
|
289
|
+
size = PyBytes_GET_SIZE(chunk)
|
|
184
290
|
if size == 0:
|
|
185
291
|
break
|
|
186
292
|
if <int32_t> size < current_buf_len: # 长度不够了
|
|
@@ -190,7 +296,7 @@ def decode_file(object input,
|
|
|
190
296
|
input.seek(-size, 1)
|
|
191
297
|
continue
|
|
192
298
|
tmp = input.read(2) # type: bytes
|
|
193
|
-
if
|
|
299
|
+
if PyBytes_GET_SIZE(tmp) == 2:
|
|
194
300
|
if tmp[0] == 61: # = stream完了 一次解码8n+2个字节
|
|
195
301
|
chunk += tmp
|
|
196
302
|
size += 2
|
|
@@ -203,6 +309,58 @@ def decode_file(object input,
|
|
|
203
309
|
finally:
|
|
204
310
|
PyMem_Free(output_buf)
|
|
205
311
|
|
|
312
|
+
def decode_file_safe(object input,
|
|
313
|
+
object output,
|
|
314
|
+
int32_t buf_rate = 10):
|
|
315
|
+
if not PyFile_Check(input):
|
|
316
|
+
raise TypeError("input except a file-like object, got %s" % type(input).__name__)
|
|
317
|
+
if not PyFile_Check(output):
|
|
318
|
+
raise TypeError("output except a file-like object, got %s" % type(output).__name__)
|
|
319
|
+
if buf_rate <= 0:
|
|
320
|
+
buf_rate = 1
|
|
321
|
+
|
|
322
|
+
chunk = input.read(1) # type: bytes
|
|
323
|
+
if not PyBytes_Check(chunk):
|
|
324
|
+
raise TypeError(f"input must be a file-like rb object, got {type(input).__name__}")
|
|
325
|
+
if chunk == b"\xfe": # 去头
|
|
326
|
+
input.read(1)
|
|
327
|
+
else:
|
|
328
|
+
input.seek(0, 0) # 没有头 回到开头
|
|
329
|
+
|
|
330
|
+
cdef int32_t current_buf_len = buf_rate * 8
|
|
331
|
+
cdef size_t output_size = <size_t> b14_decode_len(<int> current_buf_len, 0)
|
|
332
|
+
cdef char *output_buf = <char *> PyMem_Malloc(output_size)
|
|
333
|
+
if output_buf == NULL:
|
|
334
|
+
raise MemoryError
|
|
335
|
+
cdef Py_ssize_t size
|
|
336
|
+
cdef int count = 0
|
|
337
|
+
cdef const char *chunk_ptr
|
|
338
|
+
try:
|
|
339
|
+
while True:
|
|
340
|
+
chunk = input.read(current_buf_len) # 8的倍数
|
|
341
|
+
size = PyBytes_GET_SIZE(chunk)
|
|
342
|
+
if size == 0:
|
|
343
|
+
break
|
|
344
|
+
if <int32_t> size < current_buf_len: # 长度不够了
|
|
345
|
+
if buf_rate > 1: # 还能继续变小
|
|
346
|
+
buf_rate = buf_rate / 2 # 重新设置一次读取的大小
|
|
347
|
+
current_buf_len = buf_rate * 8
|
|
348
|
+
input.seek(-size, 1)
|
|
349
|
+
continue
|
|
350
|
+
tmp = input.read(2) # type: bytes
|
|
351
|
+
if PyBytes_GET_SIZE(tmp) == 2:
|
|
352
|
+
if tmp[0] == 61: # = stream完了 一次解码8n+2个字节
|
|
353
|
+
chunk += tmp
|
|
354
|
+
size += 2
|
|
355
|
+
else:
|
|
356
|
+
input.seek(-2, 1)
|
|
357
|
+
chunk_ptr = <const char *> PyBytes_AS_STRING(chunk)
|
|
358
|
+
with nogil:
|
|
359
|
+
count = b14_decode_safe(chunk_ptr, <int> size, output_buf)
|
|
360
|
+
output.write(<bytes>output_buf[:count])
|
|
361
|
+
finally:
|
|
362
|
+
PyMem_Free(output_buf)
|
|
363
|
+
|
|
206
364
|
cpdef inline bint is_64bits() nogil:
|
|
207
365
|
return pybase16384_64bits()
|
|
208
366
|
|
|
@@ -388,3 +546,74 @@ cpdef inline decode_fd_detailed(int inp, int out, int flag):
|
|
|
388
546
|
finally:
|
|
389
547
|
PyMem_Free(encbuf)
|
|
390
548
|
PyMem_Free(decbuf)
|
|
549
|
+
|
|
550
|
+
# stream
|
|
551
|
+
cdef ssize_t b14_readcallback(const void *client_data, void *buffer, size_t count) except -100 with gil:
|
|
552
|
+
cdef object file = <object>client_data
|
|
553
|
+
cdef bytes data = file.read(count)
|
|
554
|
+
cdef char* data_ptr = PyBytes_AS_STRING(data)
|
|
555
|
+
cdef ssize_t data_size = <ssize_t>PyBytes_GET_SIZE(data)
|
|
556
|
+
memcpy(buffer, data_ptr, <size_t>data_size)
|
|
557
|
+
return data_size
|
|
558
|
+
|
|
559
|
+
cdef ssize_t b14_writecallback(const void *client_data, const void *buffer, size_t count) except -100 with gil:
|
|
560
|
+
cdef object file = <object>client_data
|
|
561
|
+
cdef bytes data = PyBytes_FromStringAndSize(<char*>buffer, <Py_ssize_t>count)
|
|
562
|
+
cdef ssize_t ret = <ssize_t>file.write(data)
|
|
563
|
+
return ret
|
|
564
|
+
|
|
565
|
+
cpdef inline encode_stream_detailed(object inp, object out, int flag):
|
|
566
|
+
cdef char * encbuf = <char *> PyMem_Malloc(<size_t> BASE16384_ENCBUFSZ)
|
|
567
|
+
if encbuf == NULL:
|
|
568
|
+
raise MemoryError
|
|
569
|
+
cdef char * decbuf = <char *> PyMem_Malloc(<size_t> BASE16384_DECBUFSZ)
|
|
570
|
+
if decbuf == NULL:
|
|
571
|
+
PyMem_Free(encbuf)
|
|
572
|
+
raise MemoryError
|
|
573
|
+
|
|
574
|
+
cdef base16384_err_t ret
|
|
575
|
+
|
|
576
|
+
cdef base16384_stream_t inpstream = base16384_stream_t(f=base16384_io_function_t(reader=b14_readcallback),
|
|
577
|
+
client_data=<void *> inp)
|
|
578
|
+
# inpstream.f.reader = b14_readcallback
|
|
579
|
+
# inpstream.client_data = <const void*>inp
|
|
580
|
+
|
|
581
|
+
cdef base16384_stream_t outstream = base16384_stream_t(f=base16384_io_function_t(writer=b14_writecallback),
|
|
582
|
+
client_data=<void *> out)
|
|
583
|
+
# outstream.f.writer = b14_writecallback
|
|
584
|
+
# outstream.client_data = <const void*>out
|
|
585
|
+
try:
|
|
586
|
+
with nogil:
|
|
587
|
+
ret = b14_encode_stream_detailed(&inpstream, &outstream, encbuf, decbuf, flag)
|
|
588
|
+
if ret != base16384_err_ok:
|
|
589
|
+
raise ValueError(err_to_str(ret))
|
|
590
|
+
finally:
|
|
591
|
+
PyMem_Free(encbuf)
|
|
592
|
+
PyMem_Free(decbuf)
|
|
593
|
+
|
|
594
|
+
cpdef inline decode_stream_detailed(object inp, object out, int flag):
|
|
595
|
+
cdef char * encbuf = <char *> PyMem_Malloc(<size_t> BASE16384_ENCBUFSZ)
|
|
596
|
+
if encbuf == NULL:
|
|
597
|
+
raise MemoryError
|
|
598
|
+
cdef char * decbuf = <char *> PyMem_Malloc(<size_t> BASE16384_DECBUFSZ)
|
|
599
|
+
if decbuf == NULL:
|
|
600
|
+
PyMem_Free(encbuf)
|
|
601
|
+
raise MemoryError
|
|
602
|
+
|
|
603
|
+
cdef base16384_err_t ret
|
|
604
|
+
|
|
605
|
+
cdef base16384_stream_t inpstream = base16384_stream_t(f=base16384_io_function_t(reader=b14_readcallback),client_data= <void*>inp)
|
|
606
|
+
# inpstream.f.reader = b14_readcallback
|
|
607
|
+
# inpstream.client_data = <const void*>inp
|
|
608
|
+
|
|
609
|
+
cdef base16384_stream_t outstream = base16384_stream_t(f=base16384_io_function_t(writer=b14_writecallback),client_data= <void*>out)
|
|
610
|
+
# outstream.f.writer = b14_writecallback
|
|
611
|
+
# outstream.client_data = <const void*>out
|
|
612
|
+
try:
|
|
613
|
+
with nogil:
|
|
614
|
+
ret = b14_decode_stream_detailed(&inpstream, &outstream, encbuf, decbuf, flag)
|
|
615
|
+
if ret != base16384_err_ok:
|
|
616
|
+
raise ValueError(err_to_str(ret))
|
|
617
|
+
finally:
|
|
618
|
+
PyMem_Free(encbuf)
|
|
619
|
+
PyMem_Free(decbuf)
|
|
@@ -10,7 +10,7 @@ cdef extern from "base16384.h" nogil:
|
|
|
10
10
|
|
|
11
11
|
int BASE16384_FLAG_NOHEADER
|
|
12
12
|
int BASE16384_FLAG_SUM_CHECK_ON_REMAIN
|
|
13
|
-
int
|
|
13
|
+
int BASE16384_FLAG_DO_SUM_CHECK_FORCELY
|
|
14
14
|
|
|
15
15
|
ctypedef enum base16384_err_t:
|
|
16
16
|
base16384_err_ok
|
|
@@ -29,11 +29,14 @@ cdef extern from "base16384.h" nogil:
|
|
|
29
29
|
# decode_len calc min buf size to fill decode result
|
|
30
30
|
int b14_decode_len "base16384_decode_len" (int dlen, int offset)
|
|
31
31
|
|
|
32
|
+
int b14_encode_safe "base16384_encode_safe" (const char * data, int dlen, char * buf)
|
|
32
33
|
# encode data and write result into buf
|
|
33
34
|
int b14_encode "base16384_encode" (const char* data, int dlen, char* buf)
|
|
34
35
|
|
|
35
36
|
int b14_encode_unsafe "base16384_encode_unsafe" (const char * data, int dlen, char * buf)
|
|
36
37
|
# decode data and write result into buf
|
|
38
|
+
int b14_decode_safe "base16384_decode_safe" (const char * data, int dlen, char * buf)
|
|
39
|
+
|
|
37
40
|
int b14_decode "base16384_decode" (const char* data, int dlen, char* buf)
|
|
38
41
|
|
|
39
42
|
int b14_decode_unsafe "base16384_decode_unsafe"(const char * data, int dlen, char * buf)
|
|
@@ -82,14 +85,29 @@ cdef extern from "base16384.h" nogil:
|
|
|
82
85
|
# base16384_decode_fd_detailed decodes input fd to output fd.
|
|
83
86
|
# encbuf & decbuf must be no less than BASE16384_ENCBUFSZ & BASE16384_DECBUFSZ
|
|
84
87
|
base16384_err_t b14_decode_fd_detailed "base16384_decode_fd_detailed" (int input, int output, char* encbuf, char* decbuf, int flag)
|
|
88
|
+
# stream
|
|
89
|
+
ctypedef ssize_t (*base16384_reader_t) (const void *client_data, void *buffer, size_t count) except -100
|
|
90
|
+
ctypedef ssize_t (*base16384_writer_t) (const void *client_data, const void *buffer, size_t count) except -100
|
|
91
|
+
|
|
92
|
+
ctypedef union base16384_io_function_t:
|
|
93
|
+
base16384_reader_t reader
|
|
94
|
+
base16384_writer_t writer
|
|
95
|
+
|
|
96
|
+
ctypedef struct base16384_stream_t:
|
|
97
|
+
base16384_io_function_t f
|
|
98
|
+
void* client_data
|
|
85
99
|
|
|
100
|
+
base16384_err_t b14_encode_stream "base16384_encode_stream"(base16384_stream_t* input, base16384_stream_t* output, char* encbuf, char* decbuf)
|
|
101
|
+
base16384_err_t b14_encode_stream_detailed "base16384_encode_stream_detailed"(base16384_stream_t* input, base16384_stream_t* output, char* encbuf, char* decbuf, int flag)
|
|
102
|
+
base16384_err_t b14_decode_stream "base16384_decode_stream"(base16384_stream_t* input, base16384_stream_t* output, char* encbuf, char* decbuf)
|
|
103
|
+
base16384_err_t b14_decode_stream_detailed "base16384_decode_stream_detailed"(base16384_stream_t* input, base16384_stream_t* output, char* encbuf, char* decbuf, int flag)
|
|
86
104
|
|
|
87
105
|
cdef extern from * nogil:
|
|
88
106
|
"""
|
|
89
107
|
#ifdef CPUBIT32
|
|
90
|
-
#define pybase16384_64bits() 0
|
|
108
|
+
#define pybase16384_64bits() (0)
|
|
91
109
|
#else
|
|
92
|
-
#define pybase16384_64bits() 1
|
|
110
|
+
#define pybase16384_64bits() (1)
|
|
93
111
|
#endif
|
|
94
112
|
"""
|
|
95
113
|
int32_t pybase16384_64bits()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: pybase16384
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.8
|
|
4
4
|
Summary: fast base16384 encode and decode
|
|
5
5
|
Home-page: https://github.com/synodriver/pybase16384
|
|
6
6
|
Author: synodriver
|
|
@@ -24,7 +24,7 @@ Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
|
24
24
|
Requires-Python: >=3.6
|
|
25
25
|
Description-Content-Type: text/markdown
|
|
26
26
|
License-File: LICENSE
|
|
27
|
-
Requires-Dist: cffi
|
|
27
|
+
Requires-Dist: cffi >=1.0.0
|
|
28
28
|
|
|
29
29
|
<h1 align="center"><i>✨ pybase16384 ✨ </i></h1>
|
|
30
30
|
|
|
@@ -78,37 +78,81 @@ for i in range(1):
|
|
|
78
78
|
|
|
79
79
|
### 公开函数
|
|
80
80
|
```python
|
|
81
|
+
from typing import IO
|
|
82
|
+
|
|
81
83
|
def encode_len(dlen: int) -> int: ...
|
|
82
84
|
|
|
83
85
|
def decode_len(dlen: int, offset: int) -> int: ...
|
|
84
86
|
|
|
87
|
+
ENCBUFSZ: int
|
|
88
|
+
DECBUFSZ: int
|
|
89
|
+
FLAG_NOHEADER: int
|
|
90
|
+
FLAG_SUM_CHECK_ON_REMAIN: int
|
|
91
|
+
FLAG_DO_SUM_CHECK_FORCELY: int
|
|
92
|
+
|
|
93
|
+
def is_64bits() -> bool: ...
|
|
94
|
+
|
|
95
|
+
def encode_file(input: IO, output: IO, write_head: bool = ..., buf_rate: int = ...): ...
|
|
96
|
+
|
|
97
|
+
def encode_file_safe(input: IO, output: IO, write_head: bool = ..., buf_rate: int = ...): ...
|
|
98
|
+
|
|
99
|
+
def decode_file(input: IO, output: IO, buf_rate: int = ...): ...
|
|
100
|
+
|
|
101
|
+
def decode_file_safe(input: IO, output: IO, buf_rate: int = ...): ...
|
|
102
|
+
|
|
103
|
+
def ensure_bytes(inp) -> bytes: ...
|
|
104
|
+
|
|
105
|
+
def encode_local_file(inp, out) -> None: ...
|
|
106
|
+
|
|
107
|
+
def decode_local_file(inp, out) -> None: ...
|
|
108
|
+
|
|
109
|
+
def encode_fd(inp: int, out: int) -> None: ...
|
|
110
|
+
|
|
111
|
+
def decode_fd(inp: int, out: int) -> None: ...
|
|
112
|
+
|
|
113
|
+
def encode_local_file_detailed(inp, out, flag: int) -> None: ...
|
|
114
|
+
|
|
115
|
+
def decode_local_file_detailed(inp, out, flag: int) -> None: ...
|
|
116
|
+
|
|
117
|
+
def encode_fd_detailed(inp: int, out: int, flag: int) -> None: ...
|
|
118
|
+
|
|
119
|
+
def decode_fd_detailed(inp: int, out: int, flag: int) -> None: ...
|
|
120
|
+
|
|
85
121
|
def encode(data: bytes) -> bytes: ...
|
|
86
122
|
|
|
123
|
+
def encode_safe(data: bytes) -> bytes: ...
|
|
124
|
+
|
|
87
125
|
def decode(data: bytes) -> bytes: ...
|
|
88
126
|
|
|
89
|
-
def
|
|
127
|
+
def decode_safe(data: bytes) -> bytes: ...
|
|
90
128
|
|
|
91
|
-
def
|
|
129
|
+
def encode_from_string(data: str, write_head: bool = ...) -> bytes: ...
|
|
92
130
|
|
|
93
|
-
def
|
|
131
|
+
def encode_from_string_safe(data: str, write_head: bool = ...) -> bytes: ...
|
|
94
132
|
|
|
95
133
|
def encode_to_string(data: bytes) -> str: ...
|
|
96
134
|
|
|
135
|
+
def encode_to_string_safe(data: bytes) -> str: ...
|
|
136
|
+
|
|
97
137
|
def encode_string(data: str) -> str: ...
|
|
98
138
|
|
|
139
|
+
def encode_string_safe(data: str) -> str: ...
|
|
140
|
+
|
|
99
141
|
def decode_from_bytes(data: bytes) -> str: ...
|
|
100
142
|
|
|
143
|
+
def decode_from_bytes_safe(data: bytes) -> str: ...
|
|
144
|
+
|
|
101
145
|
def decode_from_string(data: str) -> bytes: ...
|
|
102
146
|
|
|
147
|
+
def decode_from_string_safe(data: str) -> bytes: ...
|
|
148
|
+
|
|
103
149
|
def decode_string(data: str) -> str: ...
|
|
104
150
|
|
|
105
|
-
def
|
|
151
|
+
def decode_string_safe(data: str) -> str: ...
|
|
106
152
|
|
|
107
|
-
def
|
|
153
|
+
def encode_stream_detailed(inp, out, flag: int): ...
|
|
108
154
|
|
|
109
|
-
def
|
|
110
|
-
|
|
111
|
-
def decode_fd(inp: int, out: int) -> None: ...
|
|
155
|
+
def decode_stream_detailed(inp, out, flag: int): ...
|
|
112
156
|
```
|
|
113
157
|
- write_head将显式指明编码出的文本格式(utf16be),以便文本编辑器(如记事本)能够正确渲染,一般在写入文件时使用。
|
|
114
158
|
|
|
@@ -124,12 +168,20 @@ def decode_fd(inp: int, out: int) -> None: ...
|
|
|
124
168
|
```python
|
|
125
169
|
def _encode(data: BufferProtocol) -> bytes: ...
|
|
126
170
|
|
|
171
|
+
def _encode_safe(data: BufferProtocol) -> bytes: ...
|
|
172
|
+
|
|
127
173
|
def _decode(data: BufferProtocol) -> bytes: ...
|
|
128
174
|
|
|
175
|
+
def _decode_safe(data: BufferProtocol) -> bytes: ...
|
|
176
|
+
|
|
129
177
|
def _encode_into(data: BufferProtocol, dest: BufferProtocol) -> int: ...
|
|
130
178
|
|
|
179
|
+
def _encode_into_safe(data: BufferProtocol, dest: BufferProtocol) -> int: ...
|
|
180
|
+
|
|
131
181
|
def _decode_into(data: BufferProtocol, dest: BufferProtocol) -> int: ...
|
|
132
182
|
|
|
183
|
+
def _decode_into_safe(data: BufferProtocol, dest: BufferProtocol) -> int: ...
|
|
184
|
+
|
|
133
185
|
def is_64bits() -> bool: ...
|
|
134
186
|
```
|
|
135
187
|
- ```_decode```在解码```b'='```开头的数据时***不安全***:***解释器异常***
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
pybase16384/__init__.py,sha256=xDOQ59rGsfkEhlODtzpqltiJmvTOMYT0puEhW6w8DBo,4897
|
|
2
|
+
pybase16384/backends/__init__.py,sha256=vdW_t1O2WNfdRmxDlEXRvTpyJj5ufKWAUsD2fbtku5g,55
|
|
3
|
+
pybase16384/backends/cffi/build.py,sha256=NyTK_W4JKJbqtdAS0yZ0sxkQvLDE8npjOskWN1-YOqk,5824
|
|
4
|
+
pybase16384/backends/cffi/__init__.py,sha256=oGen7JI3AMlvsCjM8xF4k6zBK2v_QqQ5UsrdMVtD_Zo,15970
|
|
5
|
+
pybase16384/backends/cffi/_core.abi3.so,sha256=t5zvjFeo68fo2WMTMI2F9leH9WR8zITIx-rfkV3cimM,188768
|
|
6
|
+
pybase16384/backends/cython/_core.c,sha256=Co0qxbDmNKtX39tTxGMB2Sh5zYdExvPFvUeGVq3X5C8,1558557
|
|
7
|
+
pybase16384/backends/cython/__init__.py,sha256=iqaf2DeavB1x_LnQi949Qqkrn00KAwG9xJMPVUdnIB8,738
|
|
8
|
+
pybase16384/backends/cython/base16384.pxd,sha256=HFGuEe2rXBWYw1vx74uaI7YATtkRGpcUAjANMRxPRFA,5942
|
|
9
|
+
pybase16384/backends/cython/_core.abi3.so,sha256=2aRco3uezVyA3YRBOQUw5VlUwm1JFeDaYaCzyHjM2sY,527696
|
|
10
|
+
pybase16384/backends/cython/_core.pyx,sha256=OcY07Gk5n-9snqRCFrVTU-WhI8k1yiD6zcutRD5G1Dk,25159
|
|
11
|
+
pybase16384/backends/cython/_core.pxi,sha256=2fXuRiumLqxO0bnmZVEz0lr_GX-grJGBfhGIVedfyt8,530
|
|
12
|
+
pybase16384-0.3.8.dist-info/RECORD,,
|
|
13
|
+
pybase16384-0.3.8.dist-info/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
|
|
14
|
+
pybase16384-0.3.8.dist-info/WHEEL,sha256=qSV6MdWvyenD5iOCNB8SN2QD3CqO4eoH1twefEj9ofw,112
|
|
15
|
+
pybase16384-0.3.8.dist-info/top_level.txt,sha256=kXpl7pWjnjpm74qJP0SJg3JhbiWuwKQApJgkJH0B5Mk,12
|
|
16
|
+
pybase16384-0.3.8.dist-info/METADATA,sha256=YmRB-ilBmbPs3GtT_87LhZ6td-Zl-G8ifiXGXGleIDY,6605
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
pybase16384-0.3.6.dist-info/RECORD,,
|
|
2
|
-
pybase16384-0.3.6.dist-info/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
|
|
3
|
-
pybase16384-0.3.6.dist-info/WHEEL,sha256=SdS6if6-uCozRXZ5GMXYH2j8iojAu9bSvihUMOitgnA,113
|
|
4
|
-
pybase16384-0.3.6.dist-info/top_level.txt,sha256=kXpl7pWjnjpm74qJP0SJg3JhbiWuwKQApJgkJH0B5Mk,12
|
|
5
|
-
pybase16384-0.3.6.dist-info/METADATA,sha256=PFDZlRqunJmn2MpmKZ8ltniUoCEE3eSmXwTpC5Wq5VM,5387
|
|
6
|
-
pybase16384/__init__.py,sha256=7GvQhJQVZAIGGSmUlq3LmdyQO3LInUlnha4Yeqbq8W8,2933
|
|
7
|
-
pybase16384/backends/__init__.py,sha256=vdW_t1O2WNfdRmxDlEXRvTpyJj5ufKWAUsD2fbtku5g,55
|
|
8
|
-
pybase16384/backends/cffi/build.py,sha256=d4Z9l6EF1yPwex5HmiMdQ-ANSHNtLeAiM3ksRnOZaas,4396
|
|
9
|
-
pybase16384/backends/cffi/__init__.py,sha256=CsRpcA_dhOqkPm0Cn9Wh_RxAeba5RYhyDDPQoV3BHX8,9507
|
|
10
|
-
pybase16384/backends/cffi/_core.abi3.so,sha256=VVS5uUW8-nw_XDVgEjTA5L5qEAGcjn1fzfVtDry4l7g,154432
|
|
11
|
-
pybase16384/backends/cython/_core.c,sha256=EJEvkeElNCEgAb4Sdw2AK4myOn7ybMsog7c92h_K014,1393172
|
|
12
|
-
pybase16384/backends/cython/__init__.py,sha256=iBis69sFYOO94e7CLK9V1SkjtYJZMTHGmGWYgOq6Fdk,551
|
|
13
|
-
pybase16384/backends/cython/base16384.pxd,sha256=ilQqiUp3FYxuibR_WTgAI079Q7FvAHCWWzW5fKBools,4654
|
|
14
|
-
pybase16384/backends/cython/_core.abi3.so,sha256=Uu39H2uP_4aDUS4ffHz9VQCmSnSDu_vfwvEoNb2i2Og,491536
|
|
15
|
-
pybase16384/backends/cython/_core.pyx,sha256=SlurBrEjfMkNit0kVDIJiATIJoGNRN5SPpb2v1g8NBM,15375
|
|
16
|
-
pybase16384/backends/cython/_core.pxi,sha256=2fXuRiumLqxO0bnmZVEz0lr_GX-grJGBfhGIVedfyt8,530
|
|
File without changes
|
|
File without changes
|