/
pfs.go
41 lines (34 loc) · 908 Bytes
/
pfs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package pfs
import (
"crypto/sha512"
"encoding/base64"
"encoding/hex"
"fmt"
"hash"
)
var (
// ChunkSize is the size of file chunks when resumable upload is used
ChunkSize = int64(512 * 1024 * 1024) // 512 MB
)
// FullID prints repoName/CommitID
func (c *Commit) FullID() string {
return fmt.Sprintf("%s/%s", c.Repo.Name, c.ID)
}
// NewHash returns a hash that PFS uses internally to compute checksums.
func NewHash() hash.Hash {
return sha512.New()
}
// EncodeHash encodes a hash into a readable format.
func EncodeHash(bytes []byte) string {
return hex.EncodeToString(bytes)
}
// DecodeHash decodes a hash into bytes.
func DecodeHash(hash string) ([]byte, error) {
return hex.DecodeString(hash)
}
// GetBlock encodes a hash into a readable format in the form of a Block.
func GetBlock(hash hash.Hash) *Block {
return &Block{
Hash: base64.URLEncoding.EncodeToString(hash.Sum(nil)),
}
}