var p = require('path');
var cp = require('child_process');

var fileExec = p.resolve(__dirname + '/../bin/file');
var fileFlags = ['--magic-file', p.resolve(__dirname + '/../share/magic.mgc'), '--brief', '--mime-type'];

var fileWrapper = function (path, cb) {
	var flags = JSON.parse(JSON.stringify(fileFlags));
	flags.push(path);
	cp.execFile(fileExec, flags, function (err, stdout) {
		stdout = stdout.trim();
		if (err) {
			if (stdout) {
				err.message = stdout;
			}
			cb(err);
		} else {
			cb(null, stdout);
		}
	});
};
exports.fileWrapper = fileWrapper;

var p = require('path');
var cp = require('child_process');

var fileExec = p.resolve(__dirname + '/../bin/file');
var fileFlags = ['--magic-file', p.resolve(__dirname + '/../share/magic.mgc'), '--brief', '--mime-type'];

var fileWrapper = function (path, cb) {
	cp.execFile(fileExec, fileFlags.concat(Array.isArray(path) ? path : [path]), function (err, stdout) {
		stdout = stdout.trim();
		if (err) {
			if (stdout)
				err.message = stdout;
			cb(err);
		} else
			cb(null, Array.isArray(path) ? stdout.split('\n') : stdout);
	});
};
exports.fileWrapper = fileWrapper;

Support arrays of paths, with the callback getting an array of mime-types.
Support arrays of paths, with the callback getting an array of mime-types.