<commit_before>var
fs = require( "fs" ),
MimeDictionary = function ( map ) {
  this.dictionary = {}

  if ( String.is( map ) ) {
    this.fromApacheFile( map )
  } else if ( Array.is( map ) ) {
    map.forEach( function ( ind ) {
      this.fromApacheFile( ind )
    }, this )
  } else {
    this.define.apply( this, arguments )
  }
};

MimeDictionary.prototype.define = function ( type, extensions ) {
  // We're defining a single type
  if ( String.is( type ) ) {
    // With multiple extensions
    if ( Array.is( extensions ) ) {
      extensions.forEach( function ( extension ) {
        this.dictionary[extension] = type
      }, this)
    // With a single extension
    } else {
      this.dictionary[extension] = extensions
    }
  // We're defining a bunch of types
  } else {
    Object.keys( type ).forEach( function ( key ) {
      this.define( key, type[ key ] )
    })
  }
}

MimeDictionary.prototype.fromApacheFile = function ( path, encoding, callback ) {
  var dictionary = this;

  fs.readFile( path, encoding || "UTF-8", function ( error, content ) {
    var type, extensions;

    if ( error ) {
      callback( error )
    } else {
      // Remove all empty lines and comments and then split the file into lines.
      content = content
        .replace( /(#.+)$/gm, '' )
        .replace( /\n{2,}/g, "\n" )
        .split( "\n" )

      content.forEach(function ( line ) {
        // Trim off any whitespace on either end of the line
        line = line.trim()

        // Ignore any empty lines that made it this far
        if (line) {
          // Remove multiple spaces/tabs and make sure extensions
          // have dots, and then turn it into an array.
          line = line.replace( /\s+/g, ' .' )
            .split(' ')

          type = line.shift() // First item on the line is the mime type
          extensions = line // Everything after is an extension
<commit_msg>Fix a crash if the path is incorrect/doesn't exist and you don't provide a callback.<commit_after>var
fs = require( "fs" ),
MimeDictionary = function ( map ) {
  this.dictionary = {}

  if ( String.is( map ) ) {
    this.fromApacheFile( map )
  } else if ( Array.is( map ) ) {
    map.forEach( function ( ind ) {
      this.fromApacheFile( ind )
    }, this )
  } else {
    this.define.apply( this, arguments )
  }
};

MimeDictionary.prototype.define = function ( type, extensions ) {
  // We're defining a single type
  if ( String.is( type ) ) {
    // With multiple extensions
    if ( Array.is( extensions ) ) {
      extensions.forEach( function ( extension ) {
        this.dictionary[extension] = type
      }, this)
    // With a single extension
    } else {
      this.dictionary[extension] = extensions
    }
  // We're defining a bunch of types
  } else {
    Object.keys( type ).forEach( function ( key ) {
      this.define( key, type[ key ] )
    })
  }
}

MimeDictionary.prototype.fromApacheFile = function ( path, encoding, callback ) {
  var dictionary = this;

  fs.readFile( path, encoding || "UTF-8", function ( error, content ) {
    var type, extensions;

    if ( error ) {
      if ( callback ) callback( error )
      else throw error
    } else {
      // Remove all empty lines and comments and then split the file into lines.
      content = content
        .replace( /(#.+)$/gm, '' )
        .replace( /\n{2,}/g, "\n" )
        .split( "\n" )

      content.forEach(function ( line ) {
        // Trim off any whitespace on either end of the line
        line = line.trim()

        // Ignore any empty lines that made it this far
        if (line) {
          // Remove multiple spaces/tabs and make sure extensions
          // have dots, and then turn it into an array.
          line = line.replace( /\s+/g, ' .' )
            .split(' ')

          type = line.shift() // First item on the line is the mime type
          extensions = line // Everything after is an extension

{'fraction_non_alphanumeric': 0.12416964741951968, 'fraction_numerical': 0.001021972406745018, 'mean_word_length': 2.0826771653543306, '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': '2083208', 'n_tokens_mistral': 1171, 'n_tokens_neox': 1133, 'n_words': 383}