Add a lot of functions to Base

This commit is contained in:
Jonathan Jenne
2023-06-16 09:16:49 +02:00
parent 00cff028c9
commit b1114545a7
8 changed files with 359 additions and 0 deletions

26
Base/FileEx.vb Normal file
View File

@@ -0,0 +1,26 @@
Imports System.IO
Imports System.Security.Cryptography
Public Class FileEx
''' <summary>
''' Reads the file at `FilePath` and computes a SHA256 Hash from its contents
''' </summary>
''' <param name="pFilePath"></param>
''' <returns></returns>
Public Function GetChecksumFromFileContents(pFilePath As String) As String
Try
Using oFileStream = IO.File.OpenRead(pFilePath)
Using oStream As New BufferedStream(oFileStream, 1200000)
Dim oChecksum() As Byte = SHA256.Create.ComputeHash(oStream)
Return BaseUtils.FormatHash(oChecksum)
End Using
End Using
Catch ex As Exception
Return Nothing
End Try
End Function
Public Function GetHashFromFileContents(pFilePath As String) As String
Return GetChecksumFromFileContents(pFilePath)
End Function
End Class