Guest User

server.py

a guest
Jun 23rd, 2021
1,096
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. from aiohttp import web
  2. import asyncio
  3.  
  4. data = open("interlaced.png", "rb").read()
  5.  
  6. # offsets found via trial and error
  7. # (although I now know how to calculate these programmatically, I might put something on github later)
  8. a = data[:10500]
  9. b = data[10500:33000]
  10. c = data[33000:78500]
  11. d = data[78500:]
  12.  
  13. CHUNK_SIZE = 512
  14.  
  15. async def handle(request):
  16.         response = web.StreamResponse(
  17.                 status=200,
  18.                 reason="OK",
  19.                 headers={
  20.                         "Cache-Control": "no-store"
  21.                 },
  22.         )
  23.         response.content_length = len(data)
  24.         response.content_type = "image/png"
  25.  
  26.         await response.prepare(request)
  27.  
  28.         await response.write(a)
  29.         await asyncio.sleep(3)
  30.         await response.write(b)
  31.         await asyncio.sleep(3)
  32.         await response.write(c)
  33.         await asyncio.sleep(3)
  34.         await response.write(d)
  35.         await response.write_eof()
  36.         return response
  37.  
  38.  
  39. app = web.Application()
  40. app.add_routes([
  41.         web.get('/', handle),
  42.         web.get('/image.png', handle)
  43. ])
  44.  
  45.  
  46. web.run_app(app, host="127.0.0.1", port=8081)
Advertisement
Add Comment
Please, Sign In to add comment