lib/index.js
function extractFileHeader(path, opts) {
  opts = opts || {};

  var decode = opts.decode === undefined ? true : !!opts.decode;
  var size = Math.max(opts.size || 4096, 4);
  var fd = fs.openSync(path, 'r');
  var buf = new Buffer(size);
  var pos = 0;
  var tap = new utils.Tap(buf);
  var header = null;

  while (pos < 4) {
    // Make sure we have enough to check the magic bytes.
    pos += fs.readSync(fd, buf, pos, size - pos);
  }
  if (containers.MAGIC_BYTES.equals(buf.slice(0, 4))) {
    do {
      header = containers.HEADER_TYPE._read(tap);
    } while (!isValid());
    if (decode !== false) {
      var meta = header.meta;
      meta['avro.schema'] = JSON.parse(meta['avro.schema'].toString());
      if (meta['avro.codec'] !== undefined) {
        meta['avro.codec'] = meta['avro.codec'].toString();
      }
    }
  }
  fs.closeSync(fd);
  return header;

  function isValid() {
    if (tap.isValid()) {
      return true;
    }
    var len = 2 * tap.buf.length;
    var buf = new Buffer(len);
    len = fs.readSync(fd, buf, 0, len);
    tap.buf = Buffer.concat([tap.buf, buf]);
    tap.pos = 0;
    return false;
  }
}
function extractFileHeader(path, opts) {
  opts = opts || {};

  var decode = opts.decode === undefined ? true : !!opts.decode;
  var size = Math.max(opts.size || 4096, 4);
  var fd = fs.openSync(path, 'r');
  var buf = new Buffer(size);
  var pos = 0;
  var tap = new utils.Tap(buf);
  var header = null;

  while (pos < 4) {
    // Make sure we have enough to check the magic bytes.
    pos += fs.readSync(fd, buf, pos, size - pos);
  }
  if (containers.MAGIC_BYTES.equals(buf.slice(0, 4))) {
    do {
      header = containers.HEADER_TYPE._read(tap);
    } while (!isValid());
    if (decode !== false) {
      var meta = header.meta;
      meta['avro.schema'] = JSON.parse(meta['avro.schema'].toString());
      if (meta['avro.codec'] !== undefined) {
        meta['avro.codec'] = meta['avro.codec'].toString();
      }
    }
  }
  fs.closeSync(fd);
  return header;

  function isValid() {
    if (tap.isValid()) {
      return true;
    }
    var len = 2 * tap.buf.length;
    var buf = new Buffer(len);
    len = fs.readSync(fd, buf, 0, len);
    tap.buf = Buffer.concat([tap.buf, buf]);
    tap.pos = 0;
    return false;
  }
}
function extractFileHeader ( path , opts ) { opts = opts || { } ; var decode = opts . decode === undefined ? true : ! ! opts . decode ; var size = Math . max ( opts . size || 4096 , 4 ) ; var fd = fs . openSync ( path , 'r' ) ; var buf = new Buffer ( size ) ; var pos = 0 ; var tap = new utils . Tap ( buf ) ; var header = null ; while ( pos < 4 ) { // Make sure we have enough to check the magic bytes. pos += fs . readSync ( fd , buf , pos , size - pos ) ; } if ( containers . MAGIC_BYTES . equals ( buf . slice ( 0 , 4 ) ) ) { do { header = containers . HEADER_TYPE . _read ( tap ) ; } while ( ! isValid ( ) ) ; if ( decode !== false ) { var meta = header . meta ; meta [ 'avro.schema' ] = JSON . parse ( meta [ 'avro.schema' ] . toString ( ) ) ; if ( meta [ 'avro.codec' ] !== undefined ) { meta [ 'avro.codec' ] = meta [ 'avro.codec' ] . toString ( ) ; } } } fs . closeSync ( fd ) ; return header ; function isValid ( ) { if ( tap . isValid ( ) ) { return true ; } var len = 2 * tap . buf . length ; var buf = new Buffer ( len ) ; len = fs . readSync ( fd , buf , 0 , len ) ; tap . buf = Buffer . concat ( [ tap . buf , buf ] ) ; tap . pos = 0 ; return false ; } }
Extract a container file's header synchronously.
Extract a container file s header synchronously .