Function Reference


_WinAPI_CompressBuffer

Compresses a buffer with specified compression format and engine type

#include <WinAPISys.au3>
_WinAPI_CompressBuffer ( $pUncompressedBuffer, $iUncompressedSize, $pCompressedBuffer, $iCompressedSize [, $iFormatAndEngine = 0x0002] )

Parameters

$pUncompressedBuffer A pointer to a caller-allocated buffer that contains the data to be compressed.
$iUncompressedSize The size of the uncompressed buffer, in bytes.
$pCompressedBuffer A pointer to a caller-allocated buffer that receives the compressed data.
$iCompressedSize The size of the compressed buffer, in bytes.
$iFormatAndEngine [optional] A bitmask that specifies the compression format and engine type.
This parameter must be set to a valid bitwise OR combination of one format type and one engine type.
    $COMPRESSION_FORMAT_LZNT1 (Default)
    $COMPRESSION_FORMAT_XPRESS
    $COMPRESSION_FORMAT_XPRESS_HUFF

    $COMPRESSION_ENGINE_STANDARD (Default)
    $COMPRESSION_ENGINE_MAXIMUM

Return Value

Success: The size of the compressed data stored in compressed buffer, in bytes.
Failure: 0 and sets the @error flag to non-zero, @extended flag may contain the NTSTATUS error code.

Remarks

The _WinAPI_CompressBuffer() function takes as input an uncompressed buffer and produces its compressed equivalent provided that the compressed data fits within the specified destination buffer.

To decompress a compressed buffer, use the _WinAPI_DecompressBuffer() function.

Related

_WinAPI_DecompressBuffer

See Also

Search RtlCompressBuffer in MSDN Library.

Example

#include <APISysConstants.au3>
#include <WinAPISys.au3>

; Create compressed and uncompressed buffers
Local $a_pBuffer[2]
For $i = 0 To 1
    $a_pBuffer[$i] = _WinAPI_CreateBuffer(1024)
Next

; Compress binary data
Local $dData = Binary('0x00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF')
Local $iSize = BinaryLen($dData)
DllStructSetData(DllStructCreate('byte[' & $iSize & ']', $a_pBuffer[0]), 1, $dData)
$iSize = _WinAPI_CompressBuffer($a_pBuffer[0], $iSize, $a_pBuffer[1], 1024, BitOR($COMPRESSION_FORMAT_LZNT1, $COMPRESSION_ENGINE_MAXIMUM))
If Not @error Then
    ConsoleWrite('Compressed:   ' & DllStructGetData(DllStructCreate('byte[' & $iSize & ']', $a_pBuffer[1]), 1) & @CRLF)
EndIf

; Decompress data
$iSize = _WinAPI_DecompressBuffer($a_pBuffer[0], 1024, $a_pBuffer[1], $iSize)
If Not @error Then
    ConsoleWrite('Uncompressed: ' & DllStructGetData(DllStructCreate('byte[' & $iSize & ']', $a_pBuffer[0]), 1) & @CRLF)
EndIf

; Free memory
For $i = 0 To 1
    _WinAPI_FreeMemory($a_pBuffer[$i])
Next