Skip to content

Commit

Permalink
Fix bug in read file for hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
nRafinia committed Mar 11, 2023
1 parent 2f905dc commit 70ad15e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/nHash/Features/HashAlgorithmFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class HashAlgorithmFeature : IFeature
public HashAlgorithmFeature()
{
_algorithmType = new Argument<AlgorithmType>("type", "Algorithm type");
_textArgument = new Argument<string>("text", "Text for calculate fingerprint");
_textArgument = new Argument<string>("text", GetDefaultString, "Text for calculate fingerprint");
_fileName = new Option<string>(name: "--file", description: "File name for calculate hash");
_lowerCase = new Option<bool>(name: "--lower", description: "Generate lower case");
}
Expand Down Expand Up @@ -46,6 +46,12 @@ private static void CalculateText(string text, AlgorithmType algorithmType, bool

if (!string.IsNullOrWhiteSpace(fileName))
{
if (!File.Exists(fileName))
{
Console.WriteLine($"File {fileName} does not exists!");
return;
}

var fileBytes = File.ReadAllBytes(fileName);
CalculateHash(fileBytes, algorithmType, lowerCase);
}
Expand Down Expand Up @@ -73,4 +79,6 @@ private static void CalculateHash(byte[] inputBytes, AlgorithmType algorithmType

Console.WriteLine(hashedText);
}

private static string GetDefaultString() => string.Empty;
}

0 comments on commit 70ad15e

Please sign in to comment.