How to stream a gzip built on the fly in Python?
问题 I'd like to stream a big log file over the network using asyncio. I retrieve the data from the database, format it, compress it using python's zlib and stream it over the network. Here is basically the code I use: @asyncio.coroutine def logs(requests): # ... yield from resp.prepare(request) # gzip magic number and compression format resp.write(b'\x1f\x8b\x08\x00\x00\x00\x00\x00') compressor = compressobj() for row in rows: ip, uid, date, url, answer, volume = row NCSA_ROW = '{} {} - [{}] "GET