<commit_before>module UnpackStrategy
  # length of the longest regex (currently Tar)
  MAX_MAGIC_NUMBER_LENGTH = 262
  private_constant :MAX_MAGIC_NUMBER_LENGTH

  def self.strategies
    @strategies ||= [
      Pkg,
      Ttf,
      Otf,
      Air,
      Executable,
      Diff,
      Jar, # needs to be before Zip
      LuaRock, # needs to be before Zip
      MicrosoftOfficeXml, # needs to be before Zip
      Zip,
      Xar,
      Compress,
      Tar, # needs to be before Bzip2/Gzip/Xz/Lzma
      Gzip,
      Lzma,
      Xz,
      Lzip,
      Git,
      Mercurial,
      Subversion,
      Cvs,
      Dmg, # needs to be before Bzip2
      Bzip2,
      Fossil,
      Bazaar,
      SelfExtractingExecutable, # needs to be before Cab
      Cab,
      P7Zip,
      Sit,
      Rar,
      Lha,
    ].freeze
  end
  private_class_method :strategies

  def self.from_type(type)
    type = {
      naked: :uncompressed,
      seven_zip: :p7zip,
    }.fetch(type, type)

    begin
      const_get(type.to_s.split("_").map(&:capitalize).join)
    rescue NameError
      nil
    end
  end

  def self.from_path(path)
    magic_number = if path.directory?
      ""
    else
      File.binread(path, MAX_MAGIC_NUMBER_LENGTH) || ""
    end

    strategy = strategies.detect do |s|
      s.can_extract?(path: path, magic_number: magic_number)
    end<commit_msg>Reorder unpack strategies again.<commit_after>module UnpackStrategy
  # length of the longest regex (currently Tar)
  MAX_MAGIC_NUMBER_LENGTH = 262
  private_constant :MAX_MAGIC_NUMBER_LENGTH

  def self.strategies
    @strategies ||= [
      Air, # needs to be before Zip
      Jar, # needs to be before Zip
      LuaRock, # needs to be before Zip
      MicrosoftOfficeXml, # needs to be before Zip
      Zip, # needs to be before Tar
      Pkg, # needs to be before Xar
      Xar, # needs to be before Tar
      Tar, # needs to be before Bzip2/Gzip/Xz/Lzma
      Gzip,
      Lzma,
      Xz,
      Lzip,
      Executable,
      Diff,
      Git,
      Mercurial,
      Subversion,
      Cvs,
      Ttf,
      Otf,
      Dmg, # needs to be before Bzip2
      Bzip2,
      Fossil,
      Bazaar,
      SelfExtractingExecutable, # needs to be before Cab
      Cab,
      Compress,
      P7Zip,
      Sit,
      Rar,
      Lha,
    ].freeze
  end
  private_class_method :strategies

  def self.from_type(type)
    type = {
      naked: :uncompressed,
      seven_zip: :p7zip,
    }.fetch(type, type)

    begin
      const_get(type.to_s.split("_").map(&:capitalize).join)
    rescue NameError
      nil
    end
  end

  def self.from_path(path)
    magic_number = if path.directory?
      ""
    else
      File.binread(path, MAX_MAGIC_NUMBER_LENGTH) || ""
    end

    strategy = strategies.detect do |s|
      s.can_extract?(path: path, magic_number: magic_number)
    end
{'fraction_non_alphanumeric': 0.0826534231997162, 'fraction_numerical': 0.005675771550195104, 'mean_word_length': 2.0618892508143323, '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': '4804805', 'n_tokens_mistral': 1000, 'n_tokens_neox': 973, 'n_words': 252}