python-filewrap 0.0.3__tar.gz → 0.0.3.1__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.0.3 → python_filewrap-0.0.3.1}/PKG-INFO +1 -1
- {python_filewrap-0.0.3 → python_filewrap-0.0.3.1}/filewrap/__init__.py +14 -10
- {python_filewrap-0.0.3 → python_filewrap-0.0.3.1}/pyproject.toml +1 -1
- {python_filewrap-0.0.3 → python_filewrap-0.0.3.1}/LICENSE +0 -0
- {python_filewrap-0.0.3 → python_filewrap-0.0.3.1}/filewrap/py.typed +0 -0
- {python_filewrap-0.0.3 → python_filewrap-0.0.3.1}/readme.md +0 -0
|
@@ -266,47 +266,51 @@ async def bio_skip_bytes_async(
|
|
|
266
266
|
|
|
267
267
|
def bytes_iter_to_reader(it: Iterable[bytes | bytearray], /) -> SupportsRead[bytes]:
|
|
268
268
|
get_next = iter(it).__next__
|
|
269
|
-
|
|
269
|
+
at_eof = False
|
|
270
|
+
unconsumed: bytearray = bytearray(b"")
|
|
270
271
|
def read(n=-1):
|
|
271
|
-
nonlocal unconsumed
|
|
272
|
-
if n == 0:
|
|
272
|
+
nonlocal at_eof, unconsumed
|
|
273
|
+
if at_eof or n == 0:
|
|
273
274
|
return b""
|
|
274
275
|
try:
|
|
275
276
|
if n < 0:
|
|
276
277
|
while True:
|
|
277
|
-
unconsumed
|
|
278
|
+
unconsumed += get_next()
|
|
278
279
|
else:
|
|
279
280
|
while n > len(unconsumed):
|
|
280
|
-
unconsumed
|
|
281
|
+
unconsumed += get_next()
|
|
281
282
|
b, unconsumed = unconsumed[:n], unconsumed[n:]
|
|
282
283
|
return bytes(b)
|
|
283
284
|
except StopIteration:
|
|
285
|
+
at_eof = True
|
|
284
286
|
return bytes(unconsumed)
|
|
285
287
|
reprs = f"<reader for {it!r}>"
|
|
286
288
|
return type("reader", (), {"read": staticmethod(read), "__repr__": staticmethod(lambda: reprs)})()
|
|
287
289
|
|
|
288
290
|
|
|
289
291
|
def bytes_iter_to_reader_async(it: Iterable[bytes | bytearray] | AsyncIterable[bytes | bytearray], /) -> SupportsRead[bytes]:
|
|
290
|
-
unconsumed = bytearray(b"")
|
|
291
292
|
if isinstance(it, AsyncIterable):
|
|
292
293
|
get_next = aiter(it).__anext__
|
|
293
294
|
else:
|
|
294
295
|
sync_next = iter(it).__next__
|
|
295
296
|
get_next = lambda: to_thread(sync_next)
|
|
297
|
+
at_eof = False
|
|
298
|
+
unconsumed: bytearray = bytearray(b"")
|
|
296
299
|
async def read(n=-1):
|
|
297
|
-
nonlocal unconsumed
|
|
298
|
-
if n == 0:
|
|
300
|
+
nonlocal at_eof, unconsumed
|
|
301
|
+
if at_eof or n == 0:
|
|
299
302
|
return b""
|
|
300
303
|
try:
|
|
301
304
|
if n < 0:
|
|
302
305
|
while True:
|
|
303
|
-
unconsumed
|
|
306
|
+
unconsumed += await get_next()
|
|
304
307
|
else:
|
|
305
308
|
while n > len(unconsumed):
|
|
306
|
-
unconsumed
|
|
309
|
+
unconsumed += await get_next()
|
|
307
310
|
b, unconsumed = unconsumed[:n], unconsumed[n:]
|
|
308
311
|
return bytes(b)
|
|
309
312
|
except StopIteration:
|
|
313
|
+
at_eof = True
|
|
310
314
|
return bytes(unconsumed)
|
|
311
315
|
reprs = f"<reader for {it!r}>"
|
|
312
316
|
return type("reader", (), {"read": staticmethod(read), "__repr__": staticmethod(lambda: reprs)})()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|