in src/ab/keys/data.py [0:0]
def open_binary(infile, force=False):
"""
返回解压后的二进制流
:param infile:
:param passw_fun():
:param encode:
:return:
"""
if os.path.exists(infile):
f = open(infile, "rb")
max_bytes = 2 ** 31 - 1
bytes_in = bytearray(0)
input_size = os.path.getsize(infile)
if input_size > max_bytes:
raise AlgorithmException(data="the file is too large! {}".format(infile))
with open(infile, 'rb') as f_in:
for _ in range(0, input_size, max_bytes):
bytes_in += f_in.read(max_bytes)
yield bytes_in
f.close()
else:
sec_file_path = infile + SEC_FILE_POSTFIX
if os.path.exists(sec_file_path):
if force:
outputfile = force_open(sec_file_path)
f = open(outputfile, "rb")
max_bytes = 2 ** 31 - 1
bytes_in = bytearray(0)
input_size = os.path.getsize(outputfile)
if input_size > max_bytes:
raise AlgorithmException(data="the file is too large! {}".format(outputfile))
with open(outputfile, 'rb') as f_in:
for _ in range(0, input_size, max_bytes):
bytes_in += f_in.read(max_bytes)
yield bytes_in
f.close()
else:
byte_io = decrypt_to_memory(sec_file_path)
yield byte_io.getvalue()
byte_io.close()
else:
raise AlgorithmException(data="file doesn't exist {}".format(sec_file_path))