mirror of
https://github.com/celogeek/piwigo-cli.git
synced 2025-05-25 10:12:37 +02:00
move md5 tools
This commit is contained in:
parent
6a3bac66d9
commit
ed52dd691c
22
internal/md5/file.go
Normal file
22
internal/md5/file.go
Normal 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
|
||||||
|
}
|
@ -4,6 +4,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/celogeek/piwigo-cli/internal/md5"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FileToUpload struct {
|
type FileToUpload struct {
|
||||||
@ -26,7 +28,7 @@ func (f *FileToUpload) Checked() bool {
|
|||||||
|
|
||||||
func (f *FileToUpload) MD5() string {
|
func (f *FileToUpload) MD5() string {
|
||||||
if f.md5 == nil {
|
if f.md5 == nil {
|
||||||
md5, err := Md5File(f.FullPath())
|
md5, err := md5.File(f.FullPath())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
@ -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
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user