Add snappy compression
This commit is contained in:
parent
4564e18b32
commit
2914dc5cc8
3 changed files with 27 additions and 2 deletions
|
@ -39,7 +39,7 @@ func init() {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
base := flag.String("base", "data", "Resources file basename")
|
base := flag.String("base", "data", "Resources file basename")
|
||||||
comp := flag.Int("comp", rres.CompDeflate, "Compression type, 0=NONE, 1=DEFLATE, 2=LZ4, 5=LZMA2 (XZ), 6=BZIP2")
|
comp := flag.Int("comp", rres.CompDeflate, "Compression type, 0=NONE, 1=DEFLATE, 2=LZ4, 5=LZMA2 (XZ), 6=BZIP2, 7=Snappy")
|
||||||
enc := flag.Int("enc", rres.CryptoNone, "Encryption type, 0=NONE, 1=XOR, 2=AES, 3=3DES, 4=Blowfish, 5=XTEA")
|
enc := flag.Int("enc", rres.CryptoNone, "Encryption type, 0=NONE, 1=XOR, 2=AES, 3=3DES, 4=Blowfish, 5=XTEA")
|
||||||
key := flag.String("key", "", "Encryption key")
|
key := flag.String("key", "", "Encryption key")
|
||||||
header := flag.Bool("header", false, "Generate C header (.h file)")
|
header := flag.Bool("header", false, "Generate C header (.h file)")
|
||||||
|
@ -286,7 +286,7 @@ func validComp(compType int) bool {
|
||||||
return true
|
return true
|
||||||
case rres.CompLZ4, rres.CompLZMA2:
|
case rres.CompLZ4, rres.CompLZMA2:
|
||||||
return true
|
return true
|
||||||
case rres.CompBZIP2:
|
case rres.CompBZIP2, rres.CompSnappy:
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -15,6 +15,7 @@ import (
|
||||||
"golang.org/x/crypto/xtea"
|
"golang.org/x/crypto/xtea"
|
||||||
|
|
||||||
"github.com/dsnet/compress/bzip2"
|
"github.com/dsnet/compress/bzip2"
|
||||||
|
"github.com/golang/snappy"
|
||||||
"github.com/klauspost/compress/flate"
|
"github.com/klauspost/compress/flate"
|
||||||
"github.com/pierrec/lz4"
|
"github.com/pierrec/lz4"
|
||||||
xor "github.com/rootlch/encrypt"
|
xor "github.com/rootlch/encrypt"
|
||||||
|
@ -171,6 +172,19 @@ func Compress(data []byte, compType int) ([]byte, error) {
|
||||||
|
|
||||||
w.Close()
|
w.Close()
|
||||||
|
|
||||||
|
return buf.Bytes(), nil
|
||||||
|
case rres.CompSnappy:
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
|
||||||
|
w := snappy.NewWriter(buf)
|
||||||
|
|
||||||
|
_, err := w.Write(data)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Close()
|
||||||
|
|
||||||
return buf.Bytes(), nil
|
return buf.Bytes(), nil
|
||||||
default:
|
default:
|
||||||
return data, nil
|
return data, nil
|
||||||
|
@ -225,6 +239,15 @@ func Decompress(data []byte, compType int) ([]byte, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return u, nil
|
||||||
|
case rres.CompSnappy:
|
||||||
|
r := snappy.NewReader(bytes.NewReader(data))
|
||||||
|
|
||||||
|
u, err := ioutil.ReadAll(r)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return u, nil
|
return u, nil
|
||||||
default:
|
default:
|
||||||
return data, nil
|
return data, nil
|
||||||
|
|
|
@ -82,6 +82,8 @@ const (
|
||||||
CompLZMA2
|
CompLZMA2
|
||||||
// BZIP2 compression
|
// BZIP2 compression
|
||||||
CompBZIP2
|
CompBZIP2
|
||||||
|
// Snappy compression
|
||||||
|
CompSnappy
|
||||||
)
|
)
|
||||||
|
|
||||||
// Encryption types
|
// Encryption types
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue