python-filewrap 0.1.3__tar.gz → 0.1.4__tar.gz
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.
- {python_filewrap-0.1.3 → python_filewrap-0.1.4}/PKG-INFO +1 -1
- {python_filewrap-0.1.3 → python_filewrap-0.1.4}/filewrap/__init__.py +31 -15
- {python_filewrap-0.1.3 → python_filewrap-0.1.4}/pyproject.toml +1 -1
- {python_filewrap-0.1.3 → python_filewrap-0.1.4}/LICENSE +0 -0
- {python_filewrap-0.1.3 → python_filewrap-0.1.4}/filewrap/py.typed +0 -0
- {python_filewrap-0.1.3 → python_filewrap-0.1.4}/readme.md +0 -0
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# encoding: utf-8
|
|
3
3
|
|
|
4
4
|
__author__ = "ChenyangGao <https://chenyanggao.github.io>"
|
|
5
|
-
__version__ = (0, 1,
|
|
5
|
+
__version__ = (0, 1, 4)
|
|
6
6
|
__all__ = [
|
|
7
7
|
"Buffer", "SupportsRead", "SupportsReadinto",
|
|
8
8
|
"SupportsWrite", "SupportsSeek",
|
|
@@ -90,7 +90,7 @@ class SupportsSeek(Protocol):
|
|
|
90
90
|
|
|
91
91
|
|
|
92
92
|
def bio_chunk_iter(
|
|
93
|
-
bio: SupportsRead[Buffer] | Callable[[int], Buffer],
|
|
93
|
+
bio: SupportsRead[Buffer] | SupportsReadinto | Callable[[int], Buffer],
|
|
94
94
|
/,
|
|
95
95
|
size: int = -1,
|
|
96
96
|
chunksize: int = COPY_BUFSIZE,
|
|
@@ -100,11 +100,19 @@ def bio_chunk_iter(
|
|
|
100
100
|
use_readinto = False
|
|
101
101
|
if callable(bio):
|
|
102
102
|
read = bio
|
|
103
|
-
elif can_buffer and
|
|
103
|
+
elif can_buffer and isinstance(bio, SupportsReadinto):
|
|
104
104
|
readinto = bio.readinto
|
|
105
105
|
use_readinto = True
|
|
106
|
-
|
|
106
|
+
elif isinstance(bio, SupportsRead):
|
|
107
107
|
read = bio.read
|
|
108
|
+
else:
|
|
109
|
+
readinto = bio.readinto
|
|
110
|
+
def read(_):
|
|
111
|
+
buf = bytearray(chunksize)
|
|
112
|
+
length = readinto(buf)
|
|
113
|
+
if length == chunksize:
|
|
114
|
+
return buf
|
|
115
|
+
return buf[:length]
|
|
108
116
|
if not callable(callback):
|
|
109
117
|
callback = None
|
|
110
118
|
if use_readinto:
|
|
@@ -151,7 +159,7 @@ def bio_chunk_iter(
|
|
|
151
159
|
|
|
152
160
|
|
|
153
161
|
async def bio_chunk_async_iter(
|
|
154
|
-
bio: SupportsRead[Buffer] | Callable[[int], Buffer | Awaitable[Buffer]],
|
|
162
|
+
bio: SupportsRead[Buffer] | SupportsReadinto | Callable[[int], Buffer | Awaitable[Buffer]],
|
|
155
163
|
/,
|
|
156
164
|
size: int = -1,
|
|
157
165
|
chunksize: int = COPY_BUFSIZE,
|
|
@@ -160,12 +168,20 @@ async def bio_chunk_async_iter(
|
|
|
160
168
|
) -> AsyncIterator[Buffer]:
|
|
161
169
|
use_readinto = False
|
|
162
170
|
if callable(bio):
|
|
163
|
-
read = ensure_async(bio)
|
|
164
|
-
elif can_buffer and
|
|
165
|
-
readinto = ensure_async(bio.readinto)
|
|
171
|
+
read = ensure_async(bio, threaded=True)
|
|
172
|
+
elif can_buffer and isinstance(bio, SupportsReadinto):
|
|
173
|
+
readinto = ensure_async(bio.readinto, threaded=True)
|
|
166
174
|
use_readinto = True
|
|
175
|
+
elif isinstance(bio, SupportsRead):
|
|
176
|
+
read = ensure_async(bio.read, threaded=True)
|
|
167
177
|
else:
|
|
168
|
-
|
|
178
|
+
readinto = ensure_async(bio.readinto, threaded=True)
|
|
179
|
+
async def read(_):
|
|
180
|
+
buf = bytearray(chunksize)
|
|
181
|
+
length = await readinto(buf)
|
|
182
|
+
if length == chunksize:
|
|
183
|
+
return buf
|
|
184
|
+
return buf[:length]
|
|
169
185
|
callback = ensure_async(callback) if callable(callback) else None
|
|
170
186
|
if use_readinto:
|
|
171
187
|
buf = bytearray(chunksize)
|
|
@@ -211,7 +227,7 @@ async def bio_chunk_async_iter(
|
|
|
211
227
|
|
|
212
228
|
|
|
213
229
|
def bio_skip_iter(
|
|
214
|
-
bio: SupportsRead[Buffer] | Callable[[int], Buffer],
|
|
230
|
+
bio: SupportsRead[Buffer] | SupportsReadinto | Callable[[int], Buffer],
|
|
215
231
|
/,
|
|
216
232
|
size: int = -1,
|
|
217
233
|
chunksize: int = COPY_BUFSIZE,
|
|
@@ -282,7 +298,7 @@ def bio_skip_iter(
|
|
|
282
298
|
|
|
283
299
|
|
|
284
300
|
async def bio_skip_async_iter(
|
|
285
|
-
bio: SupportsRead[Buffer] | Callable[[int], Buffer | Awaitable[Buffer]],
|
|
301
|
+
bio: SupportsRead[Buffer] | SupportsReadinto | Callable[[int], Buffer | Awaitable[Buffer]],
|
|
286
302
|
/,
|
|
287
303
|
size: int = -1,
|
|
288
304
|
chunksize: int = COPY_BUFSIZE,
|
|
@@ -293,7 +309,7 @@ async def bio_skip_async_iter(
|
|
|
293
309
|
callback = ensure_async(callback) if callable(callback) else None
|
|
294
310
|
length: int
|
|
295
311
|
try:
|
|
296
|
-
seek = ensure_async(getattr(bio, "seek"))
|
|
312
|
+
seek = ensure_async(getattr(bio, "seek"), threaded=True)
|
|
297
313
|
curpos = await seek(0, 1)
|
|
298
314
|
if size > 0:
|
|
299
315
|
length = (await seek(size, 1)) - curpos
|
|
@@ -303,9 +319,9 @@ async def bio_skip_async_iter(
|
|
|
303
319
|
if chunksize <= 0:
|
|
304
320
|
chunksize = COPY_BUFSIZE
|
|
305
321
|
if callable(bio):
|
|
306
|
-
read = ensure_async(bio)
|
|
322
|
+
read = ensure_async(bio, threaded=True)
|
|
307
323
|
elif hasattr(bio, "readinto"):
|
|
308
|
-
readinto = ensure_async(bio.readinto)
|
|
324
|
+
readinto = ensure_async(bio.readinto, threaded=True)
|
|
309
325
|
buf = bytearray(chunksize)
|
|
310
326
|
if size > 0:
|
|
311
327
|
while size >= chunksize:
|
|
@@ -329,7 +345,7 @@ async def bio_skip_async_iter(
|
|
|
329
345
|
await callback(length)
|
|
330
346
|
yield length
|
|
331
347
|
else:
|
|
332
|
-
read = ensure_async(bio.read)
|
|
348
|
+
read = ensure_async(bio.read, threaded=True)
|
|
333
349
|
if size > 0:
|
|
334
350
|
while size:
|
|
335
351
|
readsize = min(chunksize, size)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|