2
2
module Sprockets
3
3
module Utils
4
4
class Gzip
5
+ MTIME = RUBY_VERSION >= "2.7" ? 0 : 1
6
+
5
7
# Private: Generates a gzipped file based off of reference asset.
6
8
#
7
9
# ZlibArchiver.call(file, source, mtime)
@@ -10,13 +12,13 @@ class Gzip
10
12
# writes contents to the `file` passed in. Sets `mtime` of
11
13
# written file to passed in `mtime`
12
14
module ZlibArchiver
13
- def self . call ( file , source , mtime )
15
+ def self . call ( file , source )
14
16
gz = Zlib ::GzipWriter . new ( file , Zlib ::BEST_COMPRESSION )
15
- gz . mtime = mtime
17
+ gz . mtime = MTIME
16
18
gz . write ( source )
17
19
gz . close
18
20
19
- File . utime ( mtime , mtime , file . path )
21
+ nil
20
22
end
21
23
end
22
24
@@ -28,8 +30,8 @@ def self.call(file, source, mtime)
28
30
# writes contents to the `file` passed in. Sets `mtime` of
29
31
# written file to passed in `mtime`
30
32
module ZopfliArchiver
31
- def self . call ( file , source , mtime )
32
- compressed_source = Autoload ::Zopfli . deflate ( source , format : :gzip , mtime : mtime )
33
+ def self . call ( file , source )
34
+ compressed_source = Autoload ::Zopfli . deflate ( source , format : :gzip , mtime : MTIME )
33
35
file . write ( compressed_source )
34
36
file . close
35
37
@@ -90,7 +92,8 @@ def cannot_compress?
90
92
# Returns nothing.
91
93
def compress ( file , target )
92
94
mtime = Sprockets ::PathUtils . stat ( target ) . mtime
93
- archiver . call ( file , source , mtime )
95
+ archiver . call ( file , source )
96
+ File . utime ( mtime , mtime , file . path )
94
97
95
98
nil
96
99
end
0 commit comments