Page 24 of 40

Posted: Fri Oct 05, 2007 8:34 am
by Inf0Byt3
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.

extract encrypt zip file

Posted: Fri Oct 12, 2007 11:31 pm
by Micko
hi gnozal

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
now how can i extract these file ?
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

Re: extract encrypt zip file

Posted: Sat Oct 13, 2007 7:40 am
by gnozal
Micko wrote:now how can i extract these file ?
like this ? no this not work
This works :

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

Posted: Sat Oct 13, 2007 8:03 am
by X0r
Is it possible to set a compressionmethod(fastest,...normal,....,best)?

Posted: Sat Oct 13, 2007 11:19 am
by gnozal
Forge wrote:Is it possible to set a compressionmethod(fastest,...normal,....,best)?
You can use PureZIP_SetCompressionAlgorithm(Algorithm.l)
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.

Posted: Sun Oct 21, 2007 5:59 pm
by AL90
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()

Posted: Mon Oct 22, 2007 8:49 am
by gnozal
AL90 wrote:Hi gnozal,
Do you can confirm the bug ? or are archives limitet to 2GB ?
The Test-Archive is 2.08GB compressed.
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.

Posted: Mon Oct 22, 2007 4:54 pm
by AL90
Is it possible to use quads to fix and set the limit up to 4GB ?

Posted: Tue Oct 23, 2007 7:42 am
by gnozal
AL90 wrote:Is it possible to use quads to fix and set the limit up to 4GB ?
Maybe, at least for the PB4 version.
Will see. But I don't have >2GB free on any of my PC's for the moment to test this.

Posted: Tue Oct 23, 2007 2:52 pm
by AL90
gnozal wrote:Maybe, at least for the PB4 version.
Superb. Thanks you very much. :wink:

Posted: Tue Oct 23, 2007 3:20 pm
by gnozal
AL90 wrote:
gnozal wrote:Maybe, at least for the PB4 version.
Superb. Thanks you very much. :wink:
Don't rejoice too soon :wink:
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
Both use PB file functions, like ReadData() and WriteData(). Do they handle > 2GB files correctly ?

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) ?

Posted: Tue Oct 23, 2007 4:02 pm
by AL90
1. Does PureZIP_Archive_Compress() fail (i.e. produce a corrupt archive : test with WinRAR or else) ?
No. PureZIP_Archive_Compress() was not failed.
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.
2. Does PureZIP_Archive_Extract() fail (i.e. produce a corrupt extracted file) ?
Yes. See above.


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
Both use PB file functions, like ReadData() and WriteData(). Do they handle > 2GB files correctly ?
I will test it and give you my result if it's done.

Posted: Tue Oct 23, 2007 4:11 pm
by gnozal
AL90 wrote:
1. Does PureZIP_Archive_Compress() fail (i.e. produce a corrupt archive : test with WinRAR or else) ?
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.
Ok, so PureZIP_Archive_Compress() created a corrupt archive.
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
Maybe a ZLIB problem ?
AL90 wrote:
Both use PB file functions, like ReadData() and WriteData(). Do they handle > 2GB files correctly ?
I will test it and give you my result if it's done.
Thanks

Posted: Tue Oct 23, 2007 6:13 pm
by AL90
gnozal wrote:Ok, so PureZIP_Archive_Compress() created a corrupt archive.
yes.
Maybe a ZLIB problem ?
That's possible. I can't say it exact.

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

Posted: Wed Oct 24, 2007 7:39 am
by gnozal
AL90 wrote:So I have now test it with a 4GB file and the test was successful.
Ok, it's almost the same code as I use [see post above] (except "ReturnValue = WriteInZip(PureZIP_Handle_ZIP, *Buffer, length)" of course).
So it seems to be a ZLIB issue ?