diff options
author | Damien George <damien@micropython.org> | 2020-08-22 16:39:15 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2022-06-24 17:04:57 +1000 |
commit | db7682e02d3ffd3338f20effc9ad4735a48bf774 (patch) | |
tree | 622dec3e91f0a9fc73ff0f6f0505e504bc8b50a5 /extmod/uasyncio/stream.py | |
parent | 2a2589738c7bcc0a318f9054562de9a62575d8cc (diff) |
extmod/uasyncio: Implement stream read(-1) to read all data up to EOF.
Fixes issue #6355.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'extmod/uasyncio/stream.py')
-rw-r--r-- | extmod/uasyncio/stream.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/extmod/uasyncio/stream.py b/extmod/uasyncio/stream.py index 750d8e974..785e43555 100644 --- a/extmod/uasyncio/stream.py +++ b/extmod/uasyncio/stream.py @@ -26,9 +26,17 @@ class Stream: # TODO yield? self.s.close() - async def read(self, n): - yield core._io_queue.queue_read(self.s) - return self.s.read(n) + async def read(self, n=-1): + r = b"" + while True: + yield core._io_queue.queue_read(self.s) + r2 = self.s.read(n) + if r2 is not None: + if n >= 0: + return r2 + if not len(r2): + return r + r += r2 async def readinto(self, buf): yield core._io_queue.queue_read(self.s) |