You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.3 KiB
36 lines
1.3 KiB
|
|
import os
|
|
import zipfile
|
|
|
|
|
|
def get_file_name(path):
|
|
return os.path.splitext(os.path.basename(path))[0]
|
|
#将zip文件拆分成多个zip字文件
|
|
def create_split_zip(src_zip_path, dst_dir, max_size,suffix="zip"):
|
|
cur_file_Name=get_file_name(src_zip_path)
|
|
files=[]
|
|
with zipfile.ZipFile(src_zip_path, 'r') as z:
|
|
file_list = z.infolist()
|
|
chunk_number = 1
|
|
dst_zip = None
|
|
file_size=0
|
|
for file_info in file_list:
|
|
file_data = z.read(file_info.filename)
|
|
file_size += file_info.compress_size
|
|
if file_size >= max_size :
|
|
if dst_zip:
|
|
dst_zip.close()
|
|
dst_zip=None
|
|
chunk_number+=1
|
|
file_size=0
|
|
if dst_zip == None :
|
|
fileName=f'{cur_file_Name}{chunk_number}'
|
|
files.append(fileName)
|
|
dst_zip_name = os.path.join(dst_dir, f'{fileName}.{suffix}')
|
|
if os.path.exists(dst_zip_name):
|
|
os.remove(dst_zip_name)
|
|
dst_zip = zipfile.ZipFile(dst_zip_name, 'w', zipfile.ZIP_DEFLATED)
|
|
dst_zip.writestr(file_info.filename, file_data)
|
|
if dst_zip != None :
|
|
dst_zip.close()
|
|
return files
|