gzip的一个小坑

使用gzip压缩游戏资源的时候踩了一个小坑。

gzip命令默认会将被压缩文件的名称写入到zip包中,所以文件img.png和其副本img_copy.png压缩后的md5值就不相同了。

简单的测试脚本如下:

#! /bin/bash
echo "the md5 of original png :"
md5 /temp/test/img.png
md5 /temp/test/img_copy.png

gzip -2 -5  -c /temp/test/img.png > /temp/test/img.zip
gzip -2 -5  -c /temp/test/img_copy.png > /temp/test/img_copy.zip

echo "the md5 of zip :"
md5 /temp/test/img.zip
md5 /temp/test/img_copy.zip

执行结果如下:

the md5 of original png :
MD5 (/temp/test/img.png) = b00a1862e781da625df40658d54f48bb
MD5 (/temp/test/img_copy.png) = b00a1862e781da625df40658d54f48bb
the md5 of zip :
MD5 (/temp/test/img.zip) = d17c8b512e0eb2c0df46d1cf294d11ba
MD5 (/temp/test/img_copy.zip) = a1bc3d6f0d2c0cb174ca99190d8b6744

压缩前两个png的md5值是相同的,压缩后的两个zip的md5值确实不同了。

使用gzip –help查看命令参数:

usage: gzip [-123456789acdfhklLNnqrtVv] [-S .suffix] [ [ …]]
-1 –fast fastest (worst) compression
-2 .. -8 set compression level
-9 –best best (slowest) compression
-c –stdout write to stdout, keep original files
–to-stdout
-d –decompress uncompress files
–uncompress
-f –force force overwriting & compress links
-h –help display this help
-k –keep don’t delete input files during operation
-l –list list compressed file contents
-N –name save or restore original file name and time stamp
-n –no-name don’t save original file name or time stamp
-q –quiet output no warnings
-r –recursive recursively compress files in directories
-S .suf use suffix .suf instead of .gz
–suffix .suf
-t –test test compressed file
-V –version display program version
-v –verbose print extra statistics

关键的一句是: -n –no-name don’t save original file name or time stamp
gzip 命令中设置-n参数,压缩时不保存文件名称。
更改后的压缩命令如下:

gzip -2 -5  -c -n /temp/test/img.png > /temp/test/img.zip

PS:测试环境为Mac,自带gzip、md5命令。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值