Python shutil.make_archive 导致文件比原始文件大

问题描述

我想对一个 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'

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...