2019-10-21 00:52:16 +03:00
|
|
|
package embed
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"compress/gzip"
|
2020-09-07 09:52:42 +03:00
|
|
|
"encoding/base64"
|
2019-10-25 17:19:27 +03:00
|
|
|
"io"
|
2019-10-21 00:52:16 +03:00
|
|
|
|
2020-05-15 22:32:44 +03:00
|
|
|
"github.com/markbates/pkger/here"
|
2019-10-21 00:52:16 +03:00
|
|
|
)
|
|
|
|
|
2019-10-25 17:19:27 +03:00
|
|
|
func Decode(src []byte) ([]byte, error) {
|
2020-09-07 09:52:42 +03:00
|
|
|
dst := make([]byte, base64.RawStdEncoding.DecodedLen(len(src)))
|
|
|
|
_, err := base64.RawStdEncoding.Decode(dst, src)
|
2019-10-25 17:19:27 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-10-21 00:52:16 +03:00
|
|
|
|
2019-10-25 17:19:27 +03:00
|
|
|
r, err := gzip.NewReader(bytes.NewReader(dst))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-10-21 00:52:16 +03:00
|
|
|
|
2019-10-25 17:19:27 +03:00
|
|
|
bb := &bytes.Buffer{}
|
|
|
|
if _, err := io.Copy(bb, r); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return bb.Bytes(), nil
|
2019-10-21 00:52:16 +03:00
|
|
|
}
|
|
|
|
|
2019-10-25 17:19:27 +03:00
|
|
|
func Encode(b []byte) ([]byte, error) {
|
2019-10-21 00:52:16 +03:00
|
|
|
bb := &bytes.Buffer{}
|
|
|
|
gz := gzip.NewWriter(bb)
|
2019-10-25 17:19:27 +03:00
|
|
|
|
|
|
|
if _, err := gz.Write(b); err != nil {
|
2019-10-21 00:52:16 +03:00
|
|
|
return nil, err
|
|
|
|
}
|
2019-10-25 17:19:27 +03:00
|
|
|
|
|
|
|
if err := gz.Flush(); err != nil {
|
2019-10-21 00:52:16 +03:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-10-25 17:19:27 +03:00
|
|
|
if err := gz.Close(); err != nil {
|
|
|
|
return nil, err
|
2019-10-21 00:52:16 +03:00
|
|
|
}
|
|
|
|
|
2020-09-07 09:52:42 +03:00
|
|
|
s := base64.RawStdEncoding.EncodeToString(bb.Bytes())
|
2019-10-25 17:19:27 +03:00
|
|
|
return []byte(s), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type Data struct {
|
|
|
|
Infos map[string]here.Info `json:"infos"`
|
|
|
|
Files map[string]File `json:"files"`
|
|
|
|
Here here.Info `json:"here"`
|
2019-10-21 00:52:16 +03:00
|
|
|
}
|