Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
sice the code is working very well but i can't understand the code . i have tried to read it and understand it but it's not a clear for me .

i have used this code because i wanted to decompress some files that i have downloded it on my local drive .

i will be very happy if someone could explain to me step by step what this code is doing ?

here is the link :
GZipStream Class (System.IO.Compression) | Microsoft Docs[^]

What I have tried:

public  void Decompress(FileInfo fileToDecompress)
        {
            using (FileStream originalFileStream = fileToDecompress.OpenRead())
            {
                string currentFileName = fileToDecompress.FullName;
                string newFileName = currentFileName.Remove(currentFileName.Length - fileToDecompress.Extension.Length);

                using (FileStream decompressedFileStream = File.Create(newFileName))
                {
                    using (GZipStream decompressionStream = new GZipStream(originalFileStream, CompressionMode.Decompress))
                    {
                        decompressionStream.CopyTo(decompressedFileStream);
                     
                    }
                }
            }
        }
Posted
Updated 16-Dec-19 5:09am
Comments
ZurdoDev 16-Dec-19 9:55am    
It is not very much code. Just google each method to see what it does. It should be pretty easy.

1 solution

That's trivial code:

Open a file
Get a file name
Remove the extension.
Create and open the new file
Open the ZIP archive you started with
Extract the file.

If you can't work that out, you are punching way above your weight, and need to go back to your tutorials and learn C# properly.
 
Share this answer
 
Comments
[no name] 17-Dec-19 3:02am    
you can't tell me what i have to do .. i have asked an question if you know the answer then help anotehr peopole BUT not more .
OriginalGriff 17-Dec-19 3:22am    
Get off your high horse child - as I said, that is trivial code that anyone with even slight experience in C# should be able to understand. Your lack of comprehension shows your lack of experience, and that's a dangerous thing: you need to understand the basics before you start grabbing code from the internet and stuffing it into an app, hoping all the time it'll do exactly what you want. If you don't understand the code you are copying, you have no idea what it will do to your system - and one good way to distribute ransomware for example would be to post it up as "regular code" and let the inexperienced add to to their own app ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900