-
Notifications
You must be signed in to change notification settings - Fork 0
/
base64.go
32 lines (29 loc) · 897 Bytes
/
base64.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
package xbase64
import "encoding/base64"
func EncodeRawStd(source []byte) (base64Bytes []byte) {
enc := base64.RawStdEncoding
base64Bytes = make([]byte, enc.EncodedLen(len(source)))
enc.Encode(base64Bytes, source)
return base64Bytes
}
func DecodeRawStd(base64Bytes []byte) (source []byte, err error) {
enc := base64.RawStdEncoding
dbuf := make([]byte, enc.DecodedLen(len(base64Bytes)))
n, err := enc.Decode(dbuf, base64Bytes)
return dbuf[:n], err
}
func EncodeRawURL(src []byte) (base64Bytes []byte) {
enc := base64.RawURLEncoding
base64Bytes = make([]byte, enc.EncodedLen(len(src)))
enc.Encode(base64Bytes, src)
return base64Bytes
}
func DecodeRawURL(base64Bytes []byte) (source []byte, err error) {
enc := base64.RawURLEncoding
dbuf := make([]byte, enc.DecodedLen(len(base64Bytes)))
n, err := enc.Decode(dbuf, base64Bytes);
if err != nil {
return
}
return dbuf[:n], err
}