-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathutil.go
More file actions
43 lines (37 loc) · 908 Bytes
/
util.go
File metadata and controls
43 lines (37 loc) · 908 Bytes
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
package internal
import (
"encoding/ascii85"
"errors"
"time"
)
func MaxEncodedLen(n int) int {
return ascii85.MaxEncodedLen(n)
}
func EncodeToString(src []byte) string {
dst := make([]byte, MaxEncodedLen(len(src)))
n := ascii85.Encode(dst, src)
dst = dst[:n]
return BytesToString(dst)
}
func DecodeString(src string) ([]byte, error) {
dst := make([]byte, len(src))
ndst, nsrc, err := ascii85.Decode(dst, StringToBytes(src), true)
if err != nil {
return nil, err
}
if nsrc != len(src) {
return nil, errors.New("ascii85: src is not fully decoded")
}
return dst[:ndst], nil
}
//------------------------------------------------------------------------------
// CleanupTimer will stop a timer and purge the timer's channel to ensure
// all timer related resources are cleaned up.
func CleanupTimer(timer *time.Timer) {
if !timer.Stop() {
select {
case <-timer.C:
default:
}
}
}