GZipStream works, but extension is lost

I use the following code for a zip file and it works fine, but when I unpack using WinRar, I get the original file name without extension, any key, why if the file name is myReport.xls , when I unpack, 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(); } } 
+6
source share
2 answers

GZip only compresses one file - not knowing the name. Therefore, if you are myReport.xls file myReport.xls , you should name it myReport.xls.gz . When unpacking, the last file extension will be deleted, and you will get the original file name.

This is how it has been used on Unix / Linux for centuries ...

+12
source

Very strange. A brief search led to the following:

http://dotnetzip.codeplex.com/discussions/268293

Which means that GZipStream has no way to find out the name of the stream being recorded and suggests you set the FileName property directly.

Hope this helps.

+2
source

Source: https://habr.com/ru/post/899291/


All Articles