python-filewrap 0.1.1__py3-none-any.whl → 0.1.3__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 +80 -5
- {python_filewrap-0.1.1.dist-info → python_filewrap-0.1.3.dist-info}/METADATA +1 -1
- python_filewrap-0.1.3.dist-info/RECORD +7 -0
- python_filewrap-0.1.1.dist-info/RECORD +0 -7
- {python_filewrap-0.1.1.dist-info → python_filewrap-0.1.3.dist-info}/LICENSE +0 -0
- {python_filewrap-0.1.1.dist-info → python_filewrap-0.1.3.dist-info}/WHEEL +0 -0
filewrap/__init__.py
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
# encoding: utf-8
|
|
3
3
|
|
|
4
4
|
__author__ = "ChenyangGao <https://chenyanggao.github.io>"
|
|
5
|
-
__version__ = (0, 1,
|
|
5
|
+
__version__ = (0, 1, 3)
|
|
6
6
|
__all__ = [
|
|
7
7
|
"Buffer", "SupportsRead", "SupportsReadinto",
|
|
8
8
|
"SupportsWrite", "SupportsSeek",
|
|
9
9
|
"bio_chunk_iter", "bio_chunk_async_iter",
|
|
10
10
|
"bio_skip_iter", "bio_skip_async_iter",
|
|
11
|
+
"bytes_iter", "bytes_async_iter",
|
|
11
12
|
"bytes_iter_skip", "bytes_async_iter_skip",
|
|
12
13
|
"bytes_iter_to_reader", "bytes_iter_to_async_reader",
|
|
13
14
|
"bytes_to_chunk_iter", "bytes_to_chunk_async_iter",
|
|
@@ -22,7 +23,7 @@ from inspect import isawaitable, iscoroutinefunction, isasyncgen, isgenerator
|
|
|
22
23
|
from itertools import chain
|
|
23
24
|
from shutil import COPY_BUFSIZE # type: ignore
|
|
24
25
|
from threading import Lock
|
|
25
|
-
from typing import runtime_checkable, Any, ParamSpec, Protocol, TypeVar
|
|
26
|
+
from typing import cast, runtime_checkable, Any, ParamSpec, Protocol, TypeVar
|
|
26
27
|
|
|
27
28
|
try:
|
|
28
29
|
from collections.abc import Buffer # type: ignore
|
|
@@ -350,6 +351,67 @@ async def bio_skip_async_iter(
|
|
|
350
351
|
yield length
|
|
351
352
|
|
|
352
353
|
|
|
354
|
+
def bytes_iter(
|
|
355
|
+
it: Iterable[Buffer],
|
|
356
|
+
/,
|
|
357
|
+
size: int = -1,
|
|
358
|
+
callback: None | Callable[[int], Any] = None,
|
|
359
|
+
) -> Iterator[Buffer]:
|
|
360
|
+
it = iter(it)
|
|
361
|
+
if size < 0:
|
|
362
|
+
yield from it
|
|
363
|
+
return
|
|
364
|
+
elif size == 0:
|
|
365
|
+
return
|
|
366
|
+
for b in it:
|
|
367
|
+
l = len(b)
|
|
368
|
+
if l <= size:
|
|
369
|
+
yield b
|
|
370
|
+
if callback is not None:
|
|
371
|
+
callback(l)
|
|
372
|
+
if l < size:
|
|
373
|
+
size -= l
|
|
374
|
+
else:
|
|
375
|
+
break
|
|
376
|
+
else:
|
|
377
|
+
yield memoryview(b)[:size]
|
|
378
|
+
if callback is not None:
|
|
379
|
+
callback(size)
|
|
380
|
+
break
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
async def bytes_async_iter(
|
|
384
|
+
it: Iterable[Buffer] | AsyncIterable[Buffer],
|
|
385
|
+
/,
|
|
386
|
+
size: int = -1,
|
|
387
|
+
callback: None | Callable[[int], Any] = None,
|
|
388
|
+
threaded: bool = False,
|
|
389
|
+
) -> AsyncIterator[Buffer]:
|
|
390
|
+
it = aiter(ensure_aiter(it, threaded=threaded))
|
|
391
|
+
if size < 0:
|
|
392
|
+
async for chunk in it:
|
|
393
|
+
yield chunk
|
|
394
|
+
return
|
|
395
|
+
elif size == 0:
|
|
396
|
+
return
|
|
397
|
+
callback = ensure_async(callback) if callable(callback) else None
|
|
398
|
+
async for b in it:
|
|
399
|
+
l = len(b)
|
|
400
|
+
if l <= size:
|
|
401
|
+
yield b
|
|
402
|
+
if callback is not None:
|
|
403
|
+
await callback(l)
|
|
404
|
+
if l < size:
|
|
405
|
+
size -= l
|
|
406
|
+
else:
|
|
407
|
+
break
|
|
408
|
+
else:
|
|
409
|
+
yield memoryview(b)[:size]
|
|
410
|
+
if callback is not None:
|
|
411
|
+
await callback(size)
|
|
412
|
+
break
|
|
413
|
+
|
|
414
|
+
|
|
353
415
|
def bytes_iter_skip(
|
|
354
416
|
it: Iterable[Buffer],
|
|
355
417
|
/,
|
|
@@ -379,8 +441,9 @@ async def bytes_async_iter_skip(
|
|
|
379
441
|
/,
|
|
380
442
|
size: int = -1,
|
|
381
443
|
callback: None | Callable[[int], Any] = None,
|
|
444
|
+
threaded: bool = False,
|
|
382
445
|
) -> AsyncIterator[Buffer]:
|
|
383
|
-
it = aiter(ensure_aiter(it))
|
|
446
|
+
it = aiter(ensure_aiter(it, threaded=threaded))
|
|
384
447
|
if size == 0:
|
|
385
448
|
return it
|
|
386
449
|
callback = ensure_async(callback) if callable(callback) else None
|
|
@@ -658,7 +721,7 @@ async def bytes_ensure_part_async_iter(
|
|
|
658
721
|
|
|
659
722
|
|
|
660
723
|
def progress_bytes_iter(
|
|
661
|
-
it: Iterable[Buffer],
|
|
724
|
+
it: Iterable[Buffer] | Callable[[], Buffer],
|
|
662
725
|
make_progress: None | Callable[Args, Any] = None,
|
|
663
726
|
/,
|
|
664
727
|
*args: Args.args,
|
|
@@ -666,6 +729,8 @@ def progress_bytes_iter(
|
|
|
666
729
|
) -> Iterator[Buffer]:
|
|
667
730
|
update_progress: None | Callable = None
|
|
668
731
|
close_progress: None | Callable = None
|
|
732
|
+
if callable(it):
|
|
733
|
+
it = iter(it, b"")
|
|
669
734
|
if callable(make_progress):
|
|
670
735
|
progress = make_progress(*args, **kwds)
|
|
671
736
|
if isgenerator(progress):
|
|
@@ -689,7 +754,7 @@ def progress_bytes_iter(
|
|
|
689
754
|
|
|
690
755
|
|
|
691
756
|
async def progress_bytes_async_iter(
|
|
692
|
-
it: Iterable[Buffer] | AsyncIterable[Buffer],
|
|
757
|
+
it: Iterable[Buffer] | AsyncIterable[Buffer] | Callable[[], Buffer] | Callable[[], Awaitable[Buffer]],
|
|
693
758
|
make_progress: None | Callable[Args, Any] = None,
|
|
694
759
|
/,
|
|
695
760
|
*args: Args.args,
|
|
@@ -697,6 +762,16 @@ async def progress_bytes_async_iter(
|
|
|
697
762
|
) -> AsyncIterator[Buffer]:
|
|
698
763
|
update_progress: None | Callable = None
|
|
699
764
|
close_progress: None | Callable = None
|
|
765
|
+
if callable(it):
|
|
766
|
+
async def wrapiter(it) -> Buffer:
|
|
767
|
+
while True:
|
|
768
|
+
chunk = it()
|
|
769
|
+
if isawaitable(chunk):
|
|
770
|
+
chunk = await chunk
|
|
771
|
+
if not chunk:
|
|
772
|
+
break
|
|
773
|
+
yield chunk
|
|
774
|
+
it = cast(AsyncIterable[Buffer], wrapiter(it))
|
|
700
775
|
if callable(make_progress):
|
|
701
776
|
progress = make_progress(*args, **kwds)
|
|
702
777
|
if isgenerator(progress):
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
2
|
+
filewrap/__init__.py,sha256=P5kKImPSlq6p7MfsNNAf26RWf5MHBTuZZJ5Mt39EDiM,24102
|
|
3
|
+
filewrap/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
python_filewrap-0.1.3.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
5
|
+
python_filewrap-0.1.3.dist-info/METADATA,sha256=cVhvl8TSDHjqLYD37JE4a5a46GDiG7j68qoxhDlLZzs,1362
|
|
6
|
+
python_filewrap-0.1.3.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
7
|
+
python_filewrap-0.1.3.dist-info/RECORD,,
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
2
|
-
filewrap/__init__.py,sha256=reWapSDxv-DZT5S2r8YqWcs6-hYSuR7zNbIjesDcD00,22066
|
|
3
|
-
filewrap/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
python_filewrap-0.1.1.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
5
|
-
python_filewrap-0.1.1.dist-info/METADATA,sha256=q7nHkF41UImZ2V-59k8upeUVpYacjBHXt-21oaTuUzo,1362
|
|
6
|
-
python_filewrap-0.1.1.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
7
|
-
python_filewrap-0.1.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|