"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = getHash;

var _crypto = _interopRequireDefault(require("crypto"));

var _fs = _interopRequireDefault(require("fs"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function getHash(file, size = 20, isPath = false) {
  let hash = _crypto.default.createHash('md5');

  let fileNew = file;

  if (isPath) {
    fileNew = _fs.default.readFileSync(file);
  }

  hash.update(fileNew);
  hash = hash.digest('hex');
  return hash ? hash.substring(0, size) : null;
}