Figured out it was the filters for XZ that was causing problems

Added lzma and xz decompression.
Renamed Zlib to Gzip
This commit is contained in:
Caleb Gardner
2020-12-04 05:36:58 -06:00
parent a894e2efb9
commit 89b0a41ab9
6 changed files with 101 additions and 15 deletions
+40
View File
@@ -0,0 +1,40 @@
package compression
import (
"bytes"
"compress/zlib"
"io"
)
//Gzip is a decompressor for gzip type compression. Uses zlib for compression and decompression
type Gzip struct{}
//Decompress reads the entirety of the given reader and returns it uncompressed as a byte slice.
func (g *Gzip) Decompress(r io.Reader) ([]byte, error) {
rdr, err := zlib.NewReader(r)
if err != nil {
return nil, err
}
var data bytes.Buffer
_, err = io.Copy(&data, rdr)
if err != nil {
return nil, err
}
return data.Bytes(), nil
}
//Compress compresses the given data (as a byte array) and returns the compressed data.
func (g *Gzip) Compress(data []byte) ([]byte, error) {
var buf bytes.Buffer
wrt := zlib.NewWriter(&buf)
defer wrt.Close()
_, err := wrt.Write(data)
if err != nil {
return nil, err
}
err = wrt.Flush()
if err != nil {
return nil, err
}
return buf.Bytes(), nil
}