Project

General

Profile

Actions

Bug #16285

closed

Setting mtime to zero on Zlib::GzipWriter does nothing

Added by alanwu (Alan Wu) over 4 years ago. Updated over 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:95590]

Description

Run the following script to observe the issue

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.

I have a PR to fix this: https://github.com/ruby/zlib/pull/10

Actions #1

Updated by alanwu (Alan Wu) over 4 years ago

  • Description updated (diff)
Actions #2

Updated by alanwu (Alan Wu) over 4 years ago

  • Description updated (diff)
Actions #3

Updated by alanwu (Alan Wu) over 4 years ago

  • Subject changed from Setting mtime to zero Zlib::GzipWriter does nothing to Setting mtime to zero on Zlib::GzipWriter does nothing
Actions #4

Updated by jeremyevans0 (Jeremy Evans) over 4 years ago

  • Status changed from Open to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0