0
我想使用asyncio通過網絡傳輸大型日誌文件。我從數據庫中檢索數據,對其進行格式化,使用python的zlib對其進行壓縮並通過網絡進行流式處理。如何流化Python中構建的gzip?
這裏基本上是我使用的代碼:
@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 {} HTTP/1.0" {} {}\n'
row = NCSA_ROW.format(ip, uid, date, url, answer, volume)
row = row.encode('utf-8')
data = compressor.compress(row)
resp.write(data)
resp.write(compressor.flush())
return resp
,我檢索不能gunzip解,並用zcat提高以下錯誤打開文件:
gzip: out.gz: unexpected end of file