1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-04 09:17:32 -05:00
v2fly/tools/build/metadata.go

32 lines
592 B
Go

package main
import (
"crypto/sha1"
"encoding/hex"
"fmt"
"io"
"os"
"path/filepath"
)
func CalcMetadata(file string, writer io.Writer) error {
fileReader, err := os.Open(file)
if err != nil {
return err
}
defer fileReader.Close()
hasher := sha1.New()
nBytes, err := io.Copy(hasher, fileReader)
if err != nil {
return err
}
sha1sum := hasher.Sum(nil)
filename := filepath.Base(file)
fmt.Fprintf(writer, "File: %s\n", filename)
fmt.Fprintf(writer, "Size: %d\n", nBytes)
fmt.Fprintf(writer, "SHA1: %s\n", hex.EncodeToString(sha1sum))
fmt.Fprintln(writer)
return nil
}