/
compressing.go
35 lines (29 loc) · 1.05 KB
/
compressing.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 native
/*
#include "libdeflate.h"
typedef struct libdeflate_compressor comp;
*/
import "C"
import "unsafe"
type compress func(c *C.comp, inAddr, outAddr *byte, inSize, outSize int) int
// CompressZlib interfaces with c libdeflate for zlib compression
func CompressZlib(c *C.comp, inAddr, outAddr *byte, inSize, outSize int) int {
return int(C.libdeflate_zlib_compress(c,
unsafe.Pointer(inAddr), intToInt64(inSize),
unsafe.Pointer(outAddr), intToInt64(outSize),
))
}
// CompressDEFLATE interfaces with c libdeflate for DEFLATE compression
func CompressDEFLATE(c *C.comp, inAddr, outAddr *byte, inSize, outSize int) int {
return int(C.libdeflate_deflate_compress(c,
unsafe.Pointer(inAddr), intToInt64(inSize),
unsafe.Pointer(outAddr), intToInt64(outSize),
))
}
// CompressGzip interfaces with c libdeflate for gzip compression
func CompressGzip(c *C.comp, inAddr, outAddr *byte, inSize, outSize int) int {
return int(C.libdeflate_gzip_compress(c,
unsafe.Pointer(inAddr), intToInt64(inSize),
unsafe.Pointer(outAddr), intToInt64(outSize),
))
}