Embed the data files needed for the ssh kitten into the Go binary

This commit is contained in:
Kovid Goyal
2023-02-22 11:09:50 +05:30
parent b4b8943e64
commit a84b688038
5 changed files with 114 additions and 31 deletions

37
tools/cmd/ssh/data.go Normal file
View File

@@ -0,0 +1,37 @@
// License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>
package ssh
import (
"bytes"
_ "embed"
"encoding/binary"
"fmt"
"kitty/tools/utils"
"strconv"
"strings"
)
var _ = fmt.Print
//go:embed data_generated.bin
var embedded_data string
type Container = map[string][]byte
var Data = (&utils.Once[Container]{Run: func() Container {
raw := utils.ReadCompressedEmbeddedData(embedded_data)
num_of_entries := binary.LittleEndian.Uint32(raw)
raw = raw[4:]
ans := make(Container, num_of_entries)
idx := bytes.IndexByte(raw, '\n')
text := utils.UnsafeBytesToString(raw[:idx])
raw = raw[idx+1:]
for _, record := range strings.Split(text, ",") {
parts := strings.Split(record, " ")
offset, _ := strconv.Atoi(parts[1])
size, _ := strconv.Atoi(parts[2])
ans[parts[0]] = raw[offset : offset+size]
}
return ans
}}).Get