Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from aiohttp import web
- import asyncio
- data = open("interlaced.png", "rb").read()
- # offsets found via trial and error
- # (although I now know how to calculate these programmatically, I might put something on github later)
- a = data[:10500]
- b = data[10500:33000]
- c = data[33000:78500]
- d = data[78500:]
- CHUNK_SIZE = 512
- async def handle(request):
- response = web.StreamResponse(
- status=200,
- reason="OK",
- headers={
- "Cache-Control": "no-store"
- },
- )
- response.content_length = len(data)
- response.content_type = "image/png"
- await response.prepare(request)
- await response.write(a)
- await asyncio.sleep(3)
- await response.write(b)
- await asyncio.sleep(3)
- await response.write(c)
- await asyncio.sleep(3)
- await response.write(d)
- await response.write_eof()
- return response
- app = web.Application()
- app.add_routes([
- web.get('/', handle),
- web.get('/image.png', handle)
- ])
- web.run_app(app, host="127.0.0.1", port=8081)
Advertisement
Add Comment
Please, Sign In to add comment