diff --git a/core/src/main/java/org/jruby/ext/zlib/JZlibRubyGzipWriter.java b/core/src/main/java/org/jruby/ext/zlib/JZlibRubyGzipWriter.java index f2234d3e9833..174cd3937701 100644 --- a/core/src/main/java/org/jruby/ext/zlib/JZlibRubyGzipWriter.java +++ b/core/src/main/java/org/jruby/ext/zlib/JZlibRubyGzipWriter.java @@ -134,8 +134,9 @@ private int processLevel(int argc, IRubyObject[] args, Ruby runtime) { return level; } - private IRubyObject initializeCommon(IRubyObject stream, int level) { - realIo = (RubyObject) stream; + private IRubyObject initializeCommon(ThreadContext context, IRubyObject stream, int level) { + Ruby runtime = context.runtime; + realIo = stream; try { // the 15+16 here is copied from a Deflater default constructor Deflater deflater = new Deflater(level, 15+16, false); @@ -158,9 +159,15 @@ public void write(byte[] bytes, int off, int len) throws IOException { }; io = new GZIPOutputStream(ioOutputStream, deflater, 512, false); + + // set mtime to current time in case it is never updated + long now = System.currentTimeMillis(); + this.mtime = RubyTime.newTime(runtime, now); + io.setModifiedTime(now / 1000); + return this; } catch (IOException ioe) { - throw getRuntime().newIOErrorFromException(ioe); + throw runtime.newIOErrorFromException(ioe); } }