프로그래밍/Python
Zip Extract on Memory (Python)
bluecandyg
2022. 8. 17. 13:45
- 물리적 경로에 압축 해제 하지 않고 메모리에 Bytes로 해제 할 경우 사용
- 아래는 압축 해제 후 Json Load 까지 진행
def open_zip_file(file_path : str):
logger.info('# Zip File Extract START.')
json_data = None
with zipfile.ZipFile(file_path, 'r') as json_zip_file:
for file_name in json_zip_file.namelist():
if '.json' in file_name.lower():
zip_data = json_zip_file.read(file_name).decode('UTF-8')
json_data = json.loads(zip_data)
return json_data
return json_data