Home Forums ActiveX components Xceed Zip for ActiveX & x64 How to find compressed size when compressing to memory?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #42500 |

    Greetings,

    I am compressing/uncompressing  memory to memory using the Xceed API DLL functions:

    // Compress method
    XCD_IMPORT  int   XCD_WINAPI  XcCompress( HXCEEDCMP hComp, const BYTE* pcSource, DWORD dwSourceSize, BYTE** ppcCompressed, DWORD* pdwCompressedSize, BOOL bEndOfData );

    // Uncompress method
    XCD_IMPORT  int   XCD_WINAPI  XcUncompress( HXCEEDCMP hComp, const BYTE* pcSource, DWORD dwSourceSize, BYTE** ppcUncompressed, DWORD* pdwUncompressedSize, BOOL bEndOfData );

    To uncompress I need to pass the dwSourceSize, eg. the size of the compressed buffer. However,  as this buffer is stored in a byte container larger than the actual compressed data I need a way to figure out the size of the actual compressed data.  There are two methods I can do myself:
    1) Assuming that the compressed data never ends with a zero (0),  I could look for the end of compressed data by looking for the first none-zero by searching the buffer reverse,
     
    2) I can store a 4 byte size value leading the actual compressed data. The buffer must of course be large enough to hold both. Before uncompressing I read the compressed size value. I have tested this method and it works fine. 
     
    A third more elegant method would be to use information already in the compressed buffer: 
    3) I assume the compressed data contains a structure (header) of some sort. Maybe that structure includes the compressed size info, like it apparently does for the checksum?  Is there any documentation for the compressed data when compressing to memory using the above function?
     
     
    Thanks in advance for any helpful info.

    Kind regards
    Viggo 

     

    Imported from legacy forums. Posted by Viggo (had 459 views)

    Xceed Support
    Member
    Post count: 5658

    You will find the description of the header and footer around the compressed data here.

    However, this should not be needed. If you used the Deflated compression method, Uncompress() will detect the end of the compressed data itself even if the source buffer you supply is larger than the compressed data. This works because the Deflated compression format contains internal block markers that allow the engine to detect when decompression needs to end.

    Understand that this approach will only work if the entire compressed data is located in a single compressed buffer. This means that when you call Uncompress(), the endOfData parameter value will be ‘true’.

    Imported from legacy forums. Posted by Jb [Xceed] (had 344 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.