Skip to content

Instantly share code, notes, and snippets.

@vitaliihonta
Last active April 14, 2022 08:53
Show Gist options
  • Save vitaliihonta/b9be77deb0dfea1e9a411e695e6f15c9 to your computer and use it in GitHub Desktop.
Save vitaliihonta/b9be77deb0dfea1e9a411e695e6f15c9 to your computer and use it in GitHub Desktop.
from aiohttp.client import ClientSession
from aiohttp.streams import AsyncStreamIterator
from functools import partial
import asyncio
async def main():
async with ClientSession() as session:
# use the file from gist below
url = "https://gist.githubusercontent.com/vitaliihonta/b9be77deb0dfea1e9a411e695e6f15c9/raw/5fbf72842bff7f74ce06479d7e0d06f5af334f86/example.txt"
async with session.get(url) as resp:
async for line in AsyncStreamIterator(partial(resp.content.readuntil, b'ab')):
print(line)
if __name__ == '__main__':
asyncio.get_event_loop().run_until_complete(main())
11ab
22ab
33ab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment