Skip to content

Commit 611abf7

Browse files
author
Alex Levinson
committed
replaced flate with gzip for more reliable compression
1 parent 0ac5ad8 commit 611abf7

File tree

7 files changed

+33
-20
lines changed

7 files changed

+33
-20
lines changed

compiler/bindata.go

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/embedder.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package compiler
22

33
import (
44
"bytes"
5-
"compress/flate"
5+
"compress/gzip"
66
"fmt"
77
"io/ioutil"
88
"math/rand"
@@ -54,24 +54,22 @@ func (e *EmbeddedFile) Data() string {
5454
}
5555

5656
func (e *EmbeddedFile) GenerateEmbedData() {
57-
for idx, b := range e.Compressed {
58-
if idx%12 == 0 {
59-
e.EmbedData.WriteString("\n ")
60-
}
61-
e.EmbedData.WriteString(fmt.Sprintf("0x%02x, ", b))
57+
for _, b := range e.Compressed {
58+
e.EmbedData.WriteString(fmt.Sprintf("\\x%02x", b))
6259
}
6360
}
6461

6562
func BytesToCompressed(b []byte) []byte {
6663
buf := new(bytes.Buffer)
67-
w, _ := flate.NewWriter(buf, flate.BestCompression)
64+
w, _ := gzip.NewWriterLevel(buf, gzip.BestCompression)
6865
w.Write(b)
6966
w.Close()
7067
return buf.Bytes()
7168
}
7269

7370
func CompressedToBytes(b []byte) []byte {
74-
buf, _ := ioutil.ReadAll(flate.NewReader(bytes.NewBuffer(b)))
71+
r, _ := gzip.NewReader(bytes.NewBuffer(b))
72+
buf, _ := ioutil.ReadAll(r)
7573
return buf
7674
}
7775

gscript.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
package gscript
22

33
// Version defines the version of gscript
4-
const Version = "v0.0.15"
4+
const Version = "v0.0.16"

spec/large_file.gs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//import:/Users/flint/Downloads/e200.tar
2+
3+
function BeforeDeploy() {
4+
LogInfo("BeforeDeploy()");
5+
return true;
6+
}
7+
8+
function Deploy() {
9+
WriteFile("/Users/flint/Downloads/e301.tar", Asset("e200.tar"), "0644");
10+
return true;
11+
}
12+
13+
function AfterDeploy() {
14+
LogInfo("AfterDeploy()");
15+
return true;
16+
}

spec/test.gs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//import:/Users/flint/Downloads/tater.jpg
1+
// //import:/Users/flint/Downloads/tater.jpg
22

33
function BeforeDeploy() {
44
LogInfo("BeforeDeploy()");

templates/embed.go.tmpl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
{{- range $_, $vm := (index $.SortedVMs $pri) }}
33
{{- range $_, $embed := $vm.Embeds }}
44
func {{ $embed.NameHash }}() []byte {
5-
s, _ := ioutil.ReadAll(flate.NewReader(bytes.NewBuffer([]byte{
6-
{{- $embed.Data }}
7-
})))
5+
r, _ := gzip.NewReader(strings.NewReader("{{ $embed.Data }}"))
6+
s, _ := ioutil.ReadAll(r)
87
return s
98
}
109
{{ end -}}

templates/entrypoint.go.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package main
22

33
import (
4-
"bytes"
5-
"compress/flate"
4+
"compress/gzip"
65
"io/ioutil"
76
"sync"
87
"strconv"
8+
"strings"
99

1010
"github.com/gen0cide/gscript/engine"
1111
{{- if eq $.EnableLogging true }}

0 commit comments

Comments
 (0)