How to get a usable hash code of an empty file for comparison purposes
This puzzled me for a while, but I have a solution now. Just create a hash from the file name because file contents are empty. In C#, you can use the below:
When you compare two empty files from two different servers, with the same name, they will match. If one file is not empty, because hash will be generated from the file contents the hash will be different.
So you get pretty much what you want.
public static byte[] CreateMD5Hash(List<string> dataList) { using (MemoryStream fingerStream = new MemoryStream()) { using (StreamWriter writer = new StreamWriter(fingerStream)) { foreach (string data in dataList) { writer.Write(item); } writer.Flush(); fingerStream.Position = 0; MD5 md5 = new MD5CryptoServiceProvider(); return md5.ComputeHash(fingerStream); } } }
When you compare two empty files from two different servers, with the same name, they will match. If one file is not empty, because hash will be generated from the file contents the hash will be different.
So you get pretty much what you want.
Comments
Post a Comment