Beispiel #1
0
// Compress compresses `input` and puts the content in `output`.
// len(output) should have enough space for the compressed data.
// Returns the number of bytes in the `output` slice.
func Compress(input, output []byte) (outSize int, err error) {
	outSize = int(C.lzf_compress(p(input), clen(input), p(output), clen(output)))
	if outSize == 0 {
		err = ErrInsufficientBuffer
	}
	return
}
Beispiel #2
0
//lzf压缩算法,调用c的函数
func Lzf_compress(str string) []byte {

	cstr := C.CString(str)
	out_data := make([]byte, len(str)*2)

	result := C.lzf_compress(unsafe.Pointer(cstr), C.uint(len(str)), unsafe.Pointer(&out_data[0]), C.uint(len(str)*2))
	C.free(unsafe.Pointer(cstr))

	return out_data[:result]
}