lib/specs.js
function read(str) {
  var schema;
  if (typeof str == 'string' && ~str.indexOf(path.sep) && files.existsSync(str)) {
    // Try interpreting `str` as path to a file contain a JSON schema or an IDL
    // protocol. Note that we add the second check to skip primitive references
    // (e.g. `"int"`, the most common use-case for `avro.parse`).
    var contents = files.readFileSync(str, {encoding: 'utf8'});
    try {
      return JSON.parse(contents);
    } catch (err) {
      var opts = {importHook: files.createSyncImportHook()};
      assembleProtocol(str, opts, function (err, protocolSchema) {
        schema = err ? contents : protocolSchema;
      });
    }
  } else {
    schema = str;
  }
  if (typeof schema != 'string' || schema === 'null') {
    // This last predicate is to allow `read('null')` to work similarly to
    // `read('int')` and other primitives (null needs to be handled separately
    // since it is also a valid JSON identifier).
    return schema;
  }
  try {
    return JSON.parse(schema);
  } catch (err) {
    try {
      return Reader.readProtocol(schema);
    } catch (err) {
      try {
        return Reader.readSchema(schema);
      } catch (err) {
        return schema;
      }
    }
  }
}
function read(str) {
  var schema;
  if (typeof str == 'string' && ~str.indexOf(path.sep) && files.existsSync(str)) {
    // Try interpreting `str` as path to a file contain a JSON schema or an IDL
    // protocol. Note that we add the second check to skip primitive references
    // (e.g. `"int"`, the most common use-case for `avro.parse`).
    var contents = files.readFileSync(str, {encoding: 'utf8'});
    try {
      return JSON.parse(contents);
    } catch (err) {
      var opts = {importHook: files.createSyncImportHook()};
      assembleProtocol(str, opts, function (err, protocolSchema) {
        schema = err ? contents : protocolSchema;
      });
    }
  } else {
    schema = str;
  }
  if (typeof schema != 'string' || schema === 'null') {
    // This last predicate is to allow `read('null')` to work similarly to
    // `read('int')` and other primitives (null needs to be handled separately
    // since it is also a valid JSON identifier).
    return schema;
  }
  try {
    return JSON.parse(schema);
  } catch (err) {
    try {
      return Reader.readProtocol(schema);
    } catch (err) {
      try {
        return Reader.readSchema(schema);
      } catch (err) {
        return schema;
      }
    }
  }
}
function read ( str ) { var schema ; if ( typeof str == 'string' && ~ str . indexOf ( path . sep ) && files . existsSync ( str ) ) { // Try interpreting `str` as path to a file contain a JSON schema or an IDL // protocol. Note that we add the second check to skip primitive references // (e.g. `"int"`, the most common use-case for `avro.parse`). var contents = files . readFileSync ( str , { encoding : 'utf8' } ) ; try { return JSON . parse ( contents ) ; } catch ( err ) { var opts = { importHook : files . createSyncImportHook ( ) } ; assembleProtocol ( str , opts , function ( err , protocolSchema ) { schema = err ? contents : protocolSchema ; } ) ; } } else { schema = str ; } if ( typeof schema != 'string' || schema === 'null' ) { // This last predicate is to allow `read('null')` to work similarly to // `read('int')` and other primitives (null needs to be handled separately // since it is also a valid JSON identifier). return schema ; } try { return JSON . parse ( schema ) ; } catch ( err ) { try { return Reader . readProtocol ( schema ) ; } catch ( err ) { try { return Reader . readSchema ( schema ) ; } catch ( err ) { return schema ; } } } }
Parsing functions. 
Convenience function to parse multiple inputs into protocols and schemas.

It should cover most basic use-cases but has a few limitations:

+ It doesn't allow passing options to the parsing step.
+ The protocol/type inference logic can be deceived.

The parsing logic is as follows:

+ If `str` contains `path.sep` (on windows `\`, otherwise `/`) and is a path
to an existing file, it will first be read as JSON, then as an IDL
specification if JSON parsing failed. If either succeeds, the result is
returned, otherwise the next steps are run using the file's content
instead of the input path.
+ If `str` is a valid JSON string, it is parsed then returned.
+ If `str` is a valid IDL protocol specification, it is parsed and returned
if no imports are present (and an error is thrown if there are any
imports).
+ If `str` is a valid IDL type specification, it is parsed and returned.
+ If neither of the above cases apply, `str` is returned.
Parsing functions . Convenience function to parse multiple inputs into protocols and schemas .