PureZIP library : ZIP / UNZIP files
Moderator: gnozal
-
- Enthusiast
- Posts: 746
- Joined: Fri Jul 14, 2006 8:53 pm
- Location: Malta
- Contact:
my bad
I was not setting the variable for size properly
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
Just ask about mental issues!
http://www.lulu.com/spotlight/kingwolf
http://www.sen3.net
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:
Then PureZIP_GetFileCount() says there are 3 files instead of 2.
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
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
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".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
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).
gzip problems with static library
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.
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 ""
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
Re: gzip problems with static library
I have not compiled the static library (don't remember from where I got it) nor have I designed the code.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?...
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).
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
Must be a proxy / cache issue : I just downloaded the lib, I get 23f46a8a543fea47eacdcc0537ae1f04 for ZlibStatic.libfizban 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
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
Nope. Iirc, it comes from http://www.winimage.com/zLibDll/fizban wrote:Did you compile this one yourself?
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).