修复大文件计算hash抛异常的问题
This commit is contained in:
parent
00db7a863b
commit
308787072d
2 changed files with 8 additions and 7 deletions
|
@ -133,14 +133,15 @@ namespace iFileProxy.Helpers
|
||||||
byte[] hash = [];
|
byte[] hash = [];
|
||||||
if (File.Exists(fileName))
|
if (File.Exists(fileName))
|
||||||
{
|
{
|
||||||
|
using FileStream fileStream = File.OpenRead(fileName);
|
||||||
hash = algorithm switch
|
hash = algorithm switch
|
||||||
{
|
{
|
||||||
FileHashAlgorithm.MD5 => MD5.HashData(File.ReadAllBytes(fileName)),
|
FileHashAlgorithm.MD5 => MD5.HashData(fileStream),
|
||||||
FileHashAlgorithm.SHA1 => SHA1.HashData(File.ReadAllBytes(fileName)),
|
FileHashAlgorithm.SHA1 => SHA1.HashData(fileStream),
|
||||||
FileHashAlgorithm.SHA256 => SHA256.HashData(File.ReadAllBytes(fileName)),
|
FileHashAlgorithm.SHA256 => SHA256.HashData(fileStream),
|
||||||
FileHashAlgorithm.SHA384 => SHA384.HashData(File.ReadAllBytes(fileName)),
|
FileHashAlgorithm.SHA384 => SHA384.HashData(fileStream),
|
||||||
FileHashAlgorithm.SHA512 => SHA512.HashData(File.ReadAllBytes(fileName)),
|
FileHashAlgorithm.SHA512 => SHA512.HashData(fileStream),
|
||||||
_ => MD5.HashData(File.ReadAllBytes(fileName)),
|
_ => MD5.HashData(fileStream),
|
||||||
};
|
};
|
||||||
StringBuilder sBuilder = new StringBuilder();
|
StringBuilder sBuilder = new StringBuilder();
|
||||||
for (int i = 0; i < hash.Length; i++)
|
for (int i = 0; i < hash.Length; i++)
|
||||||
|
|
|
@ -268,7 +268,7 @@ namespace iFileProxy.Services
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.Fatal($"执行下载任务时候出现致命问题: {ex.Message}");
|
_logger.Fatal("task: {taskid} 执行下载任务时候出现致命问题: {ex}",taskInfo.TaskId, ex);
|
||||||
taskInfo.Status= TaskState.Error;
|
taskInfo.Status= TaskState.Error;
|
||||||
|
|
||||||
_dbGateService.UpdateTaskStatus(taskInfo);
|
_dbGateService.UpdateTaskStatus(taskInfo);
|
||||||
|
|
Loading…
Reference in a new issue