Here's the approach I'd take, Henk: I'd read data from the source chunk by chunk (say, in 4k bites), and compress each one before sending it. You'll want to transmit the original chunk size (4k for all but the last chunk, which will probably be smaller), the compressed size of the chunk (varies depending on how efficient compress() was), then the compressed data itself.
On the recieving end, you'll need to allocate a buffer to accept the transmitted data. This should never be larger than 4100 bytes (UInt16 origSize + UInt16 compSize + 4096 bytes of data or less). You can then allocate a decompression buffer based on the origSize, and pass it and a pointer to the data in your recieve buffer ((char *)buffer[4]) to decompress() to do the dirty work for you. Write your decompressed buffer to your database, or VFS, or the screen, or wherever, free it, clear your recieve buffer and you're ready to recieve the next chunk. Note that you can't append all of the recieved chunks together and decompress them all at once - each must be done separately, just as they were compressed separately. Good luck! Brandon On Thu, 03 Feb 2005 23:01:55 +0100, Henk Jonas <[EMAIL PROTECTED]> wrote: > I would compress the data in chunks. I assume you have control of the > receiver of the data. Then split the data in chunks of xxx KB. Define a > header, where you send the size of the chunks and for easyness the > number of chunks (the last one will be not full) and then split your > data in chunks of the given size, compress and send the result + > compressed size as the first dword. > This would be fast and sufficient. > > Regards > Henk > > Miguel Angel Sotomayor Hernandez wrote: > > > Hi everyone, > > Has anyone used copera's or Tom Zerucha's port of zlib for compressing > > data? I need to compress some data I send over tcp sockets. Because it > > is a large amount of data I use feature memory. Has anyone done this > > before? > > > > Here is a code snippet: > > > > Char *destino; > > Char *origen; > > > > FtrPtrNew(libCreatorID, 1, 1024, (void *)&destino); > > > > StrCopy(origen, otherSource); // I call functions like this several times > > // when necessary: > > FtrPtrResize(libCreatorID, 1, newSize, (void *)&destino); > > DmWrite(destino, currentSize, origen, StrLen(origen)); // I call > > functions like this several times > > > > the manual of zlib (http://www.gzip.org/zlib/manual.html) has, among > > other functions, this one, wich I guess is the one I have to use: > > > > int compress <http://www.gzip.org/zlib/manual.html#compress> (Bytef > > *dest, uLongf *destLen, const Bytef *source, uLong sourceLen); > > > > if destLen is longer than I can hold in dynamic ram, how can I use > > feature memory to store the compressed data? I can pass as "source" a > > pointer to the address where data has been saved using feature memory, > > because I can read directly from feature memory, however, acording to > > what I've found so far, I can't write directly to feature memory, I must > > use DmWrite instead. > > > > So the question is: How can I compress large amount of data (larger than > > heap when compressed)? > > > > Thanks for any help. > > > > -- > ------------------------------------------------------------------------- > Henk Jonas > Palm OS � certified developer > > [EMAIL PROTECTED] www.metaviewsoft.de > ------------------------------------------------------------------------- > > -- > For information on using the Palm Developer Forums, or to unsubscribe, please > see http://www.palmos.com/dev/support/forums/ > -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
