<commit_before>module Zippo
  class ZipFileWriter
    def initialize(directory, filename)
      @directory = directory
      @filename = filename
    end
    def write
      File.open(@filename,'wb:ASCII-8BIT') do |io|

        packer = LocalFileHeader::Packer.new io
        headers = @directory.map do |member|
          CdFileHeader.default.tap do |header|
            header.compression_method = 0 # XXX configurable
            header.name = member.name
            header.extra_field = "" # XXX extra field unimplemented
            header_size = header.file_name_length + header.extra_field_length + 30

            # record header position so we can write it later
            header.local_file_header_offset = io.pos

            # move to after the header
            io.seek header_size, IO::SEEK_CUR

            # write the compressed data
            header.compressed_size,
              header.uncompressed_size,
              header.crc32 = member.write_to io

            # write the completed header, returning to the current position
            io.seek header.local_file_header_offset
            #packer.pack LocalFileHeader.from header.convert_to LocalHileHeader
            packer.pack header.convert_to LocalFileHeader
            io.seek header.compressed_size, IO::SEEK_CUR
          end
        end

        eocdr = EndCdRecord.default
        eocdr.cd_offset = io.pos
        packer = CdFileHeader::Packer.new io
        for header in headers
          packer.pack header
        end
        eocdr.cd_size = io.pos - eocdr.cd_offset
        eocdr.records = eocdr.total_records = headers.size
        packer = EndCdRecord::Packer.new io
        packer.pack eocdr
      end
    end
  end
end
<commit_msg>Use for loop instead of map<commit_after>module Zippo
  class ZipFileWriter
    def initialize(directory, filename)
      @directory = directory
      @filename = filename
    end
    def write
      File.open(@filename,'wb:ASCII-8BIT') do |io|
        packer = LocalFileHeader::Packer.new io
        headers = []
        for member in @directory
          header = CdFileHeader.default
          header.compression_method = 0 # XXX configurable
          header.name = member.name
          header.extra_field = "" # XXX extra field unimplemented
          header_size = header.file_name_length + header.extra_field_length + 30

          # record header position so we can write it later
          header.local_file_header_offset = io.pos

          # move to after the header
          io.seek header_size, IO::SEEK_CUR

          # write the compressed data
          header.compressed_size,
            header.uncompressed_size,
            header.crc32 = member.write_to io

          # write the completed header, returning to the current position
          io.seek header.local_file_header_offset
          #packer.pack LocalFileHeader.from header.convert_to LocalHileHeader
          packer.pack header.convert_to LocalFileHeader
          io.seek header.compressed_size, IO::SEEK_CUR
          headers << header
        end

        eocdr = EndCdRecord.default
        eocdr.cd_offset = io.pos
        packer = CdFileHeader::Packer.new io
        for header in headers
          packer.pack header
        end
        eocdr.cd_size = io.pos - eocdr.cd_offset
        eocdr.records = eocdr.total_records = headers.size
        EndCdRecord::Packer.new(io).pack eocdr
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.06231799650553291, 'fraction_numerical': 0.0034944670937682005, 'mean_word_length': 2.06970509383378, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1853354', 'n_tokens_mistral': 974, 'n_tokens_neox': 939, 'n_words': 247}