简体   繁体   中英

zlib gzopen() returns a compressed file stream. Does it decompress the file?

zlib gzopen() returns a compressed file stream.

gzFile data_file;
data_file = gzopen(filename.c_str(), "r");

where data_file is the compressed file stream. I may have missed this from zlib docs. But, does this decompress the opened file? Or is gzopen() able to directly parse the gzipped file without the need to decompress it?

Thanks in advance!

gzopen doesn't decompress the data, gzread decompresses as you read it.

I haven't found a simple statement of this fact in the zlib docs, but if you want to "prove" it to yourself create a large (several GB) compressed file, and then measure how quickly gzopen returns. It "obviously" doesn't take the time required to decompress the whole file. If you look into how gzip compression is defined, you'll see that it's designed to be written and read as a stream, that is to say you don't need to decompress the whole file at once.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM