<commit_before>/**
 * Created by middleca on 6/18/15.
 */

var fs = require('fs');
var path = require("path");
var when = require('when');
var pipeline = require('when/pipeline');
var util = require('util');

var HalModuleParser = require('./HalModuleParser.js');


var HalDependencyResolver = function() {

};
HalDependencyResolver.prototype = {

	/**
	 * expects a fileBuffer and the JSON describe payload for the 'm' modules array
	 * @param describe
	 * @param fileBuffer
	 * @returns {*}
	 */
	parse_and_resolve: function(describe, fileBuffer) {
		if (!Buffer.isBuffer(fileBuffer)) {
			return when.reject("fileBuffer was invalid");
		}

		var parser = new HalModuleParser();
		var fileInfo = {
			filename: "user-file",
			fileBuffer: fileBuffer
		};

		var that = this;
		return pipeline([
			function() {
				return parser.parseBuffer(fileInfo);
			},
			function() {
				return that.resolve_dependencies(describe, fileInfo);
			}
		]);
	},

	/**
	 * splice stuff onto the start of an array.
	 * @param arr
	 * @param insArr
	 * @returns {*}
	 * @private
	 */
	_array_insert: function(arr, insArr) {
		return insArr.concat(arr);<commit_msg>adaptively try to grab the right section in case the wrong one was sent<commit_after>/**
 * Created by middleca on 6/18/15.
 */

var fs = require('fs');
var path = require("path");
var when = require('when');
var pipeline = require('when/pipeline');
var util = require('util');

var HalModuleParser = require('./HalModuleParser.js');


var HalDependencyResolver = function() {

};
HalDependencyResolver.prototype = {

	/**
	 * expects a fileBuffer and the JSON describe payload for the 'm' modules array
	 * @param describe
	 * @param fileBuffer
	 * @returns {*}
	 */
	parse_and_resolve: function(describe, fileBuffer) {
		if (describe && !util.isArray(describe) && describe.m) {
			//those goofs, they sent the whole thing, instead of just the modules section.
			describe = describe.m;
		}

		if (!Buffer.isBuffer(fileBuffer)) {
			return when.reject("fileBuffer was invalid");
		}

		var parser = new HalModuleParser();
		var fileInfo = {
			filename: "user-file",
			fileBuffer: fileBuffer
		};

		var that = this;
		return pipeline([
			function() {
				return parser.parseBuffer(fileInfo);
			},
			function() {
				return that.resolve_dependencies(describe, fileInfo);
			}
		]);
	},

	/**
	 * splice stuff onto the start of an array.
	 * @param arr
	 * @param insArr
	 * @returns {*}
	 * @private
	 */
	_array_insert: function(arr, insArr) {
		return insArr.concat(arr);
{'fraction_non_alphanumeric': 0.13895486935866982, 'fraction_numerical': 0.00395882818685669, 'mean_word_length': 3.6537753222836096, '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': '4711385', 'n_tokens_mistral': 869, 'n_tokens_neox': 755, 'n_words': 223}