Exemple #1
0
 public static UInt32 CheckSumFile(string fileName)
 {
     CRC32 crc = new CRC32 ();
     int bufferLen = 32 * 1024;
     using (FileStream fs = File.OpenRead(fileName)) {
         byte[] buffer = new byte[bufferLen];
         while (true) {
             int n = fs.Read (buffer, 0, bufferLen);
             if (n == 0)
                 break;
             crc.Write (buffer, 0, n);
         }
     }
     return crc.Sum32 ();
 }
Exemple #2
0
 /// <summary>
 /// 计算沙盒文件的crc32值
 /// </summary>
 /// <param name="filePath">沙盒文件全路径</param>
 /// <returns>crc32值</returns>
 public static UInt32 CheckSumFile(string filePath)
 {
     CRC32 crc = new CRC32();
     int bufferLen = 32 * 1024;
     using (FileStream fs = IsolatedStorageFile.GetUserStoreForApplication().OpenFile(filePath, FileMode.Open, FileAccess.Read))
     {
         byte[] buffer = new byte[bufferLen];
         while (true)
         {
             int n = fs.Read(buffer, 0, bufferLen);
             if (n == 0)
                 break;
             crc.Write(buffer, 0, n);
         }
     }
     return crc.Sum32();
 }
Exemple #3
0
 public static UInt32 CheckSumSlice(byte[] data, int offset, int count)
 {
     CRC32 crc = new CRC32();
     crc.Write(data, offset, count);
     return crc.Sum32();
 }
Exemple #4
0
 /// <summary>
 /// 计算字节数据的crc32值
 /// </summary>
 /// <param name="data">二进制数据</param>
 /// <param name="length">长度</param>
 /// <returns>crc32值</returns>
 public static UInt32 CheckSumBytes(byte[] data)
 {
     CRC32 crc = new CRC32();
     crc.Write(data, 0, data.Length);
     return crc.Sum32();
 }