PureZIP library : ZIP / UNZIP files

All PureFORM, JaPBe, Libs and useful code maintained by gnozal

Moderator: gnozal

Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

@gnozal, is it safe to use the current lib with PB4.20 final?
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Update (PB4.20 version only)

Changes :
- recompiled with PB4.20 final and latest tailbite
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Inf0Byt3 wrote:@gnozal, is it safe to use the current lib with PB4.20 final?
If it wasn't it should be now :wink:
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

Thank you very much for the quick update :D.

8)
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
kinglestat
Enthusiast
Enthusiast
Posts: 746
Joined: Fri Jul 14, 2006 8:53 pm
Location: Malta
Contact:

Post by kinglestat »

my bad

I was not setting the variable for size properly
I may not help with your coding
Just ask about mental issues!

http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Just testing PureZIP for the first time, and I noticed that sometimes it reports
the number of files +1 by mistake, if the archive has a folder in it. For example,
if the original zip structure is:

Code: Select all

MyFolder\ZippedFile1.txt
MyFolder\ZippedFile2.txt
Then PureZIP_GetFileCount() says there are 3 files instead of 2.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

PB wrote:Just testing PureZIP for the first time, and I noticed that sometimes it reports the number of files +1 by mistake, if the archive has a folder in it
This function is a simple wrapper to the ZLIB unzGetGlobalInfo() function. It returns the unz_global_info\number_entry value, wich is the "total number of entries in the central directory of the zip archive".
A directory is only a file with a 'Directory' attribute, but I guess I should have named this function 'PureZIP_GetEntriesCount()'.
For a more accurate result, you have to parse all the ZIP file entries.

Code: Select all

myFileinfo.PureZIP_FileInfo
If PureZIP_Archive_Read(MyZIP.s)
  ReturnValue.l = PureZIP_Archive_FindFirst() = #UNZ_OK
  While ReturnValue = #UNZ_OK 
    Debug PureZIP_Archive_FileInfo(@myFileinfo)
    Debug "Filename: " + myFileinfo\FileName
    Debug "Compressed Size: " + Str(myFileinfo\CompressedSize)
    Debug "Uncompressed Size: "+ Str(myFileinfo\unCompressedSize)
    ; etc ... see PureZIP_FileInfo structure members
    ReturnValue = PureZIP_Archive_FindNext()
  Wend
  PureZIP_Archive_Close()
EndIf
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Thanks. I knew it was something to do with the folder in the archive, because
when I tested it on zips without a folder, it returned the expected result. :)
fizban
User
User
Posts: 31
Joined: Thu Sep 20, 2007 7:36 am
Location: Spain

gzip problems with static library

Post by fizban »

Not directly related to purezip, but to the static library posted by gnozal on this post.

Most of the gzip files I have tried work OK, but there are some that cause a memory problem. In the following example, I have base64 encoded a couple of files in the data section so that they are easier to post here. The first one works. The second doesn't, with an invalid memory access. Any ideas why?. As another option, I have tried to use the uncompress function in order not to have to create a temporary file, but I have not been able to decompress a gzip file using that function.

UPDATE: Using the dynamic library both files get uncompressed correctly, so the issue seems to be related to the static library.

Code: Select all

EnableExplicit

Import "ZlibStatic.lib" 
  gzclose(a.l) As "_gzclose@4" 
  gzopen(a.l,b.l) As "_gzopen@8" 
  gzread(a.l,b.l,c.l) As "_gzread@12" 
EndImport 


Procedure.l gzUncompress(*in,inlen.l)
  Define tempPath.s,lg.l,filehdl.l,length.l,*out,tempFILENAME.s,zerr.l
  
  ;Create a temporary file to be able to use gzopen
  tempPath=Space(#MAX_PATH) 
  lg=GetTempPath_(#MAX_PATH,tempPATH) 
  tempPath=Left(tempPath,lg) 
  tempFILENAME.s=Space(#MAX_PATH) 
  lg=GetTempFileName_(@tempPath,"TMP", 0, @tempFilename) 
  OpenFile(1,tempFilename)
  WriteData(1,*in,inlen)
  CloseFile(1)
  
  ;The real decoding starts here
  fileHdl = gzopen(@tempFilename, @"rb")
  length=PeekL(*in+inlen-4)
  *out=AllocateMemory(length)
  gzread(fileHdl,*out,length) 
  zerr=gzclose(fileHdl) 
  DeleteFile(tempfilename)
  FreeMemory(*in)
  ProcedureReturn *out
EndProcedure


Procedure GetContent() ;concatenates a series of strings of a data section 
                        ;and base64 decodes it
  Define temp.s, cont.s,*out,lg.l
  
  Repeat
    Read temp
    cont=cont+temp
  Until temp=""
  lg=Len(cont)
  *out=AllocateMemory(lg)
  lg=Base64Decoder(@cont,lg,*out,lg)
  *out=ReAllocateMemory(*out,lg)
  ProcedureReturn *out
EndProcedure

Define lg.l,*content,*in


Restore gzfile1
*content=getcontent()
lg=MemorySize(*content)
*content=gzUncompress(*content,lg)
Debug PeekS(*content,-1,#PB_Ascii)
FreeMemory(*content)

Restore gzfile2
*content=getcontent()
lg=MemorySize(*content)
*content=gzUncompress(*content,lg)
Debug PeekS(*content,-1,#PB_Ascii)
FreeMemory(*content)

Delay(5000)

DataSection
gzfile1:
Data.s "H4sICOSCsEgAAHRlc3QyLnR4dAANi7sRwkAMBXNm6OFVQBdkNPHQyUYgn+Bs83G3hAQEDJnHgS"
Data.s "/a3WD3jrt6TOjGIvZxtoGT5TRDovsSjbpNEJZk7oEXLvaw3XZzIMTaRX/EEMIjoY6ez2j+GUmH8"
Data.s "u4rHFe65tuoNaqfWdcVNlmb93MAAAA="
Data.s ""
gzfile2:
Data.s "H4sICJ8/sEgAAHRlc3QzLnR4dADVVd9v2jAQfk6l/g9e+tBQlARKmTpCkLZuD93DNmnTXqo+GO"
Data.s "eSuDh2ZjsUNPV/n21SfnSa1vKCCgg55+++++58voTh5PhoHCu9ZGBXikhaa8QwLxpcQOp/xnP83"
Data.s "Rl9pJe1sWhY6HjbrCRJ/TsV5w0nVHBQ0Z3yJ4bU7e/Jat3ehOHxkTfHEmmhMfsJXGOOFUrRMEFx"
Data.s "jH81FClAlGeUYI6AId5UIAXKAM1b8MoV1PFRS1VRtUXE4R69lxIvg07iILmQgYXVaS9B9XgnsDF0"
Data.s "ux3028C8LZqb+tYwnbYRT1EXfWmqKcigNsu+5fUe1uHnVNHpPwV45mfLqE0dUUZVzfDymlNCMQucp"
Data.s "8mkYzBWwqowhqJnHa1w5JRTq5yOH+FmvRbt7US/oVZ3JkhTGUtUgP7EwC4/LK+zwCa4AXYi1yJRqyl"
Data.s "xbDQP/iY0lZgyQWannVVIT3e7Dm6L0P7VQlHbKo+OgV5VCaFN9gUovQ1py9tmAosa8+xKMIZrBevN5"
Data.s "P912corYsALXR68QusARmv1lTRMiwhWgdTNoEtvozlmDRgp/eSJx7RRBMtvmOGpxBun4a7T04MwV8Xc"
Data.s "mxdH7+0Tvffcw3fdb7/jCjRGpdZ1COaKz1P/SnBt0OEPMyp8RFZP7cwodcUSREosFeiUKhFeXg7fhX1/"
Data.s "4rgY5TNUSshTn1bYNFVs+4oJ9RFyymk7sIhSPpLAUt8doioBdieTBUx26eJdvusMBBMFJWIvtuc5uO3Na"
Data.s "Dxp+77vzvKeZrocnQ/P64UpaHzWGgZve8ZwFhtECbQo9WhwMXAQb4rJrJCi4VlIjHg5Osndx+7lTGA9Yp"
Data.s "Br+2RVhJjRgq9ND1sCzg8tYHBoARcHEvBqX+Cv44X8B0240m8gCQAA"
Data.s ""
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: gzip problems with static library

Post by gnozal »

fizban wrote:... In the following example, I have base64 encoded a couple of files in the data section so that they are easier to post here. The first one works. The second doesn't, with an invalid memory access. Any ideas why?...
I have not compiled the static library (don't remember from where I got it) nor have I designed the code.
But you are right, the problem seems to be the static library : I have uploaded another ZLIB version : http://freenet-homepage.de/gnozal/PBLIB ... c_GZip.zip
Could you try it ?
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
fizban
User
User
Posts: 31
Joined: Thu Sep 20, 2007 7:36 am
Location: Spain

Post by fizban »

Either it is the same library or I am downloading a proxied version. Winmerge reports that the lib file is identical as the I was using. MD5 of the lib file is D1AC5A0F0B2BE7349F76408D988A19F4
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

fizban wrote:Either it is the same library or I am downloading a proxied version. Winmerge reports that the lib file is identical as the I was using. MD5 of the lib file is D1AC5A0F0B2BE7349F76408D988A19F4
Must be a proxy / cache issue : I just downloaded the lib, I get 23f46a8a543fea47eacdcc0537ae1f04 for ZlibStatic.lib
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
fizban
User
User
Posts: 31
Joined: Thu Sep 20, 2007 7:36 am
Location: Spain

Post by fizban »

Thanks. I managed to download the new version using the IP address instead of the url name. This seems to have fooled the proxy. I checked the file and it matches the MD5 you posted. Besides, the file is smaller.
I tested it and this one seems to work. Thanks.

Did you compile this one yourself?
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

fizban wrote:Did you compile this one yourself?
Nope. Iirc, it comes from http://www.winimage.com/zLibDll/
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
fizban
User
User
Posts: 31
Joined: Thu Sep 20, 2007 7:36 am
Location: Spain

Post by fizban »

You must have done something additional. I couldn't find a lib that worked with PB there. Besides, there are some references to purezip inside your lib...
Post Reply