mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-31 22:18:45 +00:00
feat : CRC工具类增加获取整形值的方法
This commit is contained in:
@@ -73,6 +73,17 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
private uint _currentCrc;
|
private uint _currentCrc;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the computed hash value.
|
||||||
|
/// </summary>
|
||||||
|
public uint CRCValue
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _currentCrc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="CRC32Algorithm"/> class.
|
/// Initializes a new instance of the <see cref="CRC32Algorithm"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -339,6 +339,11 @@ namespace YooAsset
|
|||||||
byte[] buffer = Encoding.UTF8.GetBytes(str);
|
byte[] buffer = Encoding.UTF8.GetBytes(str);
|
||||||
return BytesCRC32(buffer);
|
return BytesCRC32(buffer);
|
||||||
}
|
}
|
||||||
|
public static uint StringCRC32Value(string str)
|
||||||
|
{
|
||||||
|
byte[] buffer = Encoding.UTF8.GetBytes(str);
|
||||||
|
return BytesCRC32Value(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取文件的CRC32
|
/// 获取文件的CRC32
|
||||||
@@ -350,6 +355,13 @@ namespace YooAsset
|
|||||||
return StreamCRC32(fs);
|
return StreamCRC32(fs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static uint FileCRC32Value(string filePath)
|
||||||
|
{
|
||||||
|
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||||
|
{
|
||||||
|
return StreamCRC32Value(fs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取文件的CRC32
|
/// 获取文件的CRC32
|
||||||
@@ -366,6 +378,18 @@ namespace YooAsset
|
|||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static uint FileCRC32ValueSafely(string filePath)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return FileCRC32Value(filePath);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
YooLogger.Exception(e);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取数据流的CRC32
|
/// 获取数据流的CRC32
|
||||||
@@ -376,6 +400,12 @@ namespace YooAsset
|
|||||||
byte[] hashBytes = hash.ComputeHash(stream);
|
byte[] hashBytes = hash.ComputeHash(stream);
|
||||||
return ToString(hashBytes);
|
return ToString(hashBytes);
|
||||||
}
|
}
|
||||||
|
public static uint StreamCRC32Value(Stream stream)
|
||||||
|
{
|
||||||
|
CRC32Algorithm hash = new CRC32Algorithm();
|
||||||
|
hash.ComputeHash(stream);
|
||||||
|
return hash.CRCValue;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取字节数组的CRC32
|
/// 获取字节数组的CRC32
|
||||||
@@ -386,6 +416,12 @@ namespace YooAsset
|
|||||||
byte[] hashBytes = hash.ComputeHash(buffer);
|
byte[] hashBytes = hash.ComputeHash(buffer);
|
||||||
return ToString(hashBytes);
|
return ToString(hashBytes);
|
||||||
}
|
}
|
||||||
|
public static uint BytesCRC32Value(byte[] buffer)
|
||||||
|
{
|
||||||
|
CRC32Algorithm hash = new CRC32Algorithm();
|
||||||
|
hash.ComputeHash(buffer);
|
||||||
|
return hash.CRCValue;
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user