Exemple #1
0
// Decompress decompresses `input` and puts the content in `output`.
// len(output) should have enough space for the uncompressed data.
// Returns the number of bytes in the `output` slice.
func Decompress(input, output []byte) (outSize int, err error) {
	var errCode C.int
	outSize = int(C.lzf_decompress(p(input), clen(input), p(output), clen(output), &errCode))
	if outSize > 0 {
		return
	}
	switch errCode {
	case C.E2BIG:
		err = ErrInsufficientBuffer
	case C.EINVAL:
		err = ErrDataCorruption
	default:
		err = ErrUnknown
	}
	return
}
//lzf解压缩算法,调用c的函数
func Lzf_dcompress(in_data []byte, length uint64) []byte {
	out_data := make([]byte, length)
	C.lzf_decompress(unsafe.Pointer(&in_data[0]), C.uint(len(in_data)), unsafe.Pointer(&out_data[0]), C.uint(length))
	return out_data
}