Skip to content

Зыков М. А., ПрИ-101 - #2

Open
0xddi wants to merge 5 commits into
MindHardt:masterfrom
0xddi:feature/from-my-master
Open

Зыков М. А., ПрИ-101#2
0xddi wants to merge 5 commits into
MindHardt:masterfrom
0xddi:feature/from-my-master

Conversation

@0xddi

@0xddi 0xddi commented Dec 12, 2025

Copy link
Copy Markdown

Для потокобезопасности по итогу воспользовался SemaphoreSlim, т.к. судя по всему lock не очень дружит с асинхронщиной внутри него самого (в частности, внутри должен быть await contentStream.CopyToAsync(destStream, ct)). Как-то так.

Валидация пути для сохранения файла через попытку создания одноимённого файла (при условии его несуществования) слишком прямолинейная, но зато вроде оптимальная по кол-ву кода. Проверка на разрешённые символы бесполезна, регулярки тоже, а отдельно проверять существование директории и ещё в придачу права на запись туда как-то излишне, на мой взгляд. Может я, конечно, не прав.

Comment thread App/Input.cs Outdated
}

private static bool IsValidUri(string uri) => uri.StartsWith("https://");
private static bool IsValidUri(string uri) => Uri.TryCreate(uri, UriKind.Absolute, out _) && uri.StartsWith("https://");

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Нам не обязательно чтобы был https, локалхост или штуки доступные только внутри сети часто http

Comment thread App/Input.cs Outdated
/// Считывает от пользователя путь до файла с результатом.
/// </summary>
public static FileInfo GetOutputFile()
public static FileInfo GetPathToOutputFile()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Ты получаешь не Path, а прям полный FileInfo, зря переименовал

Comment thread App/Input.cs Outdated
{
Console.WriteLine("[?] Файл уже существует. Хотите ли вы его перезаписать? [y/n]");
Console.Write(">>");
var answer = Console.ReadLine()!.Trim().ToLower();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Не обязательно считывать всю строку, можно Console.ReadKey()

Comment thread App/Misc.cs Outdated

using (StreamReader reader = new StreamReader(filePath.FullName))
{
while (reader.ReadLine() != null)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Здесь стоит юзать асинк версию (всегда стоит юзать асинк версию)

Comment thread App/Misc.cs Outdated


// Несколько попыток удаления
for (int i = 0; i < 3; i++)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Зачем тебе такое нужно?

Comment thread App/Program.cs Outdated
await content.CopyToAsync(destStream, ct);
});
// закрываем FileStream асинхронно
if (fileStreamIsClosed is false)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Эта проверка не обязательна, файлстрим можно диспозить несколько раз, он не против

@MindHardt MindHardt left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Ревью

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.

2 participants