AcTools.Utils.FileUtils.FastChecksum C# (CSharp) Method

FastChecksum() public static method

public static FastChecksum ( string filename ) : string
filename string
return string
        public static string FastChecksum(string filename) {
            var blockSize = 500;
            byte[] result;

            var md5 = MD5.Create();
            using (var file = File.OpenRead(filename)) {
                if (file.Length < blockSize * 3) {
                    result = md5.ComputeHash(file);
                } else {
                    var temp = new byte[blockSize * 3];
                    file.Read(temp, 0, blockSize);
                    file.Seek((file.Length - blockSize / 2), SeekOrigin.Begin);
                    file.Read(temp, blockSize, blockSize);
                    file.Seek(-blockSize, SeekOrigin.End);
                    file.Read(temp, blockSize * 2, blockSize);

                    result = md5.ComputeHash(temp, 0, temp.Length);
                }
            }

            var sb = new StringBuilder();
            foreach (var t in result) {
                sb.Append(t.ToString("X2"));
            }
            return sb.ToString();
        }