Exemplo n.º 1
0
        protected string CalculateHash(long count)
        {
            using (var fileStream = File.OpenRead())
            {
                do
                {
                    var buffer = new byte[65536];

                    if (count < buffer.Length)
                    {
                        buffer = new byte[count];
                    }

                    var bytesRead = fileStream.Read(buffer, 0, buffer.Length);

                    if (bytesRead > 0)
                    {
                        HashProvider.Append(buffer, 0, buffer.Length);
                    }

                    count -= bytesRead;
                } while (count > 0);
            }

            return(HashProvider.GetComputedHashAsString());
        }
Exemplo n.º 2
0
        protected async Task <string> CalculateHashAsync(long count)
        {
            var localHash = MD5HashProviderFactory.GetHashProvider().CreateHash();
            var buffer    = new byte[Configuration.BufferSize];

            do
            {
                var bytesToRead = count < Configuration.BufferSize ? (int)count : Configuration.BufferSize;
                var bytesRead   = await FileStream.ReadAsync(buffer, 0, bytesToRead);

                if (bytesRead > 0)
                {
                    localHash.Append(buffer, 0, bytesToRead);
                    HashProvider.Append(buffer, 0, bytesToRead);
                }
                count -= bytesRead;
            } while (count > 0);
            localHash.Finalize(new byte[1], 0, 0);
            FileStream.Seek(0, SeekOrigin.Begin);
            return(localHash.GetComputedHashAsString());
        }
Exemplo n.º 3
0
        protected async Task <string> CalculateHashAsync(long count)
        {
            var localHash = MD5HashProviderFactory.GetHashProvider().CreateHash();

            using (var fileStream = await File.OpenReadAsync())
            {
                var buffer = new byte[DefaultBufferLength];
                do
                {
                    var bytesToRead = count < DefaultBufferLength ? (int)count : DefaultBufferLength;
                    var bytesRead   = fileStream.Read(buffer, 0, bytesToRead);
                    if (bytesRead > 0)
                    {
                        localHash.Append(buffer, 0, bytesToRead);
                        HashProvider.Append(buffer, 0, bytesToRead);
                    }
                    count -= bytesRead;
                } while (count > 0);
            }
            localHash.Finalize(new byte[1], 0, 0);
            return(localHash.GetComputedHashAsString());
        }
Exemplo n.º 4
0
        protected string CalculateHash(long count)
        {
            do
            {
                var buffer = new byte[Configuration.BufferSize];

                if (count < buffer.Length)
                {
                    buffer = new byte[count];
                }

                var bytesRead = FileStream.Read(buffer, 0, buffer.Length);

                if (bytesRead > 0)
                {
                    HashProvider.Append(buffer, 0, buffer.Length);
                }

                count -= bytesRead;
            } while (count > 0);

            FileStream.Seek(0, SeekOrigin.Begin);
            return(HashProvider.GetComputedHashAsString());
        }