EldoS | Feel safer!

Software components for data protection, secure storage and transfer

TElZipwrite and existing zip file

Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.
#36023
Posted: 02/28/2016 07:48:42
by Pascal Coenen (Standard support level)
Joined: 11/17/2010
Posts: 9

Trying to add files to an existing zip file. Using the following code

Code
// Open the existing zip file
ElZipWriter.Open(MyZipFile, False);

// Add and Compress all files I want to add
for i := 0 to AllMyFiles do
begin
  ..
  ElZipWriter.Add(MyDirEntry, MySourceFile);
  ElZipWriter.Compress;
end;

// Close Zip file
ElZipWriter.Close;


What happens, suppose I would add 3 files. The result is the following:

Quote

28/02/2016 13:43:52 ZIP Success C:\Test\In\Third.doc to C:\Test\Out\Out1zip\Zipped.zip;125440
28/02/2016 13:43:52 ZIP Compress Finished C:\Test\In\Third.doc
28/02/2016 13:43:52 ZIP Compress Finished C:\Test\In\Second.doc
28/02/2016 13:43:52 ZIP Compress Finished C:\Test\In\First.doc
28/02/2016 13:43:52 ZIP Success C:\Test\In\Second.doc to C:\Test\Out\Out1zip\Zipped.zip;143872
28/02/2016 13:43:52 ZIP Compress Finished C:\Test\In\Second.doc
28/02/2016 13:43:52 ZIP Compress Finished C:\Test\In\First.doc
28/02/2016 13:43:52 ZIP Success C:\Test\In\First.doc to C:\Test\Out\Out1zip\Zipped.zip;35840
28/02/2016 13:43:52 ZIP Compress Finished C:\Test\In\First.doc


With the first file I get a single compress finished event. With the second file a two compress finished events (first and second file). With the third file I get three compress finished events (first, second and third). Why does it need to (re)compress already compressed files?

Regards,
Pascal
#36045
Posted: 02/29/2016 05:10:43
by Vsevolod Ievgiienko (EldoS Corp.)

Thank you for contacting us.

Your code is not correct as Compress method should be called only once when all files are added to the archive:

Code
// Open the existing zip file
ElZipWriter.Open(MyZipFile, False);

// Add and Compress all files I want to add
for i := 0 to AllMyFiles do
begin
  ..
  ElZipWriter.Add(MyDirEntry, MySourceFile);
end;

ElZipWriter.Compress;

// Close Zip file
ElZipWriter.Close;
#36132
Posted: 03/06/2016 03:28:28
by Pascal Coenen (Standard support level)
Joined: 11/17/2010
Posts: 9

Ok thank you. It was a stupid question of me because all info was already available at https://www.eldos.com/documentation/sbb/documentation/ref_howto_zip_common_compress.html

Ok so I changed my code to and I'm having an issue when using "ElZipWriter.ReplaceMode := armAlways;" or "ElZipWriter.ReplaceMode := armNewer";

Code
  // Important
  ElZipWriter.ReplaceMode := armAlways;
  // Open the existing zip file
  ElZipWriter.Open(MyZipFile, False);
  ElZipWriter.BeginCompression('');
  // Add and Compress all files I want to add
  for i := 0 to AllMyFiles do
  begin
    ..
    ElZipWriter.Add(MyDirEntry, MySourceFile);
    ElZipWriter.UpdateCompression;
  end;
    
    
  // Close Zip file
  ElZipWriter.EndCompression,
  ElZipWriter.Close;


Suppose the existing zip file contains a single file called First.doc

When I run the code above it should replace the First.doc in the exisiting zip file with the new First.doc in the MyDirEntry. But it doesn't. The result is a zip file containing two First.doc files, one with the Attribute set to A and the other First.doc has an empty Attribute. If I run the code one more time, then I get an exception. Can you explain this. I thought that it should just always replace the First.doc in the existing zip file with the new First.doc that I want to add.

Regards,
Pascal
#36134
Posted: 03/06/2016 04:38:06
by Eugene Mayevski (EldoS Corp.)

Could you please specify what version of Secureblackbox you are using now?


Sincerely yours
Eugene Mayevski
#36136
Posted: 03/06/2016 07:46:27
by Pascal Coenen (Standard support level)
Joined: 11/17/2010
Posts: 9

Hi Eugene,

SecureBlackbox - version 14.0.286 - Released December 12, 2015

Regards,
Pascal
#36138
Posted: 03/06/2016 11:55:50
by Eugene Mayevski (EldoS Corp.)

Thank you for the details. Let's continue in the helpdesk ticket, which I have created and which will be handled by our developers tomorrow.


Sincerely yours
Eugene Mayevski
Also by EldoS: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.

Reply

Statistics

Topic viewed 2001 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!