'use strict';

const fs = require('fs'),
    crypto = require('crypto'); 

module.exports = (filename) => {
     var promise = new Promise(function (resolve, reject) {

        let input = fs.createReadStream(filename),
            hash = crypto.createHash('md5');

        input.on('readable', () => {
            var data = input.read();
            if (data)
                hash.update(data);
            else { 
                 resolve(hash.digest('hex'));
            }
        }); 
        
        input.on('error', (e) => {
            reject(e);
        }); 
    }); 
  return promise;
};
