簡體   English   中英

python tarfile 生成的大尺寸 tar 文件

[英]Large size of the tar files generated by python tarfile

使用webdataset生成一些 tar 文件后,我在 select 一個名為000000.tar (18MB) 的 tar 文件(webdataset shard)解壓縮,然后在 Z2591C98B70119FE624898B1E424B5 命令中的 Z2591C98B70119FE624898B1E424B5 命令中重新打包成一個新的 tar 文件example.tar (15MB)。 重新打包的 tar 文件example.tar比原始 tar 文件000000.tar小 3MB。 我認為這兩個 tarfile 包含完全相同的內容。 而且我不知道為什么000000.tarexample.tar大。

這個問題導致webdataset生成的tarfile占用更多的磁盤空間,效率低下。 實際上, webdataset使用 python 內置的tarfile庫來生成 tarfile。 python 內置tarfile庫和 shell 中的tar命令之間一定有什么不同。 但我不知道如何弄清楚。

  • 補充:

我將這兩個文件( 000000.tarexample.tar )放在Google Drive中。 我在下面提供了我用來生成example.tar的命令。

(base) {22-09-01 2:25}vm:~/playground chenyaofo% ls -lha
total 18M
drwxrwxr-x  2 chenyaofo chenyaofo 4.0K Sep  1 02:25 .
drwxr-xr-x 39 chenyaofo chenyaofo 4.0K Sep  1 02:25 ..
-rw-rw-r--  1 chenyaofo chenyaofo  18M Sep  1 02:19 000000.tar
(base) {22-09-01 2:25}vm:~/playground chenyaofo% mkdir images
(base) {22-09-01 2:25}vm:~/playground chenyaofo% tar -xf 000000.tar -C images
(base) {22-09-01 2:26}vm:~/playground chenyaofo% tar -cf example.tar -C images .
(base) {22-09-01 2:26}vm:~/playground chenyaofo% ls -lha
total 33M
drwxrwxr-x  3 chenyaofo chenyaofo 4.0K Sep  1 02:26 .
drwxr-xr-x 39 chenyaofo chenyaofo 4.0K Sep  1 02:26 ..
-rw-rw-r--  1 chenyaofo chenyaofo  18M Sep  1 02:19 000000.tar
-rw-rw-r--  1 chenyaofo chenyaofo  15M Sep  1 02:26 example.tar
drwxrwxr-x  2 chenyaofo chenyaofo 160K Sep  1 02:26 images

另外,我提供了一些系統信息和庫信息。 我使用 Ubuntu 22.04 Linux vm 5.15.0-39-generic #42-Ubuntu SMP Thu Jun 9 23:42:32 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux 我使用python=3.9.13webdataset=0.2.20來生成 webdataset 分片。 tar 命令的版本是tar (GNU tar) 1.34

Github Gist中提供了用於生成 webdataset 分片的代碼。

我可能找到了大 tarfile 大小的原因。

我在Stackoverflow中發現了一個類似的問題。 簡而言之,python (>=3.8) 內置庫默認使用tarfile.PAX_FORMAT來存儲 tarfile。 相比之下,Linux 上tar命令的默認格式是tarfile.GNU_FORMAT 在此處此處查看有關這兩種格式的更多信息。 PAX_FORMAT的 tar header 比GNU_FORMAT ,因此導致 tarfile 大小較大。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM