package util

import (
	"crypto/md5"
	"encoding/hex"
	"io"
	"os"
)

type MD5 struct {
}

func (md *MD5) FileMD5(filename string) (string, int64, error) {
	file, err := os.Open(filename)
	if err != nil {
		return "", 0, err
	}
	defer file.Close()
	var len int64 = 0
	md5 := md5.New()
	if len, err = io.Copy(md5, file); err != nil {
		return "", 0, err
	}
	md5Str := hex.EncodeToString(md5.Sum(nil))
	return md5Str, len, nil
}

func NewMD5CheckSum() *MD5 {
	return &MD5{}
}
