<commit_before>require 'zip'

module Stevenson
  module OutputFilter
    module Zip
      include Base

      def output
        Dir.mktmpdir do |dir|
          # Call the parent method
          super dir

          # Zip up the output directory
          write dir, directory
        end
      end

      private

      def write(inputDir, outputFile)
        @inputDir = inputDir
        @outputFile = outputFile

        entries = Dir.entries(@inputDir)
        entries.delete(".")
        entries.delete("..")
        io = Zip::File.open(@outputFile, Zip::File::CREATE)

        writeEntries(entries, "", io)
        io.close()
      end

      def writeEntries(entries, path, io)
        entries.each { |e|
          zipFilePath = path == "" ? e : File.join(path, e)
          diskFilePath = File.join(@inputDir, zipFilePath)
          if File.directory?(diskFilePath)
            io.mkdir(zipFilePath)
            subdir =Dir.entries(diskFilePath); subdir.delete("."); subdir.delete("..")
            writeEntries(subdir, zipFilePath, io)
          else
            io.get_output_stream(zipFilePath) { |f| f.puts(File.open(diskFilePath, "rb").read())}
          end
        }
      end
    end
  end
end
<commit_msg>Use do..end syntax for multiline-blocks<commit_after>require 'zip'

module Stevenson
  module OutputFilter
    module Zip
      include Base

      def output
        Dir.mktmpdir do |dir|
          # Call the parent method
          super dir

          # Zip up the output directory
          write dir, directory
        end
      end

      private

      def write(inputDir, outputFile)
        @inputDir = inputDir
        @outputFile = outputFile

        entries = Dir.entries(@inputDir)
        entries.delete(".")
        entries.delete("..")
        io = Zip::File.open(@outputFile, Zip::File::CREATE)

        writeEntries(entries, "", io)
        io.close()
      end

      def writeEntries(entries, path, io)
        entries.each do |entry|
          zipFilePath = path == "" ? entry : File.join(path, entry)
          diskFilePath = File.join(@inputDir, zipFilePath)
          if File.directory?(diskFilePath)
            io.mkdir(zipFilePath)
            subdir =Dir.entries(diskFilePath); subdir.delete("."); subdir.delete("..")
            writeEntries(subdir, zipFilePath, io)
          else
            io.get_output_stream(zipFilePath) { |f| f.puts(File.open(diskFilePath, "rb").read()) }
          end
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.10651125401929261, 'fraction_numerical': 0.0, 'mean_word_length': 1.8908246225319396, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '345798', 'n_tokens_mistral': 713, 'n_tokens_neox': 683, 'n_words': 174}