Skip to content

Commit

Permalink
Compress binary snapshots.
Browse files Browse the repository at this point in the history
  • Loading branch information
corywalker committed Nov 10, 2018
1 parent 8c8b931 commit f3f9078
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,6 +3,7 @@ calc.go
y.output
test_rubi
expreduce/rubi_snapshot.expred
.DS_Store

.idea/expreduce.iml

Expand Down
9 changes: 7 additions & 2 deletions expreduce/builtin_system.go
Expand Up @@ -2,6 +2,7 @@ package expreduce

import (
"bytes"
"compress/zlib"
"encoding/gob"
"flag"
"fmt"
Expand Down Expand Up @@ -655,11 +656,13 @@ func getSystemDefinitions() (defs []Definition) {
// TODO: Read as a stream and not a byte string.
r := bytes.NewReader(fileData[len(exprFileHeader):])
atoms.RegisterGobAtoms()
decoder := gob.NewDecoder(r)
compressedReader, _ := zlib.NewReader(r)
decoder := gob.NewDecoder(compressedReader)
definitions := []encodedDef{}
if err := decoder.Decode(&definitions); err != nil {
panic(err)
}
compressedReader.Close()

for _, def := range definitions {
es.SetDefined(def.Name, def.Def)
Expand Down Expand Up @@ -713,10 +716,12 @@ func getSystemDefinitions() (defs []Definition) {
if err == nil {
// Write the header.
file.Write(exprFileHeader)
encoder := gob.NewEncoder(file)
compressedWriter := zlib.NewWriter(file)
encoder := gob.NewEncoder(compressedWriter)
if err := encoder.Encode(definitions); err != nil {
panic(err)
}
compressedWriter.Close()
}
file.Close()

Expand Down
2 changes: 1 addition & 1 deletion expreduce/resources/rubi.m
Expand Up @@ -22,7 +22,7 @@
};

LoadRubiSnapshot[snapshotLoc_] := (
Get[snapshotLoc_];
Get[snapshotLoc];
$ContextPath = Prepend[$ContextPath, "Rubi`"];
);
SaveRubiSnapshot[snapshotLoc_] := Save[snapshotLoc, "Rubi`*"];

0 comments on commit f3f9078

Please sign in to comment.