PDA

View Full Version : Compressing some data



Raptisoft
08-09-2004, 04:04 AM
Hi all,

I have a question and am looking for advice. I'm looking for a way to apply zip (or preferably, LZMA) compression to a block of memory. That is to say, I do NOT want to produce a file, I want essentially say:

theMemory=new char[10000];
//
// Fill 'theMemory' with data
//
char *newMemory=Compress(theMemory);

and then do:

char *restoreMemory=UnCompress(newMemory);

* * *

As far as I know, none of the existing compression SDKs will compress a hunk of memory-- they're all file writes (am I correct? I haven't researched this extensively). I know I'll need to write up my own stuff, but I wondered if anyone has a good link to a nice hold-my-hand tutorial on how to do this shtuff?

Thanks in advance!

Nikster
08-09-2004, 05:26 AM
This (http://www.gzip.org/zlib/) should be what you want SDK wise, not sure how extensive the tutorials are but it's simple to get working IMHO.

Jim Buck
08-09-2004, 09:01 AM
I'm not sure of the api you are using, but like Rapisoft said, zlib is definitely the way to go. If it's impossible, perhaps you could implement the file pointer you pass to the api (if it takes a file pointer instead of a filename) as one that actually writes to memory. For example, if it's a class, you would inherit from it and override the "write" function.

Nemesis
08-09-2004, 09:10 AM
Raptisoft,

Here's one function from zlib:

int compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);

By the looks of it.. it works from a memory source to a destination.

Hercule
08-10-2004, 04:27 AM
The function of Nemesis work (I did something similar myself).