Don't compress common filetypes which are already compressed
This commit is contained in:
@@ -350,13 +350,18 @@ def pack(
|
|||||||
_compress_level_orig = zlib.Z_DEFAULT_COMPRESSION
|
_compress_level_orig = zlib.Z_DEFAULT_COMPRESSION
|
||||||
zlib.Z_DEFAULT_COMPRESSION = compress_level
|
zlib.Z_DEFAULT_COMPRESSION = compress_level
|
||||||
_compress_mode = zipfile.ZIP_DEFLATED (compress_level == 0) if zipfile.ZIP_STORED else zipfile.ZIP_DEFLATED
|
_compress_mode = zipfile.ZIP_DEFLATED (compress_level == 0) if zipfile.ZIP_STORED else zipfile.ZIP_DEFLATED
|
||||||
|
if _compress_mode == zipfile.ZIP_STORED:
|
||||||
|
is_compressed_filetype = lambda fn: False
|
||||||
|
else:
|
||||||
|
from bam.utils.system import is_compressed_filetype
|
||||||
|
|
||||||
with zipfile.ZipFile(blendfile_dst.decode('utf-8'), 'w', _compress_mode) as zip_handle:
|
with zipfile.ZipFile(blendfile_dst.decode('utf-8'), 'w', _compress_mode) as zip_handle:
|
||||||
for fn in path_temp_files:
|
for fn in path_temp_files:
|
||||||
yield report(" %s: %r -> <archive>\n" % (colorize("copying", color='blue'), fn))
|
yield report(" %s: %r -> <archive>\n" % (colorize("copying", color='blue'), fn))
|
||||||
zip_handle.write(
|
zip_handle.write(
|
||||||
fn.decode('utf-8'),
|
fn.decode('utf-8'),
|
||||||
arcname=os.path.relpath(fn[:-1], base_dir_dst_temp).decode('utf-8'))
|
arcname=os.path.relpath(fn[:-1], base_dir_dst_temp).decode('utf-8'),
|
||||||
|
)
|
||||||
os.remove(fn)
|
os.remove(fn)
|
||||||
|
|
||||||
shutil.rmtree(base_dir_dst_temp)
|
shutil.rmtree(base_dir_dst_temp)
|
||||||
@@ -368,14 +373,11 @@ def pack(
|
|||||||
yield report(" %s: %r\n" % (colorize("source missing", color='red'), src))
|
yield report(" %s: %r\n" % (colorize("source missing", color='red'), src))
|
||||||
else:
|
else:
|
||||||
yield report(" %s: %r -> <archive>\n" % (colorize("copying", color='blue'), src))
|
yield report(" %s: %r -> <archive>\n" % (colorize("copying", color='blue'), src))
|
||||||
zip_handle.write(src.decode('utf-8'),
|
zip_handle.write(
|
||||||
arcname=os.path.relpath(dst, base_dir_dst).decode('utf-8'))
|
src.decode('utf-8'),
|
||||||
|
arcname=os.path.relpath(dst, base_dir_dst).decode('utf-8'),
|
||||||
"""
|
compress_type=zipfile.ZIP_STORED if is_compressed_filetype(dst) else _compress_mode,
|
||||||
_dbg(b"")
|
)
|
||||||
_dbg(b"REAL_FILE: " + dst)
|
|
||||||
_dbg(b"RELATIVE_FILE: " + os.path.relpath(dst, base_dir_dst))
|
|
||||||
"""
|
|
||||||
|
|
||||||
zlib.Z_DEFAULT_COMPRESSION = _compress_level_orig
|
zlib.Z_DEFAULT_COMPRESSION = _compress_level_orig
|
||||||
del _compress_level_orig, _compress_mode
|
del _compress_level_orig, _compress_mode
|
||||||
|
@@ -91,3 +91,36 @@ def write_json_to_file(path, data):
|
|||||||
# optional (pretty)
|
# optional (pretty)
|
||||||
sort_keys=True, indent=4, separators=(',', ': '),
|
sort_keys=True, indent=4, separators=(',', ': '),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def is_compressed_filetype(filepath):
|
||||||
|
"""
|
||||||
|
Use to check if we should compress files in a zip.
|
||||||
|
"""
|
||||||
|
# for now, only include files which Blender is likely to reference
|
||||||
|
import os
|
||||||
|
assert(isinstance(filepath, bytes))
|
||||||
|
return os.path.splitext(filepath)[1].lower() in {
|
||||||
|
# images
|
||||||
|
b'.exr',
|
||||||
|
b'.jpg', b'.jpeg',
|
||||||
|
b'.png',
|
||||||
|
|
||||||
|
# audio
|
||||||
|
b'.aif', b'.aiff',
|
||||||
|
b'.mp3',
|
||||||
|
b'.ogg', b'.ogv',
|
||||||
|
b'.wav',
|
||||||
|
|
||||||
|
# video
|
||||||
|
b'.avi',
|
||||||
|
b'.mkv',
|
||||||
|
b'.mov',
|
||||||
|
b'.mpg', b'.mpeg',
|
||||||
|
|
||||||
|
# archives
|
||||||
|
# '.bz2', '.tbz',
|
||||||
|
# '.gz', '.tgz',
|
||||||
|
# '.zip',
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user