|
@@ -14,23 +14,17 @@
|
|
|
|
|
|
import os
|
|
|
import tarfile
|
|
|
+import gzip
|
|
|
|
|
|
def compress_file_tar(file_path, output_filename):
|
|
|
|
|
|
if not output_filename.endswith('.tar.gz'):
|
|
|
output_filename += '.tar.gz'
|
|
|
-
|
|
|
- with tarfile.open(output_filename, "w:gz", format=tarfile.GNU_FORMAT) as tar:
|
|
|
-
|
|
|
-
|
|
|
- file_name = os.path.basename(file_path)
|
|
|
-
|
|
|
- with open(file_path, 'rb') as file_to_add:
|
|
|
-
|
|
|
- tar_info = tarfile.TarInfo(name=file_name)
|
|
|
-
|
|
|
- tar_info.size = os.path.getsize(file_path)
|
|
|
- tar.addfile(tar_info, fileobj=file_to_add)
|
|
|
+ with gzip.open(output_filename, 'wb') as gzip_file:
|
|
|
+
|
|
|
+ with open(file_path, 'rb') as file_to_compress:
|
|
|
+
|
|
|
+ gzip_file.writelines(file_to_compress)
|
|
|
|
|
|
def compress_tar(folder_path, output_filename):
|
|
|
|