diff --git a/Assets/YooAsset/Runtime/Utility/CRC32Algorithm.cs b/Assets/YooAsset/Runtime/Utility/CRC32Algorithm.cs
index b729ea9d..f8689c60 100644
--- a/Assets/YooAsset/Runtime/Utility/CRC32Algorithm.cs
+++ b/Assets/YooAsset/Runtime/Utility/CRC32Algorithm.cs
@@ -73,6 +73,17 @@ namespace YooAsset
{
private uint _currentCrc;
+ ///
+ /// Gets the computed hash value.
+ ///
+ public uint CRCValue
+ {
+ get
+ {
+ return _currentCrc;
+ }
+ }
+
///
/// Initializes a new instance of the class.
///
diff --git a/Assets/YooAsset/Runtime/Utility/YooUtility.cs b/Assets/YooAsset/Runtime/Utility/YooUtility.cs
index c8df5589..740f96aa 100644
--- a/Assets/YooAsset/Runtime/Utility/YooUtility.cs
+++ b/Assets/YooAsset/Runtime/Utility/YooUtility.cs
@@ -339,6 +339,11 @@ namespace YooAsset
byte[] buffer = Encoding.UTF8.GetBytes(str);
return BytesCRC32(buffer);
}
+ public static uint StringCRC32Value(string str)
+ {
+ byte[] buffer = Encoding.UTF8.GetBytes(str);
+ return BytesCRC32Value(buffer);
+ }
///
/// 获取文件的CRC32
@@ -350,6 +355,13 @@ namespace YooAsset
return StreamCRC32(fs);
}
}
+ public static uint FileCRC32Value(string filePath)
+ {
+ using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
+ {
+ return StreamCRC32Value(fs);
+ }
+ }
///
/// 获取文件的CRC32
@@ -366,6 +378,18 @@ namespace YooAsset
return string.Empty;
}
}
+ public static uint FileCRC32ValueSafely(string filePath)
+ {
+ try
+ {
+ return FileCRC32Value(filePath);
+ }
+ catch (Exception e)
+ {
+ YooLogger.Exception(e);
+ return 0;
+ }
+ }
///
/// 获取数据流的CRC32
@@ -376,6 +400,12 @@ namespace YooAsset
byte[] hashBytes = hash.ComputeHash(stream);
return ToString(hashBytes);
}
+ public static uint StreamCRC32Value(Stream stream)
+ {
+ CRC32Algorithm hash = new CRC32Algorithm();
+ hash.ComputeHash(stream);
+ return hash.CRCValue;
+ }
///
/// 获取字节数组的CRC32
@@ -386,6 +416,12 @@ namespace YooAsset
byte[] hashBytes = hash.ComputeHash(buffer);
return ToString(hashBytes);
}
+ public static uint BytesCRC32Value(byte[] buffer)
+ {
+ CRC32Algorithm hash = new CRC32Algorithm();
+ hash.ComputeHash(buffer);
+ return hash.CRCValue;
+ }
#endregion
}
}
\ No newline at end of file