Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GZipStream works but extension is lost

I am using following code to zip a file and it works fine but when I decompress with WinRar I get the original file name without the extension, any clue why if filename is myReport.xls when I decompress I get only myReport ?

using (var fs = new FileStream(fileName, FileMode.Open))
{
    byte[] input = new byte[fs.Length];
    fs.Read(input, 0, input.Length);
    fs.Close();

    using (var fsOutput = new FileStream(zipName, FileMode.Create, FileAccess.Write))
    using(var zip = new GZipStream(fsOutput, CompressionMode.Compress))
    {
        zip.Write(input, 0, input.Length);
        zip.Close();
        fsOutput.Close();
    }
}
like image 365
Davide Piras Avatar asked Oct 14 '11 10:10

Davide Piras


1 Answers

GZip compresses only one file - without knowing the name. Therefore if you compress the file myReport.xls you should name it myReport.xls.gz. On decompression the last file extension will be removed so you end up with the original filename.

That its the way how it is used in Unix/Linux for ages...

like image 75
Robert Avatar answered Sep 23 '22 17:09

Robert