/*
给文件添加md5标识符
@param {String} path 文件路径
@param {Object} file fis File对象
@return {String} 带有md5 hash标识的路径
488678
function addHash(path, file) {
  var rExt = file.rExt,
    qRExt = fis.util.escapeReg(rExt),
    qExt = fis.util.escapeReg(file.ext),
    hash = file.getHash(),
    onnector = fis.media().get('project.md5Connector', '_'),
    reg = new RegExp(qRExt + '$|' + qExt + '$', 'i');
  return path.replace(reg, '') + onnector + hash + rExt;
}
865884
function FileReadStream(path, options) {
  stream.Stream.call(this);
  this.readable = true;

  if(!options) {
    options = {};
  }

  this._destroyed = false;
  this._streamEnded = false;
  this._fd = null;
  this._fileName = undefined;
  this._highWaterMark = options.highWaterMark || bufferSize;
  this._offset = 0;
  this._paused = undefined;
  this._allocator = options.allocator;
  this._fileName = path;

  this._md5hash = null;
  this._md5sum = undefined;

  if (options.calcContentMd5) {
    this._md5hash = new Md5Wrapper().createMd5Hash();
  }

  this._open();
}
1042778
def md5sum(file_path, blocksize=65536):
    """"""
    md5 = hashlib.md5()
    with open(file_path, "rb") as f:
        for block in iter(lambda: f.read(blocksize), ""):
            md5.update(block)
    return md5.hexdigest()
691696
def md5_of_file(abspath):
    
    chunk_size = 1024 * 1024
    m = hashlib.md5()
    with open(abspath, "rb") as f:
        while True:
            data = f.read(chunk_size)
            if not data:
                break
            m.update(data)
    return m.hexdigest()
59978
function $file(params, fn) {
    if (params == null) {
        return params;
    }
    let file, encoding;
    if (typeof params === 'string') {
        file = params;
    } else if (Array.isArray(params) && params.length === 2) {
        file = params[0];
        encoding = params[1];
    }
    if (
        typeof file === 'string' &&
        (encoding === undefined || typeof encoding === 'string')
    ) {
        file = fn.$path(file);
        const fs = require('fs');
        if (fs.existsSync(file) && fs.lstatSync(file).isFile()) {
            return fs.readFileSync(file, { encoding });
        }
    }
    throw new Error(
        '$file expects a string or an array with two string elements'
    );
}
362930
function (/*String*/path, /*String?*/encoding) {
            if (encoding === 'utf-8') {
                encoding = 'utf8';
            }
            if (!encoding) {
                encoding = 'utf8';
            }

            var text = fs.readFileSync(path, encoding);

            //Hmm, would not expect to get A BOM, but it seems to happen,
            //remove it just in case.
            if (text.indexOf('\uFEFF') === 0) {
                text = text.substring(1, text.length);
            }

            return text;
        }
1203759
def hash_file(path, hashobj, conn=None):
    '''
    
    '''
    if os.path.isdir(path):
        return ''

    with salt.utils.files.fopen(path, 'r') as f:
        hashobj.update(salt.utils.stringutils.to_bytes(f.read()))
        return hashobj.hexdigest()
1269302
def write_and_get_hash(path, write_to_file, hash=None):
    
    hash = hash or hashlib.md5()
    try:
        # Access path
        r = config.DOWNLOAD_SESSION.get(path, stream=True)
        r.raise_for_status()
        for chunk in r:
            write_to_file.write(chunk)
            hash.update(chunk)

    except (MissingSchema, InvalidSchema):
        # If path is a local file path, try to open the file (generate hash if none provided)
        with open(path, 'rb') as fobj:
            for chunk in iter(lambda: fobj.read(2097152), b""):
                write_to_file.write(chunk)
                hash.update(chunk)

    assert write_to_file.tell() > 0, "File failed to write (corrupted)."

    return hash
822327
def _hash_file(self, path):
        

        m = hashlib.md5()
        with open(path, "rb") as f:
            while True:
                buf = f.read(128)
                if not buf:
                    break
                m.update(buf)
        return m.hexdigest()
213303
function digestFile(file, algorithm, encoding) {
    return crypto.createHash(algorithm || 'md5').update(fs.readFileSync(file)).digest(encoding || 'hex');
}
671779
function md5Hash(val) {
        if (!val) { return val; }

        var str = _.isObject(val) ? JSON.stringify(val) : val;
        var md5 = crypto.createHash('md5');
        md5.update(str);
        return md5.digest('hex');
    }
670081
public static String md5File(String filePath) {
        File file = StringKit.isBlank(filePath) ? null : new File(filePath);
        return md5File(file);
    }
186863
def create_md5(path):
    """"""
    m = hashlib.md5()
    # rb necessary to run correctly in windows.
    with open(path, "rb") as f:
        while True:
            data = f.read(8192)
            if not data:
                break
            m.update(data)

    return m.hexdigest()
871091
public static byte[] decryptFile(String path, String key) {
        try {
            byte[] buf = readFile(path);
            return decrypt(buf, key);
        } catch (final Exception e) {
            logger.warn("Could not decrypt file {}", path, e);
            return null;
        }
    }
510966
function getFileHash(filePath, callback) {
  var stream = fs.ReadStream(filePath);
  var md5sum = crypto.createHash('md5');

  stream.on('data', function(data) {
    md5sum.update(data);
  });

  stream.on('end', function() {
    callback(md5sum.digest('hex'));
  });
}
79647
function readFile(path) {
  try {
    var contents = _fs2.default.readFileSync(path, { encoding: 'utf8' });

    return contents;
  } catch (error) {
    throw new Error(error);
  }
}
110
function readFile(path, fileName) {
  return new Promise((resolve, reject) => {
    fs.readFile(`${path}/${fileName}`, 'utf8', (err, content) => {
      if (err) {
        return reject(err)
      }

      return resolve(content)
    })
  })
}