Added zlib compression for absolutely zero reason

This commit is contained in:
Caleb Gardner
2020-11-28 11:05:38 -06:00
parent e20213c3f7
commit faf9153323
2 changed files with 17 additions and 1 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ import "io"
//Compressor is a squashfs decompressor interface. Allows for easy compression.
type Compressor interface {
Compress(io.Reader) ([]byte, error)
Compress([]byte) ([]byte, error)
}
//Decompressor is a squashfs decompressor interface. Allows for easy decompression no matter the type of compression.
+16
View File
@@ -22,3 +22,19 @@ func (z *Zlib) Decompress(r io.Reader) ([]byte, error) {
}
return data.Bytes(), nil
}
//Compress compresses the given data (as a byte array) and returns the compressed data.
func (z *Zlib) 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
}