sigyllly commited on
Commit
0344861
·
verified ·
1 Parent(s): d6ebe0b

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +6 -6
utils.py CHANGED
@@ -8,7 +8,6 @@ import shutil
8
  import tempfile
9
  import requests
10
  import json
11
- import py7zr # Import the py7zr library
12
 
13
  BASE_DIR = os.path.abspath(os.path.dirname(__file__))
14
  UPLOAD_FOLDER = os.path.join(BASE_DIR, "uploads")
@@ -253,13 +252,14 @@ def process_request(request):
253
  )
254
 
255
  # Create a .7z archive with ultra compression and LZMA2
256
- seven_zip_filename = generate_random_string() + ".7z"
257
- seven_zip_filepath = os.path.join(temp_dir, seven_zip_filename)
258
- with py7zr.SevenZipFile(seven_zip_filepath, 'w', filters=[{'id': 'LZMA2', 'level': 9}]) as archive:
259
- archive.write(modified_pe_path, os.path.basename(modified_pe_path))
 
260
 
261
  # Return the .7z file in the response
262
- return send_file(seven_zip_filepath, as_attachment=True, download_name=seven_zip_filename)
263
 
264
  except Exception as e:
265
  current_app.logger.error(f"An error occurred: {str(e)}")
 
8
  import tempfile
9
  import requests
10
  import json
 
11
 
12
  BASE_DIR = os.path.abspath(os.path.dirname(__file__))
13
  UPLOAD_FOLDER = os.path.join(BASE_DIR, "uploads")
 
252
  )
253
 
254
  # Create a .7z archive with ultra compression and LZMA2
255
+ archive_name = generate_random_string() + ".7z"
256
+ archive_path = os.path.join(temp_dir, archive_name)
257
+ subprocess.run([
258
+ "7z", "a", "-t7z", "-mx=9", "-m0=LZMA2", archive_path, modified_pe_path
259
+ ], check=True)
260
 
261
  # Return the .7z file in the response
262
+ return send_file(archive_path, as_attachment=True, download_name=archive_name)
263
 
264
  except Exception as e:
265
  current_app.logger.error(f"An error occurred: {str(e)}")