python-filewrap 0.0.6__py3-none-any.whl → 0.0.7__py3-none-any.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.
- filewrap/__init__.py +55 -2
- {python_filewrap-0.0.6.dist-info → python_filewrap-0.0.7.dist-info}/METADATA +1 -1
- python_filewrap-0.0.7.dist-info/RECORD +7 -0
- python_filewrap-0.0.6.dist-info/RECORD +0 -7
- {python_filewrap-0.0.6.dist-info → python_filewrap-0.0.7.dist-info}/LICENSE +0 -0
- {python_filewrap-0.0.6.dist-info → python_filewrap-0.0.7.dist-info}/WHEEL +0 -0
filewrap/__init__.py
CHANGED
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
# encoding: utf-8
|
|
3
3
|
|
|
4
4
|
__author__ = "ChenyangGao <https://chenyanggao.github.io>"
|
|
5
|
-
__version__ = (0, 0,
|
|
5
|
+
__version__ = (0, 0, 7)
|
|
6
6
|
__all__ = [
|
|
7
7
|
"SupportsRead", "SupportsWrite",
|
|
8
8
|
"bio_chunk_iter", "bio_chunk_async_iter",
|
|
9
9
|
"bio_skip_iter", "bio_skip_async_iter",
|
|
10
|
+
"bytes_iter_skip", "bytes_async_iter_skip",
|
|
10
11
|
"bytes_iter_to_reader", "bytes_iter_to_async_reader",
|
|
11
12
|
"bytes_to_chunk_iter", "bytes_to_chunk_async_iter",
|
|
12
13
|
"bytes_ensure_part_iter", "bytes_ensure_part_async_iter",
|
|
@@ -16,6 +17,7 @@ from asyncio import to_thread, Lock as AsyncLock
|
|
|
16
17
|
from collections.abc import Awaitable, AsyncIterable, Iterable
|
|
17
18
|
from functools import update_wrapper
|
|
18
19
|
from inspect import isawaitable, iscoroutinefunction
|
|
20
|
+
from itertools import chain
|
|
19
21
|
from collections.abc import AsyncIterator, Callable, Iterator
|
|
20
22
|
from shutil import COPY_BUFSIZE # type: ignore
|
|
21
23
|
from threading import Lock
|
|
@@ -26,7 +28,7 @@ try:
|
|
|
26
28
|
except ImportError:
|
|
27
29
|
Buffer = Any
|
|
28
30
|
|
|
29
|
-
from asynctools import ensure_async, ensure_aiter
|
|
31
|
+
from asynctools import async_chain, ensure_async, ensure_aiter
|
|
30
32
|
|
|
31
33
|
|
|
32
34
|
_T_co = TypeVar("_T_co", covariant=True)
|
|
@@ -242,6 +244,57 @@ async def bio_skip_async_iter(
|
|
|
242
244
|
yield length
|
|
243
245
|
|
|
244
246
|
|
|
247
|
+
def bytes_iter_skip(
|
|
248
|
+
it: Iterable[Buffer],
|
|
249
|
+
/,
|
|
250
|
+
size: int = -1,
|
|
251
|
+
callback: None | Callable[[int], Any] = None,
|
|
252
|
+
) -> Iterator[memoryview | Buffer]:
|
|
253
|
+
it = iter(it)
|
|
254
|
+
if size == 0:
|
|
255
|
+
return it
|
|
256
|
+
if not callable(callback):
|
|
257
|
+
callback = None
|
|
258
|
+
for m in map(memoryview, it):
|
|
259
|
+
l = len(m)
|
|
260
|
+
if callback:
|
|
261
|
+
callback(min(l, size))
|
|
262
|
+
if l == size:
|
|
263
|
+
return it
|
|
264
|
+
elif l > size:
|
|
265
|
+
return chain((m[size:],), it)
|
|
266
|
+
else:
|
|
267
|
+
size -= l
|
|
268
|
+
return iter(())
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
async def bytes_async_iter_skip(
|
|
272
|
+
it: Iterable[Buffer] | AsyncIterator[Buffer],
|
|
273
|
+
/,
|
|
274
|
+
size: int = -1,
|
|
275
|
+
callback: None | Callable[[int], Any] = None,
|
|
276
|
+
) -> AsyncIterator[memoryview | Buffer]:
|
|
277
|
+
it = aiter(ensure_aiter(it))
|
|
278
|
+
if size == 0:
|
|
279
|
+
return it
|
|
280
|
+
callback = ensure_async(callback) if callable(callback) else None
|
|
281
|
+
async for b in it:
|
|
282
|
+
m = memoryview(b)
|
|
283
|
+
l = len(m)
|
|
284
|
+
if callback:
|
|
285
|
+
await callback(min(l, size))
|
|
286
|
+
if l == size:
|
|
287
|
+
return it
|
|
288
|
+
elif l > size:
|
|
289
|
+
return async_chain((m[size:],), it)
|
|
290
|
+
else:
|
|
291
|
+
size -= l
|
|
292
|
+
async def make_iter():
|
|
293
|
+
if False:
|
|
294
|
+
yield
|
|
295
|
+
return make_iter()
|
|
296
|
+
|
|
297
|
+
|
|
245
298
|
def bytes_iter_to_reader(
|
|
246
299
|
it: Iterable[Buffer],
|
|
247
300
|
/,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
2
|
+
filewrap/__init__.py,sha256=X3RWnRcr2wycOIQJomqKRdwh2lA8GWUJJLZb8tDpodU,16575
|
|
3
|
+
filewrap/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
python_filewrap-0.0.7.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
5
|
+
python_filewrap-0.0.7.dist-info/METADATA,sha256=Tt3qu_XvzzpK7AuNBh5vPGJJpql5ezi9PYosXqctUbY,1362
|
|
6
|
+
python_filewrap-0.0.7.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
7
|
+
python_filewrap-0.0.7.dist-info/RECORD,,
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
2
|
-
filewrap/__init__.py,sha256=7bcdEybE4NnEW9XHB4Cs0GoKL8YRW-1B2tqzFXXcHbs,15223
|
|
3
|
-
filewrap/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
python_filewrap-0.0.6.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
5
|
-
python_filewrap-0.0.6.dist-info/METADATA,sha256=m-aMbZMtnccOwY6zSFw88J06MFazBae7gP1z8vipBTQ,1362
|
|
6
|
-
python_filewrap-0.0.6.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
7
|
-
python_filewrap-0.0.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|