问题描述
我想对一个 49 GB 的文件夹进行 tar 压缩,以便对其进行压缩,但之后不会保留。
我使用下面的代码创建一个临时目录(我选择了父路径)然后shutil.make_archive
:
import tempfile
import shutil
with tempfile.TemporaryDirectory(dir=temp_dir_path) as temp_output_dir:
output_path = shutil.make_archive(temp_output_dir,"tar",dir_to_tar)
然而,生成的 tar 文件的大小比我 du -sh
原始文件夹时要大。当它达到 51 GB 时,我停止了代码。
我用错了吗?
解决方法
tar (tape archive) 格式不压缩,它只是将文件“归档”在一起(它基本上只是一个目录结构和它包含的文件推到一个文件中)。从定义上讲,它比原始数据大。
如果您希望压缩 tarball 使其最终小于原始数据,请使用压缩的
The above script refreshes the first excel file and then throws an error.
Error : Object invoked disconnected from its clients.
参数之一 to make_archive
,例如format
(更快、更差的压缩、最便携)或 'gztar'
(更慢、最佳压缩、便携性稍差)而不仅仅是 'xztar'
。