def
export_data(
jsc_file_path:
str
, encryption_key_str:
str
, output_file_path:
str
)
-
> Optional[
tuple
]:
logger.info(
"Starting export_data..."
)
code, status
=
check_file(jsc_file_path,
".JSC"
,
True
)
if
code !
=
"OK"
:
return
code, status
jsc_file
=
open
(jsc_file_path,
"rb"
)
jsc_file_data
=
jsc_file.read()
jsc_file.close()
logger.info(f
"Decrypting with key = {encryption_key_str}"
)
output_data
=
xxtea.decrypt(jsc_file_data, encryption_key_str, padding
=
False
)
if
len
(output_data)
=
=
0
:
return
"WRONG_KEY"
,
"Invalid encryption key!"
is_gzip_file
=
True
try
:
output_data
=
zlib.decompress(output_data,
32
+
15
)
logger.info(
"IT IS a GZIP archive."
)
except
zlib.error as error:
logger.info(
"It's NOT a GZIP archive."
)
is_gzip_file
=
False
if
not
is_gzip_file:
try
:
zip_file
=
io.BytesIO(output_data)
ZipFile(zip_file)
output_file_path
+
=
".zip"
logger.info(
"IT IS a ZIP archive."
)
except
BadZipFile as error:
logger.info(
"It is NOT a ZIP archive."
)
js_file
=
open
(output_file_path,
"wb"
)
js_file.write(output_data)
js_file.close()
logger.info(f
"File exported: {output_file_path}"
)
return
"OK"
, ""