-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdecompress.go
35 lines (32 loc) · 1.47 KB
/
decompress.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package libdeflate
// DecompressZlib decompresses the given data from in (zlib formatted) to out and returns out
// or an error if something went wrong.
//
// If you pass a buffer to out, the size of this buffer must exactly match the length of the decompressed data.
// If you pass nil to out, this function will allocate a sufficient buffer and return it.
//
// IF YOU WANT TO DECOMPRESS MORE THAN ONCE, PLEASE REFER TO NewDecompressor(),
// as this function creates a new Decompressor (alloc 32KiB) which is then closed at the end of the function.
//
// If error != nil, the data in out is undefined.
func DecompressZlib(in, out []byte) ([]byte, error) {
return Decompress(in, out, ModeZlib)
}
// Decompress decompresses the given data from in to out and returns out or an error if something went wrong.
// Mode m specifies the format (e.g. zlib) of the data within in.
//
// If you pass a buffer to out, the size of this buffer must exactly match the length of the decompressed data.
// If you pass nil to out, this function will allocate a sufficient buffer and return it.
//
// IF YOU WANT TO DECOMPRESS MORE THAN ONCE, PLEASE REFER TO NewDecompressor(),
// as this function creates a new Decompressor (alloc 32KiB) which is then closed at the end of the function.
//
// If error != nil, the data in out is undefined.
func Decompress(in, out []byte, m Mode) ([]byte, error) {
dc, err := NewDecompressor()
if err != nil {
return out, err
}
defer dc.Close()
return dc.Decompress(in, out, m)
}