Loading zip compressed files

Hey guys.
Playing around with opening up a compressed file inside of cinder. Looking at the buffer class, there is a decompressBuffer function which seems to allow for gzip decompression. Here is the relevant line in the cinder source https://github.com/cinder/Cinder/blob/master/src/cinder/Buffer.cpp#L148 . This is how I’m trying to do it.

auto inFile = loadFile("compressedTextFile.txt");
Buffer loadedBuf(inFile);

Buffer decom = decompressBuffer(loadedBuf, true, true);
string dString( static_cast<const char*>( decom.getData() ) );

console () << loadedBuf.getSize() << endl;   // the correct size
console () << decom.getSize() << endl;        // this is 0

My decompressed buffer is always 0. Am I doing this wrong? For reference, I can type “unzip compressedTextFile.txt” in the terminal and it will unpack correctly.



Could you check the format of the compressed file?

file compressedTextFile.txt

It seems decompress works for files created with gzip. Not zip.

Does not work:

file myfile.zip
Zip archive data, at least v2.0 to extract

Does work:

file myfile.gz
gzip compressed data, was


1 Like

Yup, it is indeed Zip archive data. Good to know, and thanks!