本文整理汇总了C#中Chunk.CalculateHash方法的典型用法代码示例。如果您正苦于以下问题:C# Chunk.CalculateHash方法的具体用法?C# Chunk.CalculateHash怎么用?C# Chunk.CalculateHash使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Chunk
的用法示例。
在下文中一共展示了Chunk.CalculateHash方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateHash
public void CalculateHash()
{
Complete = 0;
MD4Context md4Context = new MD4Context();
if (ChunkCount == 1)
{
byte[] data = new byte[_fileStream.Length];
_fileStream.Read(data, 0, data.Length);
Chunk newChunk = new Chunk(data);
newChunk.CalculateHash();
_hash = newChunk.MD4Digest.ToString();
Complete = 1;
return;
}
Parallel.Invoke(new Action[]
{
() =>
{
for (int i = 0; i < ChunkCount; i++)
{
byte[] data = new byte[_fileStream.Length - _fileStream.Position > ChunkSize
? ChunkSize
: _fileStream.Length - _fileStream.Position];
_fileStream.Read(data, 0, data.Length);
Chunk newChunk = new Chunk(data) {Last = _fileStream.Position == _fileStream.Length};
ThreadPool.QueueUserWorkItem(o => newChunk.CalculateHash());
//Blocks if the queue is full
_processQueue.Add(newChunk);
}
},
() =>
{
Chunk currentChunk;
do
{
//Blocks if the queue is empty
currentChunk = _processQueue.Take();
//Blocks if the chunk hash is still calculating
currentChunk.Done.WaitOne();
byte[] chunkHash = currentChunk.MD4Digest.ToArray();
md4Context.Update(chunkHash, 0, chunkHash.Length);
Complete++;
} while (!currentChunk.Last);
}
});
_hash = md4Context.GetDigest().ToString();
}