如何在同一zip文件中混合压缩类型和存储类型的文件

时间:2019-01-20 17:13:25

标签: bash shell zipfile

我正在寻找一个shell命令(最好是 one-liner ),该命令将创建一个压缩和存储内容(通过 stored 表示)的zip文件。 未压缩,如官方文档中的链接1)所述。

.ZIP File Format Specification使您可以自由混合各种压缩类型,包括仅存储文件:

  

4.1.8每个放入ZIP文件的数据文件都可以进行压缩,存储,加密或数字签名,而与其他方式无关   同一ZIP文件中的数据文件都已存档。

如果有必要,可以通过在IANA注册中心application/zip下注册的媒体类型来确认这种技术可能性:

  

A。本地文件头:

     

本地文件头签名4个字节(0x04034b50)..     压缩方法2个字节

到目前为止,我尝试了几个zip参数(-f -u -U,..)均未成功

理想情况下,该命令将压缩文本文件,并存储二进制内容(按文件扩展名区分)(例如,将html,css,js视为文本,将jpg,ico,jar视为二进制)。

2 个答案:

答案 0 :(得分:6)

您是否正在寻找-n标志?

-n suffixes
--suffixes suffixes

 Do not attempt to compress files named with the given suffixes. Such files are simply
 stored (0% compression) in the output zip file, so that zip doesn't waste its time trying
 to compress them. The suffixes are separated by either colons or semicolons. For example:

       zip -rn .Z:.zip:.tiff:.gif:.snd  foo foo

 will copy everything from foo into foo.zip, but will store any files that end in .Z,
 .zip, .tiff, .gif, or .snd without trying to compress them.

答案 1 :(得分:2)

除了@cody的答案,您还可以使用-g-0在每个文件(组)的基础上执行此操作。像这样:

zip archive.zip compressme.txt
zip -g archive.zip -0 dontcompressme.jpg
-#
(-0, -1, -2, -3, -4, -5, -6, -7, -8, -9)
       Regulate the speed of compression using the specified digit #, where -0
       indicates no compression (store all files), -1 indicates the fastest 
       compression speed (less compression) and -9 indicates the slowest
       compression speed (optimal compression, ignores the suffix list).
       The default compression level is -6.

-g
--grow
       Grow  (append  to) the specified zip archive, instead of creating a new one.
       If this operation fails, zip attempts to restore the archive to its original
       state. If the restoration fails, the archive might become corrupted.
       This option is ignored when there's no existing archive or when at least
       one archive member must be updated or deleted.