Bug #16285
Updated by alanwu (Alan Wu) over 5 years ago
Run the following script to observe the issue ```ruby require 'zlib' def write_gzip_file(content, mtime) File.open('archieve.gz', 'w') do |f| gz = Zlib::GzipWriter.new(f) gz.mtime = mtime gz.write(content) gz.close end system("file archieve.gz") end write_gzip_file("current time", 0) write_gzip_file("one second from epoch", 1) ``` Output: ``` ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin18] archieve.gz: gzip compressed data, last modified: Wed Oct 30 18:04:07 2019, from Unix, original size 12 archieve.gz: gzip compressed data, last modified: Thu Jan 1 00:00:01 1970, from Unix, original size 21 ``` As you can see, setting mtime to 0 doesn't set the timestamp in the file header to be all zeros. The documentation for `#mtime=` says: > If you do not set an mtime, the default value will be the time when compression started. Setting a value of 0 indicates no time stamp is available. which sounds like setting 0 should be a valid operation. valid. I have a PR to fix this: https://github.com/ruby/zlib/pull/10