简体   繁体   English

是否有实用程序可用于估计压缩后的文件大小?

[英]Is there a utility for estimating a file's size after compression?

I would like to estimate the final size of a file, files, or a directory of files after it has been compressed. 我想估计一个文件,一个文件或一个文件目录在压缩后的最终大小。 I'm looking for a program or script that can estimate/calculate this. 我正在寻找可以估算/计算此值的程序或脚本。

Any ideas? 有任何想法吗?

Such a tool must be accessible on the command line (for Linux/Mac). 此类工具必须在命令行上可访问(对于Linux / Mac)。 It would be most useful if it would work with all or most of the commonly-used lossless compression algorithms ( gz , bzip2 , zip , etc. ). 如果它可以与所有或大多数常用的无损压缩算法( gzbzip2zip )一起bzip2 ,则将非常有用。 Bonus points if it listed the compression ratios (or of equivalent use, the resulting file size) for a variety of methods. 如果它列出了各种方法的压缩率(或等价使用的结果文件大小),则可得到加分。 I fully expect that such a tool would scan the file prior to producing output, but I want to avoid any actual compression, if possible. 我完全希望这样的工具能够在产生输出之前扫描文件,但是如果可能的话,我想避免任何实际的压缩。

If it matters, I'd prefer that this be general-purpose: 如果重要的话,我希望这是通用的:

  • It should work well for any kind of file(s), including easily-compressed ASCII text files, binary data, and everything in between. 它适用于任何类型的文件,包括易于压缩的ASCII文本文件,二进制数据以及之间的所有文件。 (Of course, this depends wildly on the compression algorithm/tool.) (当然,这很大程度上取决于压缩算法/工具。)
  • It should work with a variety of compression algorithms/tools 它应该与各种压缩算法/工具一起使用

The following BASH script does what I want for one kind of compression algorithm, but it doesn't count (I'd like an estimation ): 下面的bash脚本做什么,我想为一种压缩算法,但它并不指望(我想估计 ):

#!/bin/bash

FILES_TO_COMPRESS=`ls ./*txt`
TEMP_FILE=myData.tgz
tar -zcvf $TEMP_FILE $FILES_TO_COMPRESS
du -h $TEMP_FILE | awk '{print $1}'
rm -f $TEMP_FILE

I would primarily use this for larger files (larger than a gigabyte), which is why I want only the estimate, and not an actual compression. 我主要将它用于较大的文件(大于1 GB),这就是为什么我只需要估算而不是实际压缩的原因。

You might compress into a pipe like | wc 您可能会压缩成| wc | wc (you could use pipe(7) -s or fifo(7) -s, perhaps with bash coprocesses ) but you still need to compress. | wc (您可以使用pipe(7) -s或fifo(7) -s,也许与bash coprocesses一起使用 ),但仍需要压缩。

(Unless you are very tight on disk space, I believe it is not worth the pain) (除非您在磁盘空间上非常紧张,否则我认为这是不值得的)

Notice that not every file is genuinely compressible. 请注意,并非每个文件都是真正可压缩的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM