const globule = require("globule");
const exif = require("exiftool");
const process = require("process");

const root = process.env.root || ".";
const files = globule.find(`${root}/**/*.jpg`);

if (files.length === 0) {
  console.error(`No files found in ${root}`);
  process.exit(1);
} else {
  console.log("Reading " + files.length + " files...");
}

function prom(file) {
  return new Promise((resolve, reject) => {
    exif.metadata(file, (err, metadata) => {
      process.stdout.write(".");
      if (err) reject(err);
      else resolve(); // throw away
    });
  });
}

console.log("Starting...");
const start = Date.now();

Promise.all(files.map(f => prom(f))).then(() => {
  const elapsedMs = Date.now() - start;
  console.log(
    `exiftool: Parsing took ${elapsedMs}ms (${(
      elapsedMs / files.length
    ).toFixed(1)}ms / file)`
  );
});

@@ -27,17 +27,16 @@
 lobule%22)
-;
 %0Aconst e
@@ -60,17 +60,16 @@
 iftool%22)
-;
 %0Aconst p
@@ -99,17 +99,16 @@
 ss%22)
-;
 %0A%0Aconst 
 root
@@ -103,20 +103,19 @@
 %0A%0Aconst 
-root
+dir
  = proce
@@ -121,24 +121,15 @@
 ess.
-env.root %7C%7C %22.%22;
+argv%5B2%5D
 %0Acon
@@ -155,20 +155,19 @@
 find(%60$%7B
-root
+dir
 %7D/**/*.j
@@ -170,17 +170,31 @@
 /*.jpg%60)
-;
+.slice(0, 1000)
 %0A%0Aif (fi
@@ -234,36 +234,115 @@
 or(%60
-No files found in $%7Broot%7D
+Please provide a directory with example images.%60)%0A  console.error(%60Usage: node ./index.js IMAGE_DIRECTORY
 %60)
-;
 %0A  p
@@ -355,17 +355,16 @@
 .exit(1)
-;
 %0A%7D else 
@@ -419,21 +419,39 @@
 les...%22)
-;
 %0A%7D%0A%0A
+const errors = %5B%5D%0A%0A
 function
@@ -504,24 +504,36 @@
 eject) =%3E %7B%0A
+    try %7B%0A  
     exif.met
@@ -575,73 +575,77 @@
     
-process.stdout.write(%22.%22);%0A      if (err) reject(
+  if (err) errors.push(%22failed to read %22 + file + %22: %22 + 
 err)
-;
 %0A      
-else
+ 
  res
@@ -650,17 +650,16 @@
 esolve()
-;
  // thro
@@ -673,48 +673,122 @@
     
+  
 %7D)
-;
 %0A  
-%7D);%0A%7D%0A%0Aconsole.log(%22Starting...%22);
+  %7D catch (err) %7B%0A      errors.push(%22error raised from %22 + file + %22: %22 + err)%0A      resolve()%0A    %7D%0A  %7D)%0A%7D%0A
 %0Acon
@@ -808,17 +808,16 @@
 te.now()
-;
 %0A%0APromis
@@ -898,17 +898,16 @@
  - start
-;
 %0A  conso
@@ -1029,10 +1029,87 @@
 %0A  )
-;
+%0A  if (errors.length %3E 0) %7B%0A    console.log(%22exiftool had errors:%22, errors)%0A  %7D
 %0A%7D)
-;
 %0A

allow exiftool to throw errors and still give a ms/file benchmark