compression.py: buffered copy (#31533)

This commit is contained in:
Harmen Stoppels 2022-07-12 16:49:59 +02:00 committed by GitHub
parent a4f0522468
commit 74e2625dcf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -112,7 +112,7 @@ def _bunzip2(archive_file):
import bz2 import bz2
f_bz = bz2.BZ2File(archive_file, mode='rb') f_bz = bz2.BZ2File(archive_file, mode='rb')
with open(archive_out, 'wb') as ar: with open(archive_out, 'wb') as ar:
ar.write(f_bz.read()) shutil.copyfileobj(f_bz, ar)
f_bz.close() f_bz.close()
else: else:
shutil.copy(archive_file, copy_path) shutil.copy(archive_file, copy_path)
@ -139,7 +139,8 @@ def _gunzip(archive_file):
import gzip import gzip
f_in = gzip.open(archive_file, "rb") f_in = gzip.open(archive_file, "rb")
with open(destination_abspath, "wb") as f_out: with open(destination_abspath, "wb") as f_out:
f_out.write(f_in.read()) shutil.copyfileobj(f_in, f_out)
f_in.close()
else: else:
_system_gunzip(archive_file) _system_gunzip(archive_file)
return destination_abspath return destination_abspath
@ -200,7 +201,7 @@ def _lzma_decomp(archive_file):
archive_out = os.path.join(os.getcwd(), decompressed_file) archive_out = os.path.join(os.getcwd(), decompressed_file)
with open(archive_out, 'wb') as ar: with open(archive_out, 'wb') as ar:
with lzma.open(archive_file) as lar: with lzma.open(archive_file) as lar:
ar.write(lar.read()) shutil.copyfileobj(lar, ar)
else: else:
if is_windows: if is_windows:
return _7zip(archive_file) return _7zip(archive_file)