35 lines
847 B
Go
35 lines
847 B
Go
|
// Package bootstrap deals with the creation of bootstrap files
|
||
|
package bootstrap
|
||
|
|
||
|
import (
|
||
|
"cryptic-net/tarutil"
|
||
|
"fmt"
|
||
|
"io"
|
||
|
"io/fs"
|
||
|
)
|
||
|
|
||
|
// GetHashFromFS returns the hash of the contents of the given bootstrap file.
|
||
|
// It may return nil if the bootstrap file doesn't have a hash.
|
||
|
func GetHashFromFS(bootstrapFS fs.FS) ([]byte, error) {
|
||
|
|
||
|
b, err := fs.ReadFile(bootstrapFS, tarutil.HashBinPath)
|
||
|
|
||
|
if err != nil {
|
||
|
return nil, fmt.Errorf("reading file %q from bootstrap fs: %w", tarutil.HashBinPath, err)
|
||
|
}
|
||
|
|
||
|
return b, nil
|
||
|
}
|
||
|
|
||
|
// GetHashFromReader reads the given tgz file as an fs.FS, and passes that to
|
||
|
// GetHashFromFS.
|
||
|
func GetHashFromReader(r io.Reader) ([]byte, error) {
|
||
|
|
||
|
bootstrapFS, err := tarutil.FSFromReader(r)
|
||
|
if err != nil {
|
||
|
return nil, fmt.Errorf("reading tar fs from reader: %w", err)
|
||
|
}
|
||
|
|
||
|
return GetHashFromFS(bootstrapFS)
|
||
|
}
|