move md5 tools

This commit is contained in:
Celogeek 2021-12-31 12:55:37 +01:00
parent 6a3bac66d9
commit ed52dd691c
Signed by: celogeek
GPG Key ID: E6B7BDCFC446233A
3 changed files with 25 additions and 25 deletions

22
internal/md5/file.go Normal file
View File

@ -0,0 +1,22 @@
package md5
import (
"crypto/md5"
"fmt"
"io"
"os"
)
func File(filename string) (string, error) {
file, err := os.Open(filename)
if err != nil {
return "", err
}
defer file.Close()
hash := md5.New()
if _, err = io.Copy(hash, file); err != nil {
return "", err
}
return fmt.Sprintf("%x", hash.Sum(nil)), nil
}

View File

@ -4,6 +4,8 @@ import (
"os"
"path/filepath"
"strings"
"github.com/celogeek/piwigo-cli/internal/md5"
)
type FileToUpload struct {
@ -26,7 +28,7 @@ func (f *FileToUpload) Checked() bool {
func (f *FileToUpload) MD5() string {
if f.md5 == nil {
md5, err := Md5File(f.FullPath())
md5, err := md5.File(f.FullPath())
if err != nil {
return ""
}

View File

@ -1,24 +0,0 @@
package piwigotools
import (
"crypto/md5"
"fmt"
"io"
"os"
)
func Md5File(filename string) (result string, err error) {
file, err := os.Open(filename)
if err != nil {
return
}
defer file.Close()
hash := md5.New()
_, err = io.Copy(hash, file)
if err != nil {
return
}
result = fmt.Sprintf("%x", hash.Sum(nil))
return
}