PureZIP library : ZIP / UNZIP files

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

Moderator: gnozal

gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

PB wrote:So I assume the deflate algo is the default, then?
Yep !
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

It's quite funny ...

Today I was looking for a possibility to load external files from a single archive into memory including password protection. So I remembered your userlib and just checked this thread. I thought it will be unusable since I avoid userlibs wherever I can but lucky for me, PureZIP is the only lib by you that is available as a shared library. :lol:

I just did some tests and everything is working fantastic. You are the greatest gnozal and I really appreciate all the effort you have put into this.

Keep up the great work! 8)
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

PureZip problem

Post by PB »

This creates a zip file that Winzip v10.0 can't extract.
A bug, or my mistake? Does it happen for anyone else?
WinZip wrote:---------------------------
WinZip
---------------------------
Error in file #1: bad Zip file offset (Error local header signature not found): disk #1 offset: 0.
---------------------------
OK Help
---------------------------

Code: Select all

f$="c:\program files\internet explorer\iexplore.exe"
z$="c:\test.zip"

If PureZIP_Archive_Create(z$,#APPEND_STATUS_CREATE)
  PureZIP_AddFile(z$,f$,#PureZIP_DontStorePath)
  PureZIP_Archive_Close()
EndIf
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Fluid Byte wrote:Today I was looking for a possibility to load external files from a single archive into memory including password protection. So I remembered your userlib and just checked this thread. I thought it will be unusable since I avoid userlibs wherever I can but lucky for me, PureZIP is the only lib by you that is available as a shared library.
Yes, it was a request ... some PureZIP users don't use PB.
Anyway, I think you can transform almost any userlib into a DLL yourself by wrapping the userlib functions.
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:

Re: PureZip problem

Post by gnozal »

PB wrote:This creates a zip file that Winzip v10.0 can't extract.
A bug, or my mistake? Does it happen for anyone else?
WinZip wrote:---------------------------
WinZip
---------------------------
Error in file #1: bad Zip file offset (Error local header signature not found): disk #1 offset: 0.
---------------------------
OK Help
---------------------------

Code: Select all

f$="c:\program files\internet explorer\iexplore.exe"
z$="c:\test.zip"

If PureZIP_Archive_Create(z$,#APPEND_STATUS_CREATE)
  PureZIP_AddFile(z$,f$,#PureZIP_DontStorePath) ; <------ ERROR
  PureZIP_Archive_Close()
EndIf
You have to use PureZIP_Archive_Compress() instead of PureZIP_AddFile() like in the PureZIP_Archive_Create() code example in the help file.

Code: Select all

If PureZIP_Archive_Create(MyZIP.s, #APPEND_STATUS_CREATE)
  Debug PureZIP_Archive_Compress(MyZIPFile1.s, #FALSE)
  Debug PureZIP_Archive_Compress(MyZIPFile2.s, #FALSE)
  PureZIP_Archive_Close()
EndIf
All PureZIP_Archive_*() functions work together, the other functions like PureZIP_AddFile() are standalone. You can't mix them.
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

Re: PureZip problem

Post by PB »

Thanks!
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Is it possible to include a ZIP archive into the executable with IncludeBinary and then extract a single file from it into memory?
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Fluid Byte wrote:Is it possible to include a ZIP archive into the executable with IncludeBinary and then extract a single file from it into memory?
Not as binary include.
But you can attach your ZIP archive at the end of the executable (like a self-extracting archive). Then, you can extract a single file from it into memory.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

gnozal wrote:Not as binary include.
But you can attach your ZIP archive at the end of the executable (like a self-extracting archive). Then, you can extract a single file from it into memory.
Actually it's a little more complicated than that. I have a password-protected ZIP file which includes various other ZIP files which have to be extracted into memory. Any chance that such a functionality will be added anytime soon? Or is it possible to accomplish this with LZMA Lib?

If the original ZLIB offers such a feature I maybe could do it myself.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Fluid Byte wrote:
gnozal wrote:Not as binary include.
But you can attach your ZIP archive at the end of the executable (like a self-extracting archive). Then, you can extract a single file from it into memory.
Actually it's a little more complicated than that. I have a password-protected ZIP file which includes various other ZIP files which have to be extracted into memory. Any chance that such a functionality will be added anytime soon?
The 'SFX' solution should also work with a password protected archive.
But embedded ZIP files ? No.
Fluid Byte wrote:Or is it possible to accomplish this with LZMA Lib?
Neither. But as I don't rely on a library (except for the compression), it might be possible to add this feature.
Fluid Byte wrote:If the original ZLIB offers such a feature I maybe could do it myself.
Iirc, ZLIB functions to read a ZIP archive (like unzOpen()) can only use a file, not a memory buffer. At least with the ZLIB version I use (original ZLIB modified by Gilles Vollant).
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 »

gnozal wrote:
Fluid Byte wrote:
gnozal wrote:Not as binary include.
But you can attach your ZIP archive at the end of the executable (like a self-extracting archive). Then, you can extract a single file from it into memory.
Actually it's a little more complicated than that. I have a password-protected ZIP file which includes various other ZIP files which have to be extracted into memory. Any chance that such a functionality will be added anytime soon?
The 'SFX' solution should also work with a password protected archive.
But embedded ZIP files ? No.
@Fluid Byte : it looks like I was partially wrong !
For example this works :

Code: Select all

DataSection
  IncludeBinary "Test.zip"
EndDataSection

myFileinfo.PureZIP_FileInfo
If PureZIP_Archive_Read(ProgramFilename())
  ReturnValue.l = PureZIP_Archive_FindFirst() = #UNZ_OK
  While ReturnValue = #UNZ_OK 
    PureZIP_Archive_FileInfo(@myFileinfo)
    Debug "Filename: " + myFileinfo\FileName
    Debug "Compressed Size: " + Str(myFileinfo\CompressedSize)
    Debug "Uncompressed Size: "+ Str(myFileinfo\unCompressedSize)
    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).
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Can't ..., describe ..., how ****ing awsome this is ... :shock:

gnozal > Fred! :P

Seriously, it works without a problem. I was afraid that only the ZIP could be included because it needs to be read from the end of the .EXE. But it seems, it doesn't matter where in your executable the archive is stored. It can even be in the middle because the memory is scanned until the ZIP-Header is found.

This works as well:

Code: Select all

IncludeFile "PureZIP.pbi"

InitSprite() : InitKeyboard()
OpenWindow(0,0,0,800,600,"void",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0,800,600,0,0,0)

CatchSprite(0,?pblogo)
CatchSprite(1,?geebee)

ArchiveFile$ = ProgramFilename()

Index = PureZIPDLL_FindFile(ArchiveFile$,"desert07_RT.jpg",1)
PureZIPDLL_GetFileInfo(ArchiveFile$,Index,pzfi.PureZIP_FileInfo)
lpData = AllocateMemory(pzfi\unCompressedSize)
PureZIPDLL_ExtractMemory(ArchiveFile$,Index,lpData,pzfi\unCompressedSize)

UseJPEGImageDecoder()
CatchSprite(2,lpData)

FreeMemory(lpData)

Repeat
	EventID = WindowEvent()
	
	ExamineKeyboard()
	ClearScreen($804020)
	DisplaySprite(0,10,10)
	DisplaySprite(1,10,85)
	DisplaySprite(2,200,85)
	FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or EventID = #PB_Event_CloseWindow

DataSection
	pblogo:
	IncludeBinary #PB_Compiler_Home + "Examples\Sources\Data\PureBasicLogo.bmp"	
	skybox:
	IncludeBinary #PB_Compiler_Home + "Examples\Sources\Data\skybox.zip"			
	geebee:
	IncludeBinary #PB_Compiler_Home + "Examples\Sources\Data\Geebee2.bmp"
EndDataSection
Thank you very much mate! Great LIB! :o
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Fluid Byte wrote:gnozal > Fred! :P
BLASPHEMY! :lol:
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

PB wrote:
Fluid Byte wrote:gnozal > Fred! :P
BLASPHEMY! :lol:
Ok, maybe not god but at least his trainee. :lol:

@gnozal:

I just discovered a weird bug. If you add UseOGGSoundDecoder() to my or your example the code will fail in both cases. I haven't found a way to get around this yet but maybe you can take a look.
Last edited by Fluid Byte on Wed Feb 18, 2009 12:40 pm, edited 1 time in total.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Fluid Byte wrote:@gnozal:
I just discovered a weird bug. If you add UseOGGSoundDecoder() to my or your example the code will fail in botch cases. I haven't found a way to get around this yet but maybe you can take a look.
It looks like a debugger issue !?
It works without it ... :shock:
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Post Reply