'zlib gzread does not decompress entire file
I'm trying to write a function that can decompress a gzip-compressed file with zlib. The file I am trying to decompress is 294 bytes compressed, and I am able to decompress it with 7zip to give me a 512 byte file. But when I run the following program, I get an output that is only the first 26 bytes of the correctly-decompressed file.
void gdef(std::string filename, std::vector<char> &decompressed){
gzFile infile = gzopen(filename.c_str(), "r");
char buffer[4096];
while(true){
int arrSize = gzread(infile, buffer, 4096);
if(arrSize == 0){
return;
}
decompressed.insert(decompressed.end(), buffer, buffer+arrSize);
}
int main(){
std::string filename = "tree.schem";
std::vector<char> compressed;
gdef(filename, compressed);
for(int i = 0; i < compressed.size(); i++){
std::cout << compressed[i];
}
return 0;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
