You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/tools/build/metadata.go

32 lines
592 B

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
}