How do you remove timestamp variation from gzip exports in one toolchain?
compress accepts an explicit mtime. Fixing it removes the generation timestamp as a source of header variation.
Python example and interpretation
Two compressions in one environment yield identical bytes for this payload. Across tool or setting changes, distinguish the payload digest from the archive digest.
import gzip
a=gzip.compress(b'rows',mtime=0)
[a==gzip.compress(b'rows',mtime=0),gzip.decompress(a).decode()]Result [True, 'rows']
中文
怎样在同一工具链中消除 gzip 导出时间导致的差异?
compress 允许显式传入 mtime,固定时间可消除压缩头中本次生成时间这一变化来源。
Python 算例与适用条件
同一运行环境内两次打包同一载荷得到相同字节。跨压缩库版本或参数时仍应区分原文哈希和归档文件哈希。
import gzip
a=gzip.compress(b'rows',mtime=0)
[a==gzip.compress(b'rows',mtime=0),gzip.decompress(a).decode()]结果 [True, 'rows']