ZIP library UncompressData()



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 11/09/2008 at 21:22, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   R9.5-R11 
    Platform:   Windows  ; Mac  ;  Mac OSX  ; 
    Language(s) :     C++  ;

    ---------
    Okay, a simple question:

    Does UncompressData() understand partial buffers due to file reads for zlib decompression?

    I'm reading a set number of bytes (per round) from a zlib-compressed file and then calling UncompressData(). So far, it always errors out at UncompressData(). I assume that the pDestData argument returns a pointer to a memory buffer that C4D allocated (thus the required GeFree()). ZBUFLEN = 65536L. I'm sorry - it is not possible to expect to be able to allocate a memory buffer to hold possible files (they may be in the hundreds of Megabytes!). Here's the method involved:

    > // Decompress infile into outfile, return outfile \> //\*---------------------------------------------------------------------------\* \> Bool myZLib::DecompressFile(const Filename& inname, const Filename& outname, char\* buf) \> //\*---------------------------------------------------------------------------\* \> { \>      AutoAlloc<BaseFile>     out; \>      AutoAlloc<BaseFile>     in; \>      if (!(in && out))          return FALSE; \> \>      if (!in->Open(inname, GE_READ, FILE_NODIALOG, GE_INTEL)) \>      { \>           GePrint("Error: in->Open"); \>           return FALSE; \>      } \>      if (!out->Open(outname, GE_WRITE, FILE_NODIALOG, GE_INTEL)) \>      { \>           GePrint("Error: out->Open"); \>           return FALSE; \>      } \> #ifdef     OS64 \>      VLONG     len; \> #else \>      LONG     len; \> #endif \>      LONG     olen; \>      char\*     obuf; \>      for (;;) \>      { \>           len = in->ReadBytes(buf, ZBUFLEN); \>           if (len < 0) \>           { \>                GePrint("Error: len < 0"); \>                return FALSE; \>           } \>           if (len == 0)     return TRUE; \>           if (!UncompressData(buf, len, (void\*&)obuf, olen)) \>           { \>                GePrint("Error: UncompressData"); // ALWAYS ERRORS HERE! \>                return FALSE; \>           } \>           if (!out->WriteBytes(obuf, olen)) \>           { \>                GeFree(obuf); \>                GePrint("Error: WriteBytes"); \>                return FALSE; \>           } \>           GeFree(obuf); \>      } \>      if (!out->Close()) \>      { \>           GePrint("Error: out->Close"); \>           return FALSE; \>      } \>      if (!in->Close()) \>      { \>           GePrint("Error: in->Close"); \>           return FALSE; \>      } \>      return TRUE; \> }

    Thanks,



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 11/09/2008 at 23:25, xxxxxxxx wrote:

    Hi!

    You only want to decrompress zip files?



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 11/09/2008 at 23:30, xxxxxxxx wrote:

    zlib compressed files. Zip files 'use' zlib compression but also include other information (such as folder/file structures). These files are simply compressed using zlib compression.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 11/09/2008 at 23:32, xxxxxxxx wrote:

    I used the class "ZipFile" to extract a zip file with its directory structure. You are able to read and write comments, and other stuff too.

    A few lines are enough to extract the whole content of a zip file to a directory. A small code snippet:
    zlib
    See my last post.

    Bye...



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 11/09/2008 at 23:39, xxxxxxxx wrote:

    Supposedly, CompressData() and UncompressData() work with zlib compressed data.

    Remember that there is a difference between this and zip files. I've already tried using the 'zip' library on these files without success - because they aren't zip archives. They are just single files that have been zlib compressed (think RLE encoding).



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 11/09/2008 at 23:46, xxxxxxxx wrote:

    Hi!, ah, ok.. I see.. :)



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 13/09/2008 at 13:32, xxxxxxxx wrote:

    Bumping this up.

    Yes, indeed CompressData() and UncompressData() work if the full buffer is being compressed or decompressed. I converted all the zlib-compressed memory buffer code and these work splendidly.

    It appears that, unlike the zlib stream support provided by gzOpen()/gzRead()/gzClose(), the C4D SDK routines cannot handle segmented buffer decompression - all or nothing. 'All' is not going to be a viable option here.

    Any thoughts here?


Log in to reply