Archived Forum Post

Index of archived forum posts

Question:

[CkZip] Copy() function has different result between 9.4.0 and 9.5.0.47?

Apr 09 '15 at 10:53

I am doing upgrade testing on CkZip, the results are different between 9.4.0 and 9.5.0.47.
Could you please check it for me? I need to zip/unzip byteDate only in memory without zip file output.
I expect copy() provides compressed data, which success in 9.4.0, but failed in 9.5.0.x.
The function implements as following,

bool ZipByte(IN CkByteData& dbRawData, OUT CkByteData& dbCompres) {

  CkZip zip;

  if ( !zip.UnlockComponent(unlockKey) )
         return false;
  if ( !zip.NewZip(unusedFilename) )
         return false;

  CkZipEntry* entry = zip.AppendData(unusedFilename, dbRawData);
  if ( entry == NULL ) {
         zip.CloseZip();
         return false;
  }

  if ( !entry->Copy(dbCompres) ) /*** failed in new version:9.5.0.x. ***/  
  {
         delete entry; entry = NULL;      
         zip.CloseZip();
         return false;
  }

  delete entry; entry = NULL;      
  zip.CloseZip();

  std::cout << dbCompres.getEncoded("hex") << std::endl;
  return true;

}


ChilkatLog:
Copy:

DllDate: Oct  1 2014
ChilkatVersion: 9.5.0.44
UnlockPrefix: ----------
Username: xxxxxxxxxx:uuuuuuuu
Architecture: Little Endian; 32-bit
Language: Visual C++ 8.0 (32-bit)
VerboseLogging: 1
Must be an entry within an opened zip archive.
Failed.

--Copy
--ChilkatLog

--
Stanley


Accepted Answer

Thanks. The old version would try to compress the data if the entry was not already a "mapped entry". This was very problematic for many reasons, and that functionality was removed for a simpler implementation that is more explicitly driven by the application.

I updated the reference documentation for the ZipEntry object. (See http://www.chilkatsoft.com/refdoc/vcCkZipEntryRef.html ) See the information for the EntryType property, as well as the Copy method.

In summary, an entry can be one of the following types:

When the zip is written by calling WriteZip or WriteToMemory, all of the zip entries are transformed into mapped entries. They become entries that contain the compressed data within the .zip that was just created. (The WriteZip method call effectively writes the zip and then opens it, replacing all of the existing entries with mapped entries.)

A better solution is to use CkCompression instead of CkZip if you only want to compress data. You would use the "deflate" compression algorithm. The CkCompression object has been part of the "Zip license" for a long time now, so you may use your Zip unlock code with CkCompression in the newer version.

I'll post a CkCompression example shortly that can be used to replace your code above..


Answer

Here is the example using CkCompression:

    CkCompression compress;

CkByteData dbIn;
bool success = dbIn.loadFile("qa_data/hamlet.xml");
if (!success) return false;

compress.put_Algorithm("deflate");
compress.put_EncodingMode("hex");

std::cout &lt;&lt; compress.compressBytesENC(dbIn) &lt;&lt; std::endl;