PureZIP library : ZIP / UNZIP files

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

Moderator: gnozal

User avatar
Michael Vogel
Addict
Addict
Posts: 2666
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: PureZIP library : ZIP / UNZIP files

Post by Michael Vogel »

I tried to change one single file in a sub directory of a large zip file and failed so far...

...the first problem have been Memory Errors when executing PureZIP_DeleteFile when the archive is not in a proper format (no problems have been seen with all other commands) - workaround extracting and compacting all files to create a compatible archive.

...but now I am still not able to remove the file in the sub directory and so I get multiple files with the same name in the archive. Is there a simple method to overwrite an existing file?

Code: Select all

Archiv.s="Test.zip"
Datei.s="subdir\file.txtl"
						
Global Buffer.s
Global Ok.i

If PureZIP_Archive_Read(Archiv)
	myfileinfo.PureZIP_FileInfo
	If PureZIP_Archive_Locate(Datei)=#UNZ_OK
		Buffer=Space(myFileinfo\unCompressedSize)
		If PureZIP_Archive_ExtractMem(@Buffer,Len(Buffer))>0
			Buffer=Left(Buffer,123)+"***"+Mid(Buffer,123)
			Ok=1
		EndIf
	EndIf
	PureZIP_Archive_Close()
EndIf

If Ok
	Debug PureZIP_DeleteFile(Archiv,Datei)
	If PureZIP_Archive_Create(Archiv,#APPEND_STATUS_ADDINZIP)
		Debug PureZIP_Archive_CompressMem(Datei,@Buffer,Len(Buffer)-1)
		PureZIP_Archive_Close()
	EndIf
EndIf
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: PureZIP library : ZIP / UNZIP files

Post by gnozal »

Michael Vogel wrote:...the first problem have been Memory Errors when executing PureZIP_DeleteFile when the archive is not in a proper format (no problems have been seen with all other commands) - workaround extracting and compacting all files to create a compatible archive.
PureZIP_DeleteFile() uses some low level ZLIB functions, so a corrupt archive may be a problem. I fixed a memory allocation issue, so maybe this is fixed.
Michael Vogel wrote:...but now I am still not able to remove the file in the sub directory and so I get multiple files with the same name in the archive. Is there a simple method to overwrite an existing file?
I have uploaded a new version, it should work now with your code. You need to add a PureZIP_Archive_FileInfo() call before using myFileinfo\unCompressedSize though.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
Michael Vogel
Addict
Addict
Posts: 2666
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: PureZIP library : ZIP / UNZIP files

Post by Michael Vogel »

gnozal wrote:I fixed a memory allocation issue, so maybe this is fixed.
Haven't changed anything here, I was trying to delete a file within MS office files (dotx, xlam, ppam) which seem to have been packed without any compression.
gnozal wrote:I have uploaded a new version, it should work now with your code. You need to add a PureZIP_Archive_FileInfo() call before using myFileinfo\unCompressedSize though.
Oh, must have deleted the PureZIP_Archive_FileInfo() line in my last code example. :oops:

Your new version do show the same effects than before, I fear I must do something wrong. I use this small zip file for the following code:

Code: Select all

Archiv.s="Zip.zip"
Datei.s="Dir1\Text1.txt"

Global Buffer.s="Hallo"
Global Ok

#Banner="***Yippieh***"

If PureZIP_Archive_Read(Archiv)
	myfileinfo.PureZIP_FileInfo
	If PureZIP_Archive_Locate(Datei)=#UNZ_OK
		PureZIP_Archive_FileInfo(@myFileinfo)
		Buffer=Space(myFileinfo\unCompressedSize)
		If PureZIP_Archive_ExtractMem(@Buffer,Len(Buffer))>0
			f=FindString(Buffer,"Change")
			If f
				f=FindString(Buffer,"[",f)
				e=FindString(Buffer,"]",f+1)
				Debug "Old Text: "+Mid(Buffer,f+1,e-f-1)
				If e
					Debug "New Text: "+#Banner
					Buffer=Left(Buffer,f)+#Banner+Mid(Buffer,e)
					Ok=#True
				EndIf
			EndIf
		EndIf
	EndIf
	PureZIP_Archive_Close()
EndIf

If Ok
	PureZIP_Archive_Close()
	Debug PureZIP_DeleteFile(Archiv,Datei)
	If PureZIP_Archive_Create(Archiv,#APPEND_STATUS_ADDINZIP)
		Debug PureZIP_Archive_CompressMem(Datei,@Buffer,Len(Buffer)-1)
		PureZIP_Archive_Close()
	EndIf
EndIf
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: PureZIP library : ZIP / UNZIP files

Post by gnozal »

Michael Vogel wrote:Haven't changed anything here, I was trying to delete a file within MS office files (dotx, xlam, ppam) which seem to have been packed without any compression.
I tried PureZIP_DeleteFile() on an archive with no compression (store) : no problem.
It seems to be something else.
Michael Vogel wrote:Your new version do show the same effects than before, I fear I must do something wrong. I use this small zip file for the following code...
ZIP archives store the '\' in unix style '/'.
I have updated PureZIP_DeleteFile() in the library to handle the '\' correctly.

I hope it works as expected now : version 2.33 (MAR 9th 2012).
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User_Russian
Addict
Addict
Posts: 1443
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: PureZIP library : ZIP / UNZIP files

Post by User_Russian »

How can I open several files at once?
Function PureZIP_Archive_Read() only works with a single archive.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: PureZIP library : ZIP / UNZIP files

Post by gnozal »

User_Russian wrote:Function PureZIP_Archive_Read() only works with a single archive.
Correct.
User_Russian wrote:How can I open several files at once?
Currently, you can't.
If you need this feature, have a look at MiniZip
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Nituvious
Addict
Addict
Posts: 998
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

Re: PureZIP library : ZIP / UNZIP files

Post by Nituvious »

Following code crashes, using PB5 and the dll version.

Code: Select all

Procedure openzip(filename.s)
	Define myFileinfo.PureZIP_FileInfo
	Define ReturnValue.l
If PureZIPDLL_Archive_Read(filename)
   ReturnValue.l = PureZIPDLL_Archive_FindFirst()
   While ReturnValue = #UNZ_OK 
      Debug PureZIPDLL_Archive_FileInfo(@myFileinfo)
      Debug "Filename: " + myFileinfo\FileName
      Debug "Compressed Size: " + Str(myFileinfo\CompressedSize)
      Debug "Uncompressed Size: "+ Str(myFileinfo\unCompressedSize)
      ReturnValue = PureZIPDLL_Archive_FindNext()
   Wend
   PureZIPDLL_Archive_Close()
 EndIf 
 EndProcedure
Should add that I receive an IMA at EndProcedure.
▓▓▓▓▓▒▒▒▒▒░░░░░
Nituvious
Addict
Addict
Posts: 998
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

Re: PureZIP library : ZIP / UNZIP files

Post by Nituvious »

Sorry for the double post but it seems the DLL version is extremely unstable. PureZIPDLL_AddMemory("D:\test.zip", "folder/test.txt", @"Hello world", len("Hello world")) doesn't write contents to the file entirely, or the contents become something like, "4050 64".

Even the examples do this. Any idea whats going on here?


[edit] disregard this post. I think this may actually be an error with my system itself.
▓▓▓▓▓▒▒▒▒▒░░░░░
zeehteam
New User
New User
Posts: 1
Joined: Sat Aug 03, 2013 12:56 pm

Re: PureZIP library : ZIP / UNZIP files

Post by zeehteam »

Is it possible to upgrade PureZip DLL to make it possible to do file deletion in archive, file renaming in archive, and read archive from memory? Thank you.
Opcode
Enthusiast
Enthusiast
Posts: 137
Joined: Thu Jul 18, 2013 4:58 am

Re: PureZIP library : ZIP / UNZIP files

Post by Opcode »

zeehteam wrote:Is it possible to upgrade PureZip DLL to make it possible to do file deletion in archive, file renaming in archive, and read archive from memory? Thank you.
PureBasic supports archives since 5.10 I think, might wanna give them a look. It can do a couple of things you're looking to do.

http://www.purebasic.com/documentation/ ... index.html
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: PureZIP library : ZIP / UNZIP files

Post by IdeasVacuum »

ruslanx wrote:Thanks Gnozal for quick answer ... I will use 7z.exe ... 7z a archive.7z -p123 -mhe *.txt

but I need a 'ProgressionCallback' .... I find a key for 7z -so (write data to stdout)
how I can read info from stdout .. can you give a peace of code or example ..thx.
Another way:

Code: Select all

 *Buffer = AllocateMemory(1024 * SizeOf(character))

   i7zip = RunProgram("C:\7zip\7za.exe", " a -t7z my_archive.7z C:\MyTemp", "C:\", #PB_Program_Open | #PB_Program_Hide | #PB_Program_Read)
If i7zip

          While ProgramRunning(i7zip)

                    If AvailableProgramOutput(i7zip)

                           ReadProgramData(i7zip,*Buffer,1024)
                                 Debug PeekS(*Buffer, 1024, #PB_UTF8)
                    EndIf
          Wend

          CloseProgram(i7zip)
EndIf
Unfortunately, it seems that PB receives the 7zip output when the whole task is complete, so you can't use the output to show progress. Did you find a better way with 7zip's -so flag? I can't get that option to work.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
graves
Enthusiast
Enthusiast
Posts: 160
Joined: Wed Oct 03, 2007 2:38 pm
Location: To the deal with a pepper

Re: PureZIP library : ZIP / UNZIP files

Post by graves »

Hi
Compiling with PB 5.21 LTS, the compiler says:
PB library missing Misc

PB has been removed it.
What is the solution?
Last edited by graves on Sat Dec 21, 2013 10:48 am, edited 1 time in total.
User avatar
Bisonte
Addict
Addict
Posts: 1226
Joined: Tue Oct 09, 2007 2:15 am

Re: PureZIP library : ZIP / UNZIP files

Post by Bisonte »

Gnozal's libraries are only for this PB Version, their compiled for. Latest Update of his libs is to fit to PB5.0x (Tailbite).

If you want to use gnozal's libs with a newer version of PB, you have to wait for gnozal's update....

By the way... Where is Gnozal ? Normally his libs are converted to the newest PB version at real-time ;)
PureBasic 6.04 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: PureZIP library : ZIP / UNZIP files

Post by PB »

> PureBasic supports archives since 5.10 I think

But not with passwords, so I still need Gnozal's lib for now.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Bisonte
Addict
Addict
Posts: 1226
Joined: Tue Oct 09, 2007 2:15 am

Re: PureZIP library : ZIP / UNZIP files

Post by Bisonte »

PB wrote:> PureBasic supports archives since 5.10 I think

But not with passwords, so I still need Gnozal's lib for now.
Give a try to HeX0r's or TS-Soft's includes here in the forum ....
PureBasic 6.04 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
Post Reply