Пример #1
0
func lzoDecompress(src []byte, dst []byte) (int, error) {
	dstLen := len(dst)
	err := C.lzo1x_decompress((*C.uchar)(unsafe.Pointer(&src[0])), C.lzo_uint(len(src)),
		(*C.uchar)(unsafe.Pointer(&dst[0])), (*C.lzo_uint)(unsafe.Pointer(&dstLen)), nil)
	if err != 0 {
		return 0, errno(err)
	}
	return dstLen, nil
}
Пример #2
0
// Decompress decompresses the byte array b passed in into the byte array o, and returns the size of the valid uncompressed data.
// If o is not large enough to hold the  compressed data, an error is returned.
func (z *Compressor) Decompress(b []byte, o []byte) (uint, error) {

	// both and input param (size of 'o') and output param (decompressed size)
	out_size := uint(len(o))

	err := C.lzo1x_decompress((*C.uchar)(unsafe.Pointer(&b[0])), C.lzo_uint(len(b)),
		(*C.uchar)(unsafe.Pointer(&o[0])), (*C.lzo_uint)(unsafe.Pointer(&out_size)), nil)

	// decompression failed :(
	if err != 0 {
		return out_size, Errno(err)
	}

	return out_size, nil
}
Пример #3
0
func lzoCompressBest(src []byte, dst []byte, dst_size *int) C.int {
	wrkmem := make([]byte, int(C.lzo1x_999_mem_compress()))
	return C.lzo1x_999_compress((*C.uchar)(unsafe.Pointer(&src[0])), C.lzo_uint(len(src)),
		(*C.uchar)(unsafe.Pointer(&dst[0])), (*C.lzo_uint)(unsafe.Pointer(dst_size)),
		unsafe.Pointer(&wrkmem[0]))
}
Пример #4
0
func lzo1x_999_compress(b []byte, out []byte, out_size *int, wrkmem []byte) C.int {
	return C.lzo1x_999_compress((*C.uchar)(unsafe.Pointer(&b[0])), C.lzo_uint(len(b)),
		(*C.uchar)(unsafe.Pointer(&out[0])), (*C.lzo_uint)(unsafe.Pointer(out_size)),
		unsafe.Pointer(&wrkmem[0]))
}