<commit_before>class FileStore < Store
  class << self

    ### GET

    def get_text(path)
      File.read path if File.exist? path
    end

    alias_method :get_blob, :get_text

    ### PUT

    def put_text(path, text, metadata=nil)
      # Note: metadata is ignored for filesystem storage
      File.open(path, 'w'){ |file| file.write text }
      text
    end

    def put_blob(path, blob)
      File.open(path, 'wb'){ |file| file.write blob }
      blob
    end

    ### COLLECTIONS

    def annotated_pages(pages_dir)
      Dir.foreach(pages_dir).reject{|name|name =~ /^\./}.collect do |name|
        page = get_page(File.join pages_dir, name)
        page.merge!({
          'name' => name,
          'updated_at' => File.new("#{pages_dir}/#{name}").mtime
        })
      end
    end

    ### UTILITY

    def farm?(data_root)
      ENV['FARM_MODE'] || File.exists?(File.join data_root, "farm")
    end

    def mkdir(directory)
      FileUtils.mkdir_p directory
    end

    def exists?(path)
      File.exists?(path)
    end
  end
end
<commit_msg>read blob in binary mode<commit_after>class FileStore < Store
  class << self

    ### GET

    def get_text(path)
      File.read path if File.exist? path
    end

    def get_blob(path)
      File.binread path if File.exist? path
    end

    ### PUT

    def put_text(path, text, metadata=nil)
      # Note: metadata is ignored for filesystem storage
      File.open(path, 'w'){ |file| file.write text }
      text
    end

    def put_blob(path, blob)
      File.open(path, 'wb'){ |file| file.write blob }
      blob
    end

    ### COLLECTIONS

    def annotated_pages(pages_dir)
      Dir.foreach(pages_dir).reject{|name|name =~ /^\./}.collect do |name|
        page = get_page(File.join pages_dir, name)
        page.merge!({
          'name' => name,
          'updated_at' => File.new("#{pages_dir}/#{name}").mtime
        })
      end
    end

    ### UTILITY

    def farm?(data_root)
      ENV['FARM_MODE'] || File.exists?(File.join data_root, "farm")
    end

    def mkdir(directory)
      FileUtils.mkdir_p directory
    end

    def exists?(path)
      File.exists?(path)
    end
  end
end

{'fraction_non_alphanumeric': 0.1283471837488458, 'fraction_numerical': 0.0, 'mean_word_length': 2.2537537537537538, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '1051941', 'n_tokens_mistral': 750, 'n_tokens_neox': 719, 'n_words': 175}