I am currently trying, with the goal of learning the basic usage of zlib, to create a small utility to compress and decompress files in C++. I am using the compress2
and uncompress
functions provided by zlib to facilitate this. Both of these functions, however, take various types that seem specific to zlib ( Bytef
, uLongf
, etc.) without any automatic conversions between them and C++ types (or, rather, the pointers to each of these types). This makes simple code to interface with zlib more complex, unless I write my entire application based around zlib's types.
My question has 3 parts:
unsigned long
, which I am using in my own file I/O code to represent file lengths? char
pointers to data to (de)compress to Bytef
pointers without changing the data length from the length of my char array? Because char
is one byte and Bytef
's name suggests that it is the same length, I imagine that I can, but I want to make sure. Can I simply assign an unsigned long
(or other non-zlib integral type) to uLongf
and other zlib seemingly-integral types? I skimmed the zlib manual and fully read the sections that could possibly seem relevant, along with a ctrl+f aided search, to no avail. My search engine also does not know the answer.
off_t
, not unsigned long
. On some systems those are different sizes, with off_t
being longer. Bytef
and char
. ( Bytef
is actually unsigned char
, but there is no conversion required.) uLong
is simply unsigned long
. (See zconf.h.) zlibCompileFlags()
to determine the number of bits in each type. (See zlib.h.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.