Skip to content

Commit

Permalink
Add sha384 file hash and GetBinDir
Browse files Browse the repository at this point in the history
  • Loading branch information
TheArcaneBrony committed Mar 15, 2024
1 parent d74542f commit e94a5b1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions ArcaneLibs/FileUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Reflection;
using System.Security.Cryptography;

namespace ArcaneLibs;

public static class FileUtils {
public static async Task<string> GetFileSha384Async(string path) {
using var sha384 = SHA384.Create();
await using var stream = File.OpenRead(path);
return Convert.ToBase64String(await sha384.ComputeHashAsync(stream));
}

public static string GetBinDir() {
var assembly = Assembly.GetEntryAssembly();
var uri = new Uri(assembly!.Location);

Check warning on line 15 in ArcaneLibs/FileUtils.cs

View workflow job for this annotation

GitHub Actions / build

'System.Reflection.Assembly.Location' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'.
return Path.GetDirectoryName(uri.LocalPath)!;
}
}
4 changes: 2 additions & 2 deletions ArcaneLibs/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public static async IAsyncEnumerable<string> GetCommandOutputInDirAsync(string p
}

public static string BytesToString(long byteCount, int maxnums = 2) {
string[] suf = { "B", "kiB", "MiB", "GiB", "TiB", "PiB", "EiB" }; //Longs run out around EB
string[] suf = ["B", "kiB", "MiB", "GiB", "TiB", "PiB", "EiB"]; //Longs run out around EB
if (byteCount == 0)
return "0 " + suf[0];
var bytes = Math.Abs(byteCount);
Expand All @@ -170,7 +170,7 @@ public static string BytesToString(long byteCount, int maxnums = 2) {
}

public static string SI_BytesToString(long byteCount, int maxnums = 2) {
string[] suf = { "B", "kB", "MB", "GB", "TB", "PB", "EB" }; //Longs run out around EB
string[] suf = ["B", "kB", "MB", "GB", "TB", "PB", "EB"]; //Longs run out around EB
if (byteCount == 0)
return "0 " + suf[0];
var bytes = Math.Abs(byteCount);
Expand Down

0 comments on commit e94a5b1

Please sign in to comment.