Discuss usage of zlib to compress resp. decompress files in the C Programming forum on Dev Shed. usage of zlib to compress resp. decompress files C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
Time spent in forums: 19 h 29 m 24 sec
Reputation Power: 11
Is there an "easier" way to zip a file by using a dll?
I just want to specify the input file and the output file and nothing more. Is there no existing dll that provides this or have I really write my own?
Time spent in forums: 3 Days 15 h 29 m 40 sec
Reputation Power: 10
I'm not familiar with the topic, but this library does not have such a function. the compress() function that it offers takes an input buffer and length, and an output buffer and length.
If you read your file into memory, you can pass it in as the input buffer and the output buffer will be the zipped file.
I would assume that Bytef is an unsigned char and uLong is an unsigned long.
int compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);
Compresses the source buffer into the destination buffer. sourceLen is the byte length of the source buffer. Upon entry, destLen is the total size of the destination buffer, which must be at least 0.1% larger than sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
This function can be used to compress a whole file at once if the input file is mmap'ed.
compress returns Z_OK if success, Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR if there was not enough room in the output buffer.
__________________ Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
Time spent in forums: 2 Weeks 4 Days 2 h 38 m 46 sec
Reputation Power: 243
If you have zlib.dll you almost certainly have the zlib exe somewhere in your distribution, just make a system call to that zlib exe (search the archives for tons of stuff on system calls). You lose the fine grained abillity to manage error cases, but if all you want to do is zip/unzip files (and are having trouble with the lib) then system will probably save you a lot of headaches.