ConceptPortal-public/rsconcept/backend/shared/utility.py
Ivan 642a94b565
Some checks are pending
Backend CI / build (3.12) (push) Waiting to run
Frontend CI / build (22.x) (push) Waiting to run
R: restructure backend DB
Warning! This will reset database migrations. Data should be imported manually
2024-07-25 19:12:59 +03:00

22 lines
660 B
Python

''' Utility functions. '''
import json
from io import BytesIO
from zipfile import ZipFile
def read_zipped_json(data, json_filename: str) -> dict:
''' Read JSON from zipped data '''
with ZipFile(data, 'r') as archive:
json_data = archive.read(json_filename)
result: dict = json.loads(json_data)
return result
def write_zipped_json(json_data: dict, json_filename: str) -> bytes:
''' Write json JSON to bytes buffer '''
content = BytesIO()
data = json.dumps(json_data, indent=4, ensure_ascii=False)
with ZipFile(content, 'w') as archive:
archive.writestr(json_filename, data=data)
return content.getvalue()