Can't open GZIP file

Hello,

I have trouble unzipping GZIP files using either the GZIPDecompressorInputStream or the ZipFile class (the length of the InputStream is -1). Both can’t open this file that was compressed using the GZipStream class from .NET. I have no control over my input files, so I can’t change the compression format.

Is there a way to uncompress such GZIP files using Juce?

Thanks,
Julien.

Works for me:

int main (int argc, char* argv[])
{

    File gzipFile (File::getSpecialLocation (File::userHomeDirectory).getChildFile ("example.gzip"));
    if (gzipFile.existsAsFile())
    {
        GZIPDecompressorInputStream input (gzipFile.createInputStream(), true, GZIPDecompressorInputStream::gzipFormat);
        jassert (! input.isExhausted());
        
        File outputFile (gzipFile.getParentDirectory().getChildFile ("example"));
        
        outputFile.deleteFile();
        ScopedPointer<OutputStream> output = outputFile.createOutputStream();
        if (output)
            *output << input;
    }


    return 0;
}

I think you may be worried by getTotalLength() returning -1, but this just indicates that it’s not clear yet how big the decompressed file will be (before it has been decompressed).

1 Like

Oh sorry, you are right, is it working. I shouldn’t have relied on the getTotatLength(). Thanks a lot for the help.