Skip to content

Commit

Permalink
Added GetFileChecksum
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir2217 committed Jan 2, 2025
1 parent 13dc9fa commit 9f38bfc
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions FileSystem/FileInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package FileSystem

import (
"bufio"
"encoding/hex"
"encoding/json"
"github.com/RENCI/GoUtils/Collections"
"hash"
"io"
"os"
)
Expand Down Expand Up @@ -81,6 +83,22 @@ func (this *FileInfo) ReadFileLines() (Collections.List[string], error) {
return res, nil
}

func (this *FileInfo) GetFileChecksum(hash hash.Hash) (string, error) {
//println(filePath)
//defer timeTrack(time.Now(), fmt.Sprintf("getFileChecksum [%s]: ", filePath))
file, err := os.Open(this.Path)
if err != nil {
return "", err
}
defer file.Close()

if _, err := io.Copy(hash, file); err != nil {
return "", err
}
hashstr := hex.EncodeToString(hash.Sum(nil))
return hashstr, nil
}

func (this *FileInfo) LoadJSON() (interface{}, error) {
var data interface{}
fileData, err := os.ReadFile(this.Path)
Expand Down

0 comments on commit 9f38bfc

Please sign in to comment.