mirror of
https://github.com/tmedwards/tweego.git
synced 2025-07-05 14:10:27 -04:00
[UPDATE] Add compression to data and template tags
This commit is contained in:
parent
6a91103a6d
commit
f6e633fc0f
1 changed files with 19 additions and 1 deletions
20
storyload.go
20
storyload.go
|
@ -9,6 +9,8 @@ package main
|
||||||
import (
|
import (
|
||||||
// standard packages
|
// standard packages
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"compress/zlib"
|
||||||
|
b64 "encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -389,10 +391,26 @@ func (s *story) loadTagged(tag, filename, encoding string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var str string
|
||||||
|
|
||||||
|
if tag == "data" || tag == "template" {
|
||||||
|
// Add Compression
|
||||||
|
var b bytes.Buffer
|
||||||
|
w := zlib.NewWriter(&b)
|
||||||
|
w.Write(source)
|
||||||
|
w.Close()
|
||||||
|
|
||||||
|
// str = b64.StdEncoding.EncodeToString(source)
|
||||||
|
str = b64.StdEncoding.EncodeToString(b.Bytes())
|
||||||
|
// fmt.Println(filename, len(b.Bytes()), len(str))
|
||||||
|
} else {
|
||||||
|
str = string(source)
|
||||||
|
}
|
||||||
|
|
||||||
s.add(newPassage(
|
s.add(newPassage(
|
||||||
filepath.Base(filename),
|
filepath.Base(filename),
|
||||||
[]string{tag},
|
[]string{tag},
|
||||||
string(source),
|
str,
|
||||||
))
|
))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue