Skip to content

Initial commit - #26

Open
Palezehvat wants to merge 1 commit into
masterfrom
Md5
Open

Palezehvat wants to merge 1 commit into
masterfrom
Md5

Conversation

@Palezehvat

Copy link
Copy Markdown
Owner

No description provided.

Comment thread MD5/MD5/MultiThreadMD5.cs
using System.Text;
using System.Security.Cryptography;

namespace Md5;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше неймспейс в самом начале файла (после шапки с лицензией)

Comment thread MD5/MD5/MultiThreadMD5.cs

namespace Md5;

public class MultiThreadMD5

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Самому классу тоже нужен комментарий
  • Все методы static, значит и сам класс по логике вещей должен быть static

Comment thread MD5/MD5/MultiThreadMD5.cs
{
throw new FileNotFoundException();
}
var fstream = File.OpenRead(path);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var fstream = File.OpenRead(path);
using var fstream = File.OpenRead(path);

Comment thread MD5/MD5/MultiThreadMD5.cs
}
var fstream = File.OpenRead(path);
using var md5 = MD5.Create();
byte[] buffer = new byte[fstream.Length];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
byte[] buffer = new byte[fstream.Length];
var buffer = new byte[fstream.Length];

Comment thread MD5/MD5/MultiThreadMD5.cs
var fstream = File.OpenRead(path);
using var md5 = MD5.Create();
byte[] buffer = new byte[fstream.Length];
await fstream.ReadAsync(buffer, 0, buffer.Length);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачитывать весь файл в массив может быть хорошей идеей, если мы знаем, что у нас ОЧЕНЬ маленькие файлы и ОЧЕНЬ много оперативки. Поэтому у ComputeHash есть перегрузка, принимающая Stream (она сама вычитывает файл порциями и считает хеш поблочно).

Comment thread MD5/MD5/Program.cs
{
Console.WriteLine("Далее будет выполнено сравнение Md5 hash с использованием многопоточности и без неё");
Console.WriteLine("Введите путь до дирректории");
var pathToDirrectory = Console.ReadLine();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var pathToDirrectory = Console.ReadLine();
var pathToDirectory = Console.ReadLine();

Comment thread MD5/MD5/Program.cs
var pathToDirrectory = Console.ReadLine();
if (pathToDirrectory == null )
{
throw new NullReferenceException();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Никогда не кидайте NullReferenceException, оно всегда должно указывать на ошибку в коде (и кидаться .NET-машиной).

Comment thread MD5/MD5/Program.cs
{
throw new NullReferenceException();
}
Stopwatch stopwatchForDirrectory = new Stopwatch();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Stopwatch stopwatchForDirrectory = new Stopwatch();
Stopwatch stopwatchForDirectory = new();

}
var fstream = File.OpenRead(path);
using var md5 = MD5.Create();
return md5.ComputeHash(fstream);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кажется, это можно было бы переиспользовать и в многопоточном варианте.

Comment thread MD5/TestsMD5/TestsMD5.cs
public void IsThrowExceptionWhenIncorrectPathFileInMultiThread()
{
Assert.ThrowsAsync<FileNotFoundException>(() => MultiThreadMD5.CalculateFile(pathDirectory + "/ttrt.txt"));
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно было бы использовать TestCaseSource, чтобы избежать копипаста.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants