Unzip a zip in memory and read files

BlitzMax Forums/BlitzMax Programming/Unzip a zip in memory and read files

Czar Flavius(Posted 2011) [#1]
Hi.

Each level in my game has a folder and a number of files, to store the terrain, scripts etc in several files within the folder. I'd like for these files to be stored in a zip archive of some kind, both to save space and to make it easier to transfer levels. All files can be modified with in-game editors so there is no need for ordinary users to see the individual files.

Does anybody know how I could do this? I don't want to extract the files to disk every time I load the level. I want to extract to "virtual" files in ram, and read them.

Thank you.


Czar Flavius(Posted 2011) [#2]
Seperate question, how do I use the Pub.ZLib compress function?

How big does the dest array need to be? In case it doesn't compress, it could be larger than the original array? What is the point of the dest size parameter? Can I give it 1 and get infinate compression?


Czar Flavius(Posted 2011) [#3]
Ok I've got it to compress, but how do I know the size of the compressed data? Otherwise how do I know how much to write to a file without writing the whole block? This function is useless.


Czar Flavius(Posted 2011) [#4]
Ok the dest len paramater is passed in as a pointer, and changed to the compressed size.

There is a missing function called compressBound which returns the maximum size needed to compress the source data, in order to allocate a large enough dest buffer.


Warner(Posted 2011) [#5]
I use the first two functions I found in this thread:
http://www.blitzbasic.com/Community/posts.php?topic=44765#498146
They take a Byte array as a parameter, and handle the resizing themselves. I find them quite convenient.


Grisu(Posted 2011) [#6]
I use Gman's Zip Engine: http://www.gprogs.com/viewtopic.php?id=28

Free, cross-platform and a dedicated support. - All one should need... ;)


Czar Flavius(Posted 2011) [#7]
Can I use this to extract a multi-file archive into memory?


Midimaster(Posted 2011) [#8]
if you talk about read-only-files, you could use Koriolis-ZipStream for them. The advantage is, the ZIP-File can be added as INCBIN, the files inside can be used with the normal stream-functions. So ,there is no need to think about unzipping, etc...

picture=LoadImage("zip::pack.zip/background.png")
'or:
incbin "pack.zip"
LoadImage("zip::incbin::pack.zip/background.png"


The disadvantage is, there is no chance of any kind of writing into the zip.


Czar Flavius(Posted 2011) [#9]
It's for reading and writing level files which can be made with the game editor and shared between friends, so sadly I can't use that. Thanks for the suggestion!