class Middleman::Extensions::Gzip
def gzip_file(path)
def gzip_file(path) input_file = File.open(path, 'rb').read output_filename = options.overwrite ? path : path + '.gz' input_file_time = File.mtime(path) # Check if the right file's already there if !options.overwrite && File.exist?(output_filename) && File.mtime(output_filename) == input_file_time return [nil, nil, nil] end File.open(output_filename, 'wb') do |f| gz = Zlib::GzipWriter.new(f, Zlib::BEST_COMPRESSION) gz.mtime = input_file_time.to_i gz.write input_file gz.close end # Make the file times match, both for Nginx's gzip_static extension # and so we can ID existing files. Also, so even if the GZ files are # wiped out by build --clean and recreated, we won't rsync them over # again because they'll end up with the same mtime. File.utime(File.atime(output_filename), input_file_time, output_filename) old_size = File.size(path) new_size = File.size(output_filename) [output_filename, old_size, new_size] end