small pixel drawing of a pufferfish zoa

utils/utils.go

package utils

import (
	"crypto/sha256"
	"fmt"
	"io"
	"os"
)

// Copy just copiez files, it's only used by zoaCopy rn
func Copy(src, dst string) error {
	in, err := os.Open(src)
	if err != nil {
		return err
	}
	defer in.Close()

	out, err := os.Create(dst)
	if err != nil {
		return err
	}
	defer out.Close()

	_, err = io.Copy(out, in)
	if err != nil {
		return err
	}
	return out.Close()
}

func ChecksumFile(file string) (string, error) {
	f, err := os.Open(file)
	if err != nil {
		return "", err
	}
	defer f.Close()

	h := sha256.New()
	if _, err := io.Copy(h, f); err != nil {
		return "", err
	}

	checksum := fmt.Sprintf("%x", h.Sum(nil))
	return checksum, nil
}

func BluePrintln(s string) {
	colored := fmt.Sprintf("\x1b[%dm%s\x1b[0m", 34, s)
	fmt.Println(colored)
}