python-filewrap 0.2.1__py3-none-any.whl → 0.2.2__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 +56 -1
- {python_filewrap-0.2.1.dist-info → python_filewrap-0.2.2.dist-info}/METADATA +1 -1
- python_filewrap-0.2.2.dist-info/RECORD +7 -0
- python_filewrap-0.2.1.dist-info/RECORD +0 -7
- {python_filewrap-0.2.1.dist-info → python_filewrap-0.2.2.dist-info}/LICENSE +0 -0
- {python_filewrap-0.2.1.dist-info → python_filewrap-0.2.2.dist-info}/WHEEL +0 -0
filewrap/__init__.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# encoding: utf-8
|
|
3
3
|
|
|
4
4
|
__author__ = "ChenyangGao <https://chenyanggao.github.io>"
|
|
5
|
-
__version__ = (0, 2,
|
|
5
|
+
__version__ = (0, 2, 2)
|
|
6
6
|
__all__ = [
|
|
7
7
|
"Buffer", "SupportsRead", "SupportsReadinto", "SupportsWrite", "SupportsSeek",
|
|
8
8
|
"AsyncBufferedReader", "AsyncTextIOWrapper",
|
|
@@ -14,6 +14,7 @@ __all__ = [
|
|
|
14
14
|
"bytes_to_chunk_iter", "bytes_to_chunk_async_iter",
|
|
15
15
|
"bytes_ensure_part_iter", "bytes_ensure_part_async_iter",
|
|
16
16
|
"progress_bytes_iter", "progress_bytes_async_iter",
|
|
17
|
+
"copyfileobj", "copyfileobj_async",
|
|
17
18
|
]
|
|
18
19
|
|
|
19
20
|
from asyncio import to_thread, Lock as AsyncLock
|
|
@@ -1793,3 +1794,57 @@ async def progress_bytes_async_iter(
|
|
|
1793
1794
|
if callable(close_progress):
|
|
1794
1795
|
await ensure_async(close_progress)()
|
|
1795
1796
|
|
|
1797
|
+
|
|
1798
|
+
def copyfileobj(
|
|
1799
|
+
fsrc,
|
|
1800
|
+
fdst: SupportsWrite[Buffer],
|
|
1801
|
+
/,
|
|
1802
|
+
chunksize: int = COPY_BUFSIZE,
|
|
1803
|
+
):
|
|
1804
|
+
if chunksize <= 0:
|
|
1805
|
+
chunksize = COPY_BUFSIZE
|
|
1806
|
+
fdst_write = fdst.write
|
|
1807
|
+
fsrc_read = getattr(fsrc, "read", None)
|
|
1808
|
+
fsrc_readinto = getattr(fsrc, "readinto", None)
|
|
1809
|
+
if callable(fsrc_readinto):
|
|
1810
|
+
buf = bytearray(chunksize)
|
|
1811
|
+
view = memoryview(buf)
|
|
1812
|
+
while size := fsrc_readinto(buf):
|
|
1813
|
+
fdst_write(view[:size])
|
|
1814
|
+
elif callable(fsrc_read):
|
|
1815
|
+
while chunk := fsrc_read(chunksize):
|
|
1816
|
+
fdst_write(chunk)
|
|
1817
|
+
else:
|
|
1818
|
+
for chunk in fsrc:
|
|
1819
|
+
if chunk:
|
|
1820
|
+
fdst_write(chunk)
|
|
1821
|
+
|
|
1822
|
+
|
|
1823
|
+
async def copyfileobj_async(
|
|
1824
|
+
fsrc,
|
|
1825
|
+
fdst: SupportsWrite[Buffer],
|
|
1826
|
+
/,
|
|
1827
|
+
chunksize: int = COPY_BUFSIZE,
|
|
1828
|
+
threaded: bool = True,
|
|
1829
|
+
):
|
|
1830
|
+
if chunksize <= 0:
|
|
1831
|
+
chunksize = COPY_BUFSIZE
|
|
1832
|
+
fdst_write = ensure_async(fdst.write, threaded=threaded)
|
|
1833
|
+
fsrc_read = getattr(fsrc, "read", None)
|
|
1834
|
+
fsrc_readinto = getattr(fsrc, "readinto", None)
|
|
1835
|
+
if callable(fsrc_readinto):
|
|
1836
|
+
fsrc_readinto = ensure_async(fsrc_readinto, threaded=threaded)
|
|
1837
|
+
buf = bytearray(chunksize)
|
|
1838
|
+
view = memoryview(buf)
|
|
1839
|
+
while size := await fsrc_readinto(buf):
|
|
1840
|
+
await fdst_write(view[:size])
|
|
1841
|
+
elif callable(fsrc_read):
|
|
1842
|
+
fsrc_read = ensure_async(fsrc_read, threaded=threaded)
|
|
1843
|
+
while chunk := await fsrc_read(chunksize):
|
|
1844
|
+
await fdst_write(chunk)
|
|
1845
|
+
else:
|
|
1846
|
+
chunkiter = ensure_aiter(fsrc, threaded=threaded)
|
|
1847
|
+
async for chunk in chunkiter:
|
|
1848
|
+
if chunk:
|
|
1849
|
+
await fdst_write(chunk)
|
|
1850
|
+
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
2
|
+
filewrap/__init__.py,sha256=kQ3EL_pPx5jkImO5tPuhAx6PiQnocXeHwVmBz3_o60k,62700
|
|
3
|
+
filewrap/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
python_filewrap-0.2.2.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
5
|
+
python_filewrap-0.2.2.dist-info/METADATA,sha256=hOJOU4Q01T3SkJQ0VQ7qAVOZSUcvwlEe3q2uHeo_xZ4,1413
|
|
6
|
+
python_filewrap-0.2.2.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
7
|
+
python_filewrap-0.2.2.dist-info/RECORD,,
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
2
|
-
filewrap/__init__.py,sha256=hHxlP4oHxigZM59pS1q2JcHWlir_6Tz5nFmEZKkmaJo,61023
|
|
3
|
-
filewrap/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
python_filewrap-0.2.1.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
|
|
5
|
-
python_filewrap-0.2.1.dist-info/METADATA,sha256=3uqJCHXBeLRckkyTTdzFCBLst6hv31dq68RFPU8Ei_k,1413
|
|
6
|
-
python_filewrap-0.2.1.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
7
|
-
python_filewrap-0.2.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|