Hash files (#7)

added md5 check for animations
diff --git a/images/index.js b/images/index.js
index f25a3ed..10fc63d 100644
--- a/images/index.js
+++ b/images/index.js
@@ -8,9 +8,13 @@
 const express = require('express');
 const fs = require('fs');
 const commandLineArgs = require('command-line-args');
+const md5File = require('md5-file');
+const { promises: { readFile } } = require('fs');
 
 const examplesDirectory = '../examples/';
 const destinationDirectory = './screenshots';
+const md5Directory = './md5sum/lottie_web';
+
 if (!fs.existsSync(destinationDirectory)) {
   fs.mkdirSync(destinationDirectory);
 }
@@ -65,26 +69,26 @@
 const wait = (time) => new Promise((resolve) => setTimeout(resolve, time));
 
 const startServer = async () => {
-  const lottieJS = fs.readFileSync('node_modules/lottie-web/build/player/lottie.min.js', 'utf8');
-  const screenshotJS = fs.readFileSync('screenshot.js', 'utf8');
-  const driverHTML = fs.readFileSync('screenshot.html', 'utf8');
-  const lottieJSON = fs.readFileSync('../examples/rectangle.json', 'utf8');
+  const lottieJS = await readFile('node_modules/lottie-web/build/player/lottie.min.js', 'utf8');
+  const screenshotJS = await readFile('screenshot.js', 'utf8');
+  const driverHTML = await readFile('screenshot.html', 'utf8');
+  const lottieJSON = await readFile('../examples/rectangle.json', 'utf8');
   const app = express();
   app.get('/screenshot.html', (req, res) => res.send(driverHTML));
-  app.get('/screenshot_live.html', (req, res) => {
-    const file = fs.readFileSync('screenshot.html', 'utf8');
+  app.get('/screenshot_live.html', async (req, res) => {
+    const file = await readFile('screenshot.html', 'utf8');
     res.send(file);
   });
   app.get('/lottie.js', (req, res) => res.send(lottieJS));
   app.get('/screenshot.js', (req, res) => res.send(screenshotJS));
   app.get('/lottie.json', (req, res) => res.send(lottieJSON));
-  app.get('/*', (req, res) => {
+  app.get('/*', async (req, res) => {
     try {
       if (req.originalUrl.indexOf('.json') !== -1) {
-        const file = fs.readFileSync(`..${req.originalUrl}`, 'utf8');
+        const file = await readFile(`..${req.originalUrl}`, 'utf8');
         res.send(file);
       } else {
-        const data = fs.readFileSync(`..${req.originalUrl}`);
+        const data = await readFile(`..${req.originalUrl}`);
         res.writeHead(200, { 'Content-Type': 'image/jpeg' });
         res.end(data);
       }
@@ -109,12 +113,12 @@
   return page;
 };
 
-const createFilmStrim = async (page, path) => {
+const createFilmStrip = async (page, path) => {
   await page.waitForFunction('window._finished === true', {
     timeout: 20000,
   });
   await page.screenshot({
-    path: `${destinationDirectory}/${path}.png`,
+    path,
     fullPage: true,
   });
 };
@@ -131,9 +135,33 @@
   })
 );
 
+const getFileAsString = async (path) => {
+  try {
+    const fileBuffer = await readFile(path);
+    return fileBuffer.toString();
+  } catch (err) {
+    return '';
+  }
+};
+
+const checkMD5Sum = async (fileName, filePath) => {
+  const md5FilePath = `${md5Directory}/${fileName}.md5`;
+  const md5StoredValue = await getFileAsString(md5FilePath);
+  if (!md5StoredValue) {
+    // It's a new file.. Check how to commit the new value.
+  } else {
+    const md5Value = await md5File(filePath);
+    if (md5Value !== md5StoredValue) {
+      // The file has changed. Should not allow the commit.
+    }
+  }
+};
+
 async function processPage(browser, settings, directory, file) {
   const page = await startPage(browser, settings, directory + file);
-  await createFilmStrim(page, file);
+  const filePath = `${destinationDirectory}/${file}.png`;
+  await createFilmStrip(page, filePath);
+  await checkMD5Sum(file, filePath);
 }
 
 const iteratePages = async (browser, settings) => {
diff --git a/images/md5sum/lottie_web/image.json.md5 b/images/md5sum/lottie_web/image.json.md5
new file mode 100644
index 0000000..9d82e1b
--- /dev/null
+++ b/images/md5sum/lottie_web/image.json.md5
@@ -0,0 +1 @@
+29077ea93acecd8a1bfe740b8a1cfe27
\ No newline at end of file
diff --git a/images/md5sum/lottie_web/precomp.json.md5 b/images/md5sum/lottie_web/precomp.json.md5
new file mode 100644
index 0000000..7a4cddd
--- /dev/null
+++ b/images/md5sum/lottie_web/precomp.json.md5
@@ -0,0 +1 @@
+76bacdfe0fed97addc47c4f1f49cc98c
\ No newline at end of file
diff --git a/images/md5sum/lottie_web/rectangle.json.md5 b/images/md5sum/lottie_web/rectangle.json.md5
new file mode 100644
index 0000000..b6e34c0
--- /dev/null
+++ b/images/md5sum/lottie_web/rectangle.json.md5
@@ -0,0 +1 @@
+a74c36a7a1b674c9ec5949b133f9c54b
\ No newline at end of file
diff --git a/images/md5sum/lottie_web/shape.json.md5 b/images/md5sum/lottie_web/shape.json.md5
new file mode 100644
index 0000000..1bdd46f
--- /dev/null
+++ b/images/md5sum/lottie_web/shape.json.md5
@@ -0,0 +1 @@
+fbbd168a2504590b2e5e315350bd4427
\ No newline at end of file
diff --git a/images/package-lock.json b/images/package-lock.json
index 4a056c6..6c66d2d 100644
--- a/images/package-lock.json
+++ b/images/package-lock.json
@@ -1553,6 +1553,11 @@
         "yallist": "^4.0.0"
       }
     },
+    "md5-file": {
+      "version": "5.0.0",
+      "resolved": "https://registry.npmjs.org/md5-file/-/md5-file-5.0.0.tgz",
+      "integrity": "sha512-xbEFXCYVWrSx/gEKS1VPlg84h/4L20znVIulKw6kMfmBUAZNAnF00eczz9ICMl+/hjQGo5KSXRxbL/47X3rmMw=="
+    },
     "media-typer": {
       "version": "0.3.0",
       "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
diff --git a/images/package.json b/images/package.json
index c2ac02a..66602b3 100644
--- a/images/package.json
+++ b/images/package.json
@@ -7,6 +7,7 @@
     "command-line-args": "^5.2.0",
     "express": "^4.17.1",
     "lottie-web": "^5.7.14",
+    "md5-file": "^5.0.0",
     "puppeteer": "^10.4.0"
   },
   "devDependencies": {
@@ -16,7 +17,7 @@
   },
   "scripts": {
     "test": "echo \"Error: no test specified\" && exit 1",
-    "lint" : "./node_modules/.bin/eslint index.js"
+    "lint": "./node_modules/.bin/eslint index.js"
   },
   "keywords": [],
   "author": "",