8000 Compress the languages data by apocelipes · Pull Request #468 · boyter/scc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Compress the languages data #468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion processor/constants.go

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package processor

import (
"bytes"
"compress/gzip"
"encoding/base64"
"fmt"
"os"
Expand Down Expand Up @@ -504,13 +506,17 @@ func loadDatabase() map[string]Language {
var database map[string]Language
startTime := makeTimestampMilli()

data, err := base64.StdEncoding.DecodeString(languages)
gzData, err := base64.StdEncoding.DecodeString(languages)
if err != nil {
panic(fmt.Sprintf("failed to base64 decode languages: %v", err))
}
dataReader, err := gzip.NewReader(bytes.NewReader(gzData))
if err != nil {
panic(fmt.Sprintf("failed to create gzip reader: %v", err))
}

var json = jsoniter.ConfigCompatibleWithStandardLibrary
if err := json.Unmarshal(data, &database); err != nil {
if err := json.NewDecoder(dataReader).Decode(&database); err != nil {
panic(fmt.Sprintf("languages json invalid: %v", err))
}

Expand Down
5 changes: 4 additions & 1 deletion scripts/include.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package main

import (
"compress/gzip"
"encoding/base64"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -50,9 +51,11 @@ func generateConstants() error {
out.Write([]byte(strings.TrimSuffix(f.Name(), ".json") + " = `"))

enc := base64.NewEncoder(base64.StdEncoding, out)
if _, err := io.Copy(enc, f); err != nil {
gz, _ := gzip.NewWriterLevel(enc, gzip.BestSpeed)
if _, err := io.Copy(gz, f); err != nil {
return fmt.Errorf("failed to encode file '%s': %v", f.Name(), err)
}
gz.Close()
enc.Close()

out.Write([]byte("`\n"))
Expand Down
Loading
0