프로그래밍/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

'프로그래밍 > Python' 카테고리의 다른 글

[Python3] ZIP Function  (0) 2023.01.12
Using Slack Webhook in Python  (0) 2022.08.17
Using Rotating-Logging in Python  (0) 2022.08.17
FTP Sending From Memory (Python)  (0) 2022.08.17
Python 실행 파일 만들기  (0) 2021.06.29