代码之家  ›  专栏  ›  技术社区  ›  Eugène Adell

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

  •  3
  • Eugène Adell  · 技术社区  · 6 年前

    我正在寻找shell命令(最好是 一班轮 )这将创建一个压缩和存储内容的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 回复  |  直到 6 年前
        1
  •  6
  •   cody    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.
    
        2
  •  2
  •   Aurel Bílý    6 年前

    添加到@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.