Skip to content

Commit

Permalink
zip use process (#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
wayyoungboy authored Nov 13, 2024
1 parent afe537e commit 53dedd4
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions common/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""

from __future__ import absolute_import, division, print_function
import multiprocessing as mp

import os
import io
Expand Down Expand Up @@ -679,16 +680,22 @@ def tar_gz_to_zip(temp_dir, tar_gz_file, output_zip, password, stdio):
base_path = os.path.basename(root)
files_to_compress.append(file_path)
base_paths.append(base_path)

stdio.verbose("start pyminizip compress_multiple")
# 3. Compress the extracted files into a (possibly) encrypted zip file
zip_process = None
if password:
# Use pyminizip to create the encrypted zip file
pyminizip.compress_multiple(files_to_compress, base_paths, output_zip, password, 5) # 5 is the compression level
zip_process = mp.Process(target=pyminizip.compress_multiple, args=(files_to_compress, base_paths, output_zip, password, 5))
# pyminizip.compress_multiple(files_to_compress, base_paths, output_zip, password, 5) # 5 is the compression level
stdio.verbose("extracted files compressed into encrypted {0}".format(output_zip))
else:
# Create an unencrypted zip file
pyminizip.compress_multiple(files_to_compress, base_paths, output_zip, None, 5)
zip_process = mp.Process(target=pyminizip.compress_multiple, args=(files_to_compress, base_paths, output_zip, None, 5))
# pyminizip.compress_multiple(files_to_compress, base_paths, output_zip, None, 5)
stdio.verbose("extracted files compressed into unencrypted {0}".format(output_zip))
zip_process.start()
if zip_process is not None:
zip_process.join()

# 4. Remove the extracted directory
shutil.rmtree(extract_dir)
Expand Down

0 comments on commit 53dedd4

Please sign in to comment.