Answer the question
In order to leave comments, you need to log in
How to work with zip archive in memory in Python without using disk?
Once a minute I receive an http zip archive. I open it, there are 8 text files, I write them to disk and then I work with them.
I am using this code:
responce = requests.get(url)
if responce.status_code == 200:
zf = zipfile.ZipFile(io.BytesIO(responce.content))
zf.extractall(DIR_NAME)
return True
Answer the question
In order to leave comments, you need to log in
Everything turned out to be easier than I thought. I did this: (actually the same as suggested above):
files = {}
responce = requests.get(url)
with zipfile.ZipFile(io.BytesIO(responce.content), 'r') as zf:
file_name = zf.namelist()
for i in file_name:
files[i] = []
with zf.open(i) as f:
for j in f.readlines():
files[i].append(j.rstrip().decode('cp1251'))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question