/*!
 * vinyl-yaml-data | MIT (c) Shinnosuke Watanabe
 * https://github.com/shinnn/vinyl-yaml-data
*/
'use strict';

var path = require('path');

var BufferStreams = require('bufferstreams');
var objectPath = require('object-path');
var replaceExt = require('replace-ext');
var through = require('through2');
var tryStreamPush = require('try-stream-push');
var xtend = require('xtend');
var yaml = require('js-yaml');

module.exports = function vinylYamlData(options) {
  options = options || {};

  return through.obj(function(file, enc, cb) {
    if (file.isNull()) {
      cb();
      return;
    }

    if (file.path === undefined) {
      this.emit('error', new TypeError('Expecting vinyl object to have "path" property.'));
      cb();
      return;
    }

    var props = path.relative(file.base, file.path).split(path.sep);

    if (!options.ext) {
      props[props.length - 1] = replaceExt(props[props.length - 1], '');
    }

    var self = this;

    function parseYaml(buf, cb) {
      var result = {};
      var yamlOptions = xtend(options, {
        filename: path.resolve(file.cwd, path.relative('', file.path)),
        ext: undefined
      });

      tryStreamPush(self, function() {
        objectPath.set(result, props, yaml.safeLoad(buf, xtend(options, yamlOptions)));
        return result;
      });

      cb();
    }

    if (file.isStream()) {
      file.contents = file.contents.pipe(new BufferStreams(function(none, buf, cb) {
        parseYaml(buf, cb);
      }));
      return;
    }

    parseYaml(file.contents, cb);
  });
};

@@ -975,26 +975,28 @@
 seYaml(buf, 
-cb
+done
 ) %7B%0A      va
@@ -1125,32 +1125,8 @@
 th))
-,%0A        ext: undefined
 %0A   
@@ -1228,31 +1228,16 @@
 oad(buf,
- xtend(options,
  yamlOpt
@@ -1242,17 +1242,16 @@
 ptions))
-)
 ;%0A      
@@ -1280,26 +1280,28 @@
  %7D);%0A%0A      
-cb
+done
 ();%0A    %7D%0A%0A 
@@ -1405,18 +1405,20 @@
 e, buf, 
-cb
+done
 ) %7B%0A    
@@ -1435,19 +1435,35 @@
 aml(buf,
+ done);%0A       
  cb
+(
 );%0A     

fix complexity and redundancy