Create a ZIP file from a Clarion Application

Is there a way to create zip files from a clarion application using the win32 API or is there a utility. we have a document manager and need to export MS Office documents and PDF in batches to Zip files.

Many Thanks.

If there are no outdated DLL libraries, then you can do this:

CreateZIPFile        PROCEDURE  (Source_,ZipFile_,NoMess_) 
Loc:Object           CSTRING(65)
Loc:RetValue         BYTE(False)
  CODE
  If json::SaveFile(ZipFile_,'<80><75><5><6>' & All(Chr(0),18))  ! Create empty ZIP file

     Loc:Object              = Create(0,Create:Ole)
     Loc:Object{Prop:Create} = 'Shell.Application'
     If ~NoMess_ then Loc:Object{Prop:ReportException} = True.   ! Message 

     Loc:Object{'NameSpace("' & Clip(ZipFile_) & '").CopyHere("' & Clip(Source_) & '",20)'}

     Loop until Loc:Object{'NameSpace("' & Clip(ZipFile_) & '").Items().Count'} = 1
       Loop 100 times
         Yield
       end
     end

     If Exists(ZipFile_) then Loc:RetValue = True.
     Loc:Object{Prop:Deactivate}
  end
  Return Loc:RetValue
1 Like

thanks for that suggestion.

we have script generating classes might try those insteadā€¦

or something like this , generate a file and run something like thisā€¦

Thereā€™s also a discussion at this topic

That includes a link to a source class for using the zlib dll

Hereā€™s an update to my scenario:

  • I had to abandon using LSZip because it would consistently GPF when zipping large amounts of data. With my app, the total file size can easily be 5-10 GB. I suspect that the issue is the age of LSZip and that the version of the zip spec that it uses was limited. (My LSZip was from 2008.)

  • With @John_Hickeyā€™s help, I implemented the ClarionZipClass (linked to above). It worked with the file sizes, but while 7Zip would compress 10 GB of photos in about 30 seconds, the class was taking about 2.5 hours (!!).

  • So I switched to using the 7Zip CLI, which was simple. e.g. run("7z a archivename.zip filemask.ext"). That worked well, could easily handle the file sizes, and was very fast (e.g. 10 GB of photos took about 30 seconds to zip up), but I wanted to show a progress bar so I started looking at OddJobs.

  • In the meantime, John figured out what was causing the ClarionZipClass to run so slowly and also added a progress bar to the class. What was taking 2.5 hours now takes less than 2 minutes. Itā€™s slower than 7Zip, but the wait for my usage is trivial so thatā€™s what Iā€™m using now.

I think John was going to do a ClarionLive about the code. Hopefully he shares his updated code.

Thank you very much for the great suggestions and examples it is much appreciated as the document manager desperately needs a solution for packaging listed office documents and Pdfā€™sā€¦

Cheers!!!

Where is the class please?

note that the old zip format used 32 bit pointers (ULONG) so had a maximum file size of 4GB (less one byte if you want to be pedantic). so (2^32 - 1). Hence ZIP64 format was developed that uses 64bit ints for pointers and so can address (2^64 - 1) bytes which is 18,446,744,073,709,551,615 bytes.

(I ran out of fingers calculating that :grinning:)

I am tempted to say that is bigger than you will ever need but that smacks of Bill Gates and 640k.

Having a quick look at that CZipClass.CreateZipFile you will see it is using a small 10 thousand byte buffer so you might want to make that larger to avoid so many round trips. Another thought is that StringTheory has Gzip functionality so you could perhaps use that for the compression part of each individual file - of course that assumes you have enough memory to read a file into memory plus extra for the compressed copy so not suitable for enormous multi-GB files.

Maybe using 7Zip is the easiest route.

1 Like

post by Marcelo_Sanseau

1 Like

googling suggests the following (I have not tested):

You can use -bsp1 switch to view the progress

'C:\Program Files\7-Zip\7z.exe'  a  -bsp1

another post mentioned:

Look in your Program Files folder where 7zip is installed. In there, you will find an executable called 7zG.exe. It is the same thing as 7z.exe except it displays a GUI progressbar.

note that the old zip formatā€¦ had a maximum file size of 4GB

Yep, that I assume due to the age of LSZip that it only supports the old format, which is not sufficient for my usage.

Having a quick look at that CZipClass.CreateZipFile you will see it is using a small 10 thousand byte buffer so you might want to make that larger to avoid so many round trips.

Yep, Iā€™ve already done that.

Maybe using 7Zip is the easiest route.

Calling 7Zip through the CLI was easy enough but ClarionZipClass is working well now.

7Zip is fast and efficient and has piles of options, but I prefer using ClarionZipClass because I can control the window and progress bar to match the rest of my app.

Is this ā€œClarionZipClassā€ on Github?

downloaded the drop box .

IF zipFH > 0 THEN
    LOOP i# = 1 TO Records(q1)
      Get(q1, i#)
      INCLUDE('CheckERR.equ')

this appears to be missing? CheckERR.equ

many thanksā€¦

again, any question just ask.

1 Like

this appears to be missing from the zip

ā€œINCLUDE(ā€˜CheckERR.equā€™)ā€

anything important in this or can it be ignoredā€¦

many thanks

it is only a checking for error. You can omit the include.
Sorry for that, the first time I uploaded the class with an example and all the files needed.
This time I uploaded the code in a hurry and I forget to check.

many thanks

will give it a test this week when we get a chanceā€¦ summer here in the south pacific and we are busy with holidaysā€¦

its compiled as first step and in a manager classā€¦

see how we go ā€¦ very interesting ā€¦

cheers