async def write_to_csv(self, asset_list, header) -> io.BytesIO:
buffer = io.BytesIO()
with zipfile.ZipFile(buffer, "w", zipfile.ZIP_DEFLATED, False) as zf:
with zf.open("result.csv", "w") as f:
writer = csv.writer(io.TextIOWrapper(f, newline="", write_through=True))
writer.writerow(header)
for asset in asset_list:
writer.writerow(asset)
buffer.seek(0)
return buffer
I tried using the aiocsv and aiozipstream modules to make the csv and zip creation part non-blocking in the above code, which is the blocking part, but it didn't work as expected.
How can I implement the above code asynchronously?
Any help would be appriciated.