PureZIP library : ZIP / UNZIP files
Moderator: gnozal
Hehe, well I must appologise again for my superficiality. When I tried the code you posted, I just forgot to add the SetCurrentDirectory() line, and poor PureBasic was not finding the files. Thank you again for having patience with me, I know I can be a pain in the a** sometimes.
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
extract encrypt zip file
hi gnozal
now how can i extract these file ?
like this ? no this not work
Code: Select all
zipfile.s = "C:\Test.zip"
file.s = "C:\Temp\contact.txt"
file2.s = "C:\Temp\Info.txt"
outputfile.s = "C:\unzip file\"
If PureZIP_Archive_Create(zipfile, #APPEND_STATUS_CREATE)
PureZIP_SetArchivePassword("password")
PureZIP_Archive_Compress(file, #False)
PureZIP_Archive_Compress(file2,#False)
PureZIP_Archive_Close()
MessageRequester("ZIP/UNZIP","successful !",0)
EndIf
like this ? no this not work
Code: Select all
MessageRequester("ZIP/UNZIP","Ready to unzip encryted file !",0)
If PureZIP_Archive_Read(zipfile)
;PureZIP_SetArchivePassword("")
ReturnValue.l = PureZIP_Archive_FindFirst() = #UNZ_OK
While ReturnValue = #UNZ_OK
PureZIP_Archive_Extract(MyZIPOutPut.s, #True)
ReturnValue = PureZIP_Archive_FindNext()
Wend
PureZIP_Archive_Close()
EndIf
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
Re: extract encrypt zip file
This works :Micko wrote:now how can i extract these file ?
like this ? no this not work
Code: Select all
zipfile.s = "C:\Test.zip"
outputfile.s = "C:\unzip file"
MessageRequester("ZIP/UNZIP","Ready to unzip encryted file !",0)
If PureZIP_Archive_Read(zipfile)
PureZIP_SetArchivePassword("password")
ReturnValue.l = PureZIP_Archive_FindFirst() = #UNZ_OK
While ReturnValue = #UNZ_OK
PureZIP_Archive_Extract(outputfile, #True)
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).
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
You can use PureZIP_SetCompressionAlgorithm(Algorithm.l)Forge wrote:Is it possible to set a compressionmethod(fastest,...normal,....,best)?
where Algorithm is :
#Z_NO_COMPRESSION : no compression (store)
#Z_DEFLATED : deflate algorithm (default)
Note that if #Z_DEFLATED is used, the compression is always set to #Z_BEST_COMPRESSION.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Hi gnozal,
I have found a (possible?) Bug as I test my new Backup Software.
When I Backup a Folder with 5GB+ the archive will be corrupt.
I thought first I have a bug in my software, but later I see
the same problem if I use another software with PureZIP support.
Do you can confirm the bug ? or are archives limitet to 2GB ?
The Test-Archive is 2.08GB compressed.
BTW:
I use PureZIP_Archive_Compress()
I have found a (possible?) Bug as I test my new Backup Software.
When I Backup a Folder with 5GB+ the archive will be corrupt.
I thought first I have a bug in my software, but later I see
the same problem if I use another software with PureZIP support.
Do you can confirm the bug ? or are archives limitet to 2GB ?
The Test-Archive is 2.08GB compressed.
BTW:
I use PureZIP_Archive_Compress()
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
ZLIB should handle files up to 4 Gbytes, but PB longs are signed [0 - 2 Gbytes], so this may explain a problem with files > 2Gbytes.AL90 wrote:Hi gnozal,
Do you can confirm the bug ? or are archives limitet to 2GB ?
The Test-Archive is 2.08GB compressed.
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:
Maybe, at least for the PB4 version.AL90 wrote:Is it possible to use quads to fix and set the limit up to 4GB ?
Will see. But I don't have >2GB free on any of my PC's for the moment to test this.
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:
Don't rejoice too soonAL90 wrote:Superb. Thanks you very much.gnozal wrote:Maybe, at least for the PB4 version.

Some variables in the library (like filesize) are already quads.
The compression / decompression functions use a fixed size buffer, so no overflow problem expected here (size is 102400 bytes).
Code: Select all
Stream = ReadFile(#PB_Any, FileName)
If Stream
*Buffer = AllocateMemory(#FileBufferSize)
If *Buffer
Repeat
length = ReadData(Stream, *Buffer, #FileBufferSize)
ReturnValue = WriteInZip(PureZIP_Handle_ZIP, *Buffer, length)
Until Eof(Stream)
FreeMemory(*Buffer)
EndIf
CloseFile(Stream)
EndIf
Some questions to help find the problem :
When you compress a file > 2GB,
1. Does PureZIP_Archive_Compress() fail (i.e. produce a corrupt archive : test with WinRAR or else) ?
2. Does PureZIP_Archive_Extract() fail (i.e. produce a corrupt extracted file) ?
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
No. PureZIP_Archive_Compress() was not failed.1. Does PureZIP_Archive_Compress() fail (i.e. produce a corrupt archive : test with WinRAR or else) ?
But PureZIP_Archive_Read() will fail. So I wondered
why I get an empty (Linked) list of contains and have seen that
PureZIP_Archive_Read() has fail. I have test the archive with
TotalCMD and the directory will open. But some files in it are
corrupt as I try to extract in a temp directory.
Yes. See above.2. Does PureZIP_Archive_Extract() fail (i.e. produce a corrupt extracted file) ?
Here now the part of my code to create the archive:
Code: Select all
SetCurrentDirectory(Source$)
If PureZIP_Archive_Create(ZipFile$, #APPEND_STATUS_CREATE)
ResetList(Files())
For i=0 To anzahl-1
NumFile=i*100
NextElement(Files())
file$=Right(Files(),Len(Files())-Len(Source$))
st=PureZIP_Archive_Compress(file$, #True)
If st<>#Z_OK And ArcBreak=#False
If Right(file$,1)<>"\" And FileSize(file$)>0
MessageRequester("Info", "An error has occurred. can't create backup.", #MB_OK|#MB_ICONWARNING)
ArcBreak=#True
EndIf
EndIf
If ArcBreak=#True : Break : EndIf
Next
PureZIP_Archive_Close()
EndIf
I will test it and give you my result if it's done.Both use PB file functions, like ReadData() and WriteData(). Do they handle > 2GB files correctly ?
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
Ok, so PureZIP_Archive_Compress() created a corrupt archive.AL90 wrote:PureZIP_Archive_Read() has fail. I have test the archive with1. Does PureZIP_Archive_Compress() fail (i.e. produce a corrupt archive : test with WinRAR or else) ?
TotalCMD and the directory will open. But some files in it are
corrupt as I try to extract in a temp directory.
But there is not much PB code that could fail :
Code: Select all
Stream = ReadFile(#PB_Any, FileName)
If Stream
*Buffer = AllocateMemory(#FileBufferSize)
If *Buffer
Repeat
length = ReadData(Stream, *Buffer, #FileBufferSize)
ReturnValue = WriteInZip(PureZIP_Handle_ZIP, *Buffer, length)
Until Eof(Stream)
FreeMemory(*Buffer)
EndIf
CloseFile(Stream)
EndIf
ThanksAL90 wrote:I will test it and give you my result if it's done.Both use PB file functions, like ReadData() and WriteData(). Do they handle > 2GB files correctly ?
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
yes.gnozal wrote:Ok, so PureZIP_Archive_Compress() created a corrupt archive.
That's possible. I can't say it exact.Maybe a ZLIB problem ?
So I have now test it with a 4GB file and the test was successful.
Here the testcode.
Code: Select all
; This Code will generate a 4GB TestFile and checks it with a small CRC32-test
TestFile$ = "C:\TestFile.tmp"
TotalSize.q = 4294963200
Size.q = 0
BlockSize.l = 102400 ; Test with '100 KB' BlockSize
Buffer.l = AllocateMemory(BlockSize)
FillMemory_(Buffer, BlockSize, $FF)
CRC32.l = CRC32Fingerprint(Buffer, BlockSize)
If Buffer
If CreateFile(0,TestFile$)
For i=1 To 41943
WriteData(0, Buffer, BlockSize)
Next
CloseFile(0)
EndIf
If ReadFile(0, TestFile$)
Repeat
Size.q + BlockSize
FillMemory_(Buffer, BlockSize, $00)
x = ReadData(0, Buffer, BlockSize)
If x <> BlockSize
MessageRequester("Info", "Read Error!", #MB_OK|#MB_ICONWARNING)
Break
EndIf
If CRC32Fingerprint(Buffer, BlockSize) <> CRC32
MessageRequester("Info", "CRC32 Error!", #MB_OK|#MB_ICONWARNING)
Break
EndIf
Until Eof(0)
CloseFile(0)
EndIf
FreeMemory(Buffer)
EndIf
If Size = TotalSize
MessageRequester("Info", "Test successfully completed!", #MB_OK|#MB_ICONINFORMATION)
EndIf
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
Ok, it's almost the same code as I use [see post above] (except "ReturnValue = WriteInZip(PureZIP_Handle_ZIP, *Buffer, length)" of course).AL90 wrote:So I have now test it with a 4GB file and the test was successful.
So it seems to be a ZLIB issue ?
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).