Exemple #1
0
func Decompress(in, out []byte) error {
	n := C.LZ4_uncompress((*C.char)(unsafe.Pointer(&in[0])), (*C.char)(unsafe.Pointer(&out[0])), C.int(len(out)))
	if n < 0 {
		return fmt.Errorf("Decompressiong error. Got %d", n)
	}
	return nil
}
Exemple #2
0
// Uncompress with a known output size. len(out) should be equal to
// the length of the uncompressed outout.
func Uncompress(in []byte, out []byte) (err error) {
	read := int(C.LZ4_uncompress(p(in), p(out), clen(out)))

	if read != len(in) {
		err = fmt.Errorf("Uncompress read %d bytes should have read %d",
			read, len(in))
	}
	return
}
Exemple #3
0
// Uncompress with an known output size. `len(*output)` should be equal to the
// length of the uncompressed output.
func Uncompress(input []byte, output *[]byte) error {
	ip, op := charp(&input), charp(output)

	resultlen := int(C.LZ4_uncompress(ip, op, C.int(len(*output))))

	if resultlen < len(input) {
		return fmt.Errorf("Decompression didn't read all the input "+
			" Expected %d bytes, read %d", len(input), resultlen)
	}
	return nil
}
Exemple #4
0
/*
osize  : is the output size, therefore the original size
return : the number of bytes read in the source buffer

If the source stream is malformed, the function will stop decoding and return a negative result, indicating the byte position of the faulty instruction
This function never writes beyond dest + osize, and is therefore protected against malicious data packets

note : destination buffer must be already allocated.
its size must be a minimum of 'osize' bytes.
*/
func Decompress(source, dest []byte, osize int) int {
	return int(C.LZ4_uncompress(cast(source), cast(dest), C.int(osize)))
}