Last active
November 26, 2019 21:56
-
-
Save njsmith/0f5caed5c97b623e9ef4d2fa1b380e9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from byoio import receive_until, receive_some | |
async def decode_chunked(stream, buf): | |
while True: | |
header = await receive_until(stream, buf, b"\r\n") | |
to_read = int(header.strip()) # FIXME: proper validation | |
if to_read == 0: | |
# FIXME: read trailers | |
return | |
while to_read > 0: | |
piece = await receive_some(stream, buf, to_read) | |
to_read -= len(piece) | |
yield piece |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment