<commit_before>require_relative 'deflater_base'

module Paperclip
  module Processors
    class Gzip < DeflaterBase
      def initialize(file, options = {}, attachment = nil)
        super
        @gzip_options = @options[:gzip_options] || {}
      end

      def make
        level       = @gzip_options[:level]
        strategy    = @gzip_options[:strategy]

        dst = create_tempfile
        begin
          gz = Zlib::GzipWriter.new(dst, level, strategy)
          gz.write @file.read
        rescue ::Exception => e
          gz.close rescue nil
          raise e
        end
        gz.close
        @file.rewind
        dst.open

        dst
      end
    end
  end
end<commit_msg>Gzip with buffering<commit_after>require_relative 'deflater_base'

module Paperclip
  module Processors
    class Gzip < DeflaterBase
      def initialize(file, options = {}, attachment = nil)
        super
        @gzip_options = @options[:gzip_options] || {}
      end

      def make
        level       = @gzip_options[:level]
        strategy    = @gzip_options[:strategy]

        dst = create_tempfile
        begin
          gz = Zlib::GzipWriter.new(dst, level, strategy)
          while chunk = @file.read(16 * 1024) do
            gz.write chunk
          end
        rescue ::Exception => e
          gz.close rescue nil
          raise e
        end
        gz.close
        @file.rewind
        dst.open

        dst
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.07862068965517241, 'fraction_numerical': 0.004137931034482759, 'mean_word_length': 1.6920222634508348, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7226840', 'n_tokens_mistral': 435, 'n_tokens_neox': 417, 'n_words': 107}