Skip to content

Commit

Permalink
replaced flate with gzip for more reliable compression
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Levinson committed Mar 4, 2018
1 parent 0ac5ad8 commit 611abf7
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 20 deletions.
10 changes: 5 additions & 5 deletions compiler/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions compiler/embedder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package compiler

import (
"bytes"
"compress/flate"
"compress/gzip"
"fmt"
"io/ioutil"
"math/rand"
Expand Down Expand Up @@ -54,24 +54,22 @@ func (e *EmbeddedFile) Data() string {
}

func (e *EmbeddedFile) GenerateEmbedData() {
for idx, b := range e.Compressed {
if idx%12 == 0 {
e.EmbedData.WriteString("\n ")
}
e.EmbedData.WriteString(fmt.Sprintf("0x%02x, ", b))
for _, b := range e.Compressed {
e.EmbedData.WriteString(fmt.Sprintf("\\x%02x", b))
}
}

func BytesToCompressed(b []byte) []byte {
buf := new(bytes.Buffer)
w, _ := flate.NewWriter(buf, flate.BestCompression)
w, _ := gzip.NewWriterLevel(buf, gzip.BestCompression)
w.Write(b)
w.Close()
return buf.Bytes()
}

func CompressedToBytes(b []byte) []byte {
buf, _ := ioutil.ReadAll(flate.NewReader(bytes.NewBuffer(b)))
r, _ := gzip.NewReader(bytes.NewBuffer(b))
buf, _ := ioutil.ReadAll(r)
return buf
}

Expand Down
2 changes: 1 addition & 1 deletion gscript.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gscript

// Version defines the version of gscript
const Version = "v0.0.15"
const Version = "v0.0.16"
16 changes: 16 additions & 0 deletions spec/large_file.gs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//import:/Users/flint/Downloads/e200.tar

function BeforeDeploy() {
LogInfo("BeforeDeploy()");
return true;
}

function Deploy() {
WriteFile("/Users/flint/Downloads/e301.tar", Asset("e200.tar"), "0644");
return true;
}

function AfterDeploy() {
LogInfo("AfterDeploy()");
return true;
}
2 changes: 1 addition & 1 deletion spec/test.gs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//import:/Users/flint/Downloads/tater.jpg
// //import:/Users/flint/Downloads/tater.jpg

function BeforeDeploy() {
LogInfo("BeforeDeploy()");
Expand Down
5 changes: 2 additions & 3 deletions templates/embed.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
{{- range $_, $vm := (index $.SortedVMs $pri) }}
{{- range $_, $embed := $vm.Embeds }}
func {{ $embed.NameHash }}() []byte {
s, _ := ioutil.ReadAll(flate.NewReader(bytes.NewBuffer([]byte{
{{- $embed.Data }}
})))
r, _ := gzip.NewReader(strings.NewReader("{{ $embed.Data }}"))
s, _ := ioutil.ReadAll(r)
return s
}
{{ end -}}
Expand Down
4 changes: 2 additions & 2 deletions templates/entrypoint.go.tmpl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package main

import (
"bytes"
"compress/flate"
"compress/gzip"
"io/ioutil"
"sync"
"strconv"
"strings"

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

0 comments on commit 611abf7

Please sign in to comment.