39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'middleman-more/lib/middleman-more/extensions/gzip.rb', line 39
def gzip_file(path, builder)
input_file = File.open(path, 'r').read
output_filename = path + '.gz'
input_file_time = File.mtime(path)
if File.exist?(output_filename) && File.mtime(output_filename) == input_file_time
return
end
File.open(output_filename, 'w') do |f|
gz = Zlib::GzipWriter.new(f, Zlib::BEST_COMPRESSION)
gz.mtime = input_file_time.to_i
gz.write input_file
gz.close
end
File.utime(File.atime(output_filename), input_file_time, output_filename)
old_size = File.size(path)
new_size = File.size(output_filename)
size_change_word = (old_size - new_size) > 0 ? 'smaller' : 'larger'
builder.say_status :gzip, "#{output_filename} (#{number_to_human_size((old_size - new_size).abs)} #{size_change_word})"
end
|