Add a lot of functions to Base
This commit is contained in:
26
Base/FileEx.vb
Normal file
26
Base/FileEx.vb
Normal 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
|
||||
Reference in New Issue
Block a user