diff --git a/rres/cmd/rrem/main.go b/rres/cmd/rrem/main.go index 3e356e8..7436918 100644 --- a/rres/cmd/rrem/main.go +++ b/rres/cmd/rrem/main.go @@ -39,7 +39,7 @@ func init() { func main() { 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") key := flag.String("key", "", "Encryption key") header := flag.Bool("header", false, "Generate C header (.h file)") @@ -286,7 +286,7 @@ func validComp(compType int) bool { return true case rres.CompLZ4, rres.CompLZMA2: return true - case rres.CompBZIP2: + case rres.CompBZIP2, rres.CompSnappy: return true } return false diff --git a/rres/rlib/rlib.go b/rres/rlib/rlib.go index 5b2a3b6..b64f7f4 100644 --- a/rres/rlib/rlib.go +++ b/rres/rlib/rlib.go @@ -15,6 +15,7 @@ import ( "golang.org/x/crypto/xtea" "github.com/dsnet/compress/bzip2" + "github.com/golang/snappy" "github.com/klauspost/compress/flate" "github.com/pierrec/lz4" xor "github.com/rootlch/encrypt" @@ -171,6 +172,19 @@ func Compress(data []byte, compType int) ([]byte, error) { 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 default: return data, nil @@ -225,6 +239,15 @@ func Decompress(data []byte, compType int) ([]byte, error) { 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 default: return data, nil diff --git a/rres/rres.go b/rres/rres.go index 1a13d67..f3dee7b 100644 --- a/rres/rres.go +++ b/rres/rres.go @@ -82,6 +82,8 @@ const ( CompLZMA2 // BZIP2 compression CompBZIP2 + // Snappy compression + CompSnappy ) // Encryption types