Beispiel #1
0
// Uncompress with an unknown output size. The destination buffer should have
// a cap() of sufficient size to hold the output, otherwise an error is returned.
func UncompressUnknownOutputSize(input []byte, output *[]byte) error {
	ip, op := charp(&input), charp(output)

	resultlen := int(C.LZ4_uncompress_unknownOutputSize(
		ip, op, C.int(len(input)), C.int(cap(*output))))

	if resultlen < 0 {
		return fmt.Errorf("decompression failed: resultlen=%d", resultlen)
	}

	*output = (*output)[0:resultlen]
	if len(*output) != resultlen {
		return fmt.Errorf("Failed to resize destination buffer")
	}
	return nil
}
Beispiel #2
0
func DecompressUnknownOutputSize(in, out []byte) int {
	n := C.LZ4_uncompress_unknownOutputSize((*C.char)(unsafe.Pointer(&in[0])), (*C.char)(unsafe.Pointer(&out[0])), C.int(len(in)), C.int(len(out)))
	return (int)(n)
}
Beispiel #3
0
/*
isize  : is the input size, therefore the compressed size
maxOutputSize : is the size of the destination buffer (which must be already allocated)
return : the number of bytes decoded in the destination buffer (necessarily <= maxOutputSize)

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 + maxOutputSize, and is therefore protected against malicious data packets

note   : Destination buffer must be already allocated.
This version is slightly slower than Decompress()
*/
func DecompressUnknownOutputSize(source, dest []byte, isize, maxOutputSize int) int {
	return int(C.LZ4_uncompress_unknownOutputSize(cast(source), cast(dest), C.int(isize), C.int(maxOutputSize)))
}