blob: 880396acda62abb3205db43aa77483c85bbee3dc (
plain)
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
|
package storage
import (
"crypto/sha256"
"fmt"
"io"
)
type WalkMode int
const (
Folder WalkMode = iota
File
FileFolder
)
type Storage interface {
Walk(path string, walkMode WalkMode) <-chan string
Get(path string) (io.Reader, error)
Put(path string, f io.Reader) error
List(path string) ([]string, error)
Move(src string, dest string) error
Copy(src string, dest string) error
Mkdir(path string) error
Exists(path string) (bool, error)
}
func CalculateSHA256(r io.Reader) (string, error) {
h := sha256.New()
if _, err := io.Copy(h, r); err != nil {
return "", err
}
return fmt.Sprintf("%x", h.Sum(nil)), nil
}
|