python-filewrap 0.0.3__py3-none-any.whl → 0.0.3.1__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 CHANGED
@@ -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
- unconsumed = bytearray(b"")
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.extend(get_next())
278
+ unconsumed += get_next()
278
279
  else:
279
280
  while n > len(unconsumed):
280
- unconsumed.extend(get_next())
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.extend(await get_next())
306
+ unconsumed += await get_next()
304
307
  else:
305
308
  while n > len(unconsumed):
306
- unconsumed.extend(await get_next())
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)})()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-filewrap
3
- Version: 0.0.3
3
+ Version: 0.0.3.1
4
4
  Summary: Python file wrappers.
5
5
  Home-page: https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/python-filewrap
6
6
  License: MIT
@@ -0,0 +1,7 @@
1
+ LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
2
+ filewrap/__init__.py,sha256=MzZLsQJkjBke4XZzxjw8i5eyL7LyiGjw3M4HVyiMxeA,9893
3
+ filewrap/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ python_filewrap-0.0.3.1.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
5
+ python_filewrap-0.0.3.1.dist-info/METADATA,sha256=OO_ZWnnc6HBBvRtFXfV2kPM3zBji3dsMTRSruLtGPiI,1331
6
+ python_filewrap-0.0.3.1.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
7
+ python_filewrap-0.0.3.1.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
2
- filewrap/__init__.py,sha256=Q-2Vh8EycWNA2aEmNGKAJHHuEKpdn89JTmOKJWl21go,9765
3
- filewrap/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- python_filewrap-0.0.3.dist-info/LICENSE,sha256=o5242_N2TgDsWwFhPn7yr8YJNF7XsJM5NxUMtcT97bc,1100
5
- python_filewrap-0.0.3.dist-info/METADATA,sha256=n-AMSKOYJZ4eiVIwDEeziJkFkCjW1Mkg6jJZSrXBiyo,1329
6
- python_filewrap-0.0.3.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
7
- python_filewrap-0.0.3.dist-info/RECORD,,