Skip to content

Instantly share code, notes, and snippets.

@njsmith
Last active November 26, 2019 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save njsmith/0f5caed5c97b623e9ef4d2fa1b380e9a to your computer and use it in GitHub Desktop.
Save njsmith/0f5caed5c97b623e9ef4d2fa1b380e9a to your computer and use it in GitHub Desktop.
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