Example #1
0
File: lzo.go Project: presbrey/lzo
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
}
Example #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
}