-
Notifications
You must be signed in to change notification settings - Fork 0
/
page_selection.go
45 lines (35 loc) · 889 Bytes
/
page_selection.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
42
43
44
45
package store_verzeichnisse
import (
"crypto/sha256"
"io"
"strconv"
"strings"
"github.com/friedenberg/zit/src/alfa/errors"
"github.com/friedenberg/zit/src/alfa/schnittstellen"
"github.com/friedenberg/zit/src/charlie/sha"
"github.com/friedenberg/zit/src/echo/kennung"
)
func (i Store) PageForKennung(h kennung.Kennung) (n int, err error) {
s := sha.FromStringer(h)
return i.PageForSha(s)
}
func (i Store) PageForString(s string) (n int, err error) {
sr := strings.NewReader(s)
hash := sha256.New()
if _, err = io.Copy(hash, sr); err != nil {
err = errors.Wrap(err)
return
}
sh := sha.FromHash(hash)
return i.PageForSha(sh)
}
func (i Store) PageForSha(s schnittstellen.ShaLike) (n int, err error) {
var n1 int64
ss := s.String()[:DigitWidth]
if n1, err = strconv.ParseInt(ss, 16, 64); err != nil {
err = errors.Wrap(err)
return
}
n = int(n1)
return
}