Use more compact base64 encoding for assets
This commit is contained in:
parent
4ac67eb1f9
commit
2e77e498f5
File diff suppressed because one or more lines are too long
@ -9,8 +9,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
"encoding/base64"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
|
||||||
"go/format"
|
"go/format"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
@ -23,7 +23,7 @@ var tpl = template.Must(template.New("assets").Parse(`package auto
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"encoding/hex"
|
"encoding/base64"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ func init() {
|
|||||||
var bs []byte
|
var bs []byte
|
||||||
var gr *gzip.Reader
|
var gr *gzip.Reader
|
||||||
{{range $asset := .assets}}
|
{{range $asset := .assets}}
|
||||||
bs, _ = hex.DecodeString("{{$asset.HexData}}")
|
bs, _ = base64.StdEncoding.DecodeString("{{$asset.Data}}")
|
||||||
gr, _ = gzip.NewReader(bytes.NewBuffer(bs))
|
gr, _ = gzip.NewReader(bytes.NewBuffer(bs))
|
||||||
bs, _ = ioutil.ReadAll(gr)
|
bs, _ = ioutil.ReadAll(gr)
|
||||||
Assets["{{$asset.Name}}"] = bs
|
Assets["{{$asset.Name}}"] = bs
|
||||||
@ -43,7 +43,7 @@ func init() {
|
|||||||
|
|
||||||
type asset struct {
|
type asset struct {
|
||||||
Name string
|
Name string
|
||||||
HexData string
|
Data string
|
||||||
}
|
}
|
||||||
|
|
||||||
var assets []asset
|
var assets []asset
|
||||||
@ -70,7 +70,7 @@ func walkerFor(basePath string) filepath.WalkFunc {
|
|||||||
name, _ = filepath.Rel(basePath, name)
|
name, _ = filepath.Rel(basePath, name)
|
||||||
assets = append(assets, asset{
|
assets = append(assets, asset{
|
||||||
Name: filepath.ToSlash(name),
|
Name: filepath.ToSlash(name),
|
||||||
HexData: fmt.Sprintf("%x", buf.Bytes()),
|
Data: base64.StdEncoding.EncodeToString(buf.Bytes()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user