package utils

import (
	"hash/fnv"
	"io"
	"mime/multipart"
	"os"
)

func FileHashFromUpload(file multipart.File) (uint64, error) {
	h := fnv.New64a()
	if _, err := io.Copy(h, file); err != nil {
		return 0, err
	}

	return h.Sum64(), nil
}

func FileHash(path string) (uint64, error) {
	f, err := os.Open(path)
	if err != nil {
		return 0, err
	}
	defer f.Close()

	h := fnv.New64a()
	if _, err := io.Copy(h, f); err != nil {
		return 0, err
	}

	return h.Sum64(), nil
}
