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

Closed
wants to merge 1 commit into
from
View
@@ -5,18 +5,14 @@ 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) {
+ cp.execFile(fileExec, fileFlags.concat(Array.isArray(path) ? path : [path]), function (err, stdout) {
stdout = stdout.trim();
if (err) {
- if (stdout) {
+ if (stdout)
err.message = stdout;
- }
cb(err);
- } else {
- cb(null, stdout);
- }
+ } else
+ cb(null, Array.isArray(path) ? stdout.split('\n') : stdout);
});
};
exports.fileWrapper = fileWrapper;