Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

I have an INF file with compressed.
I have to uncompress the INF file and read the data from that.

Ex: xxx.in_ (contains some sections and keys with compressed format)
i need to decompress the file to xxx.inf and needs to read the sections from that.


I used the below code to decompress the INF file.

C#
using (FileStream sourceFileStream = File.OpenRead(infFile))
                        {
                            using (FileStream destFileStream = File.Create(orgInfFileName))
                            {
                                using (GZipStream decompressingStream = new GZipStream(sourceFileStream, CompressionMode.Decompress))
                                {
                                    int byteRead;
                                    while ((byteRead = decompressingStream.ReadByte()) != -1)
                                    {
                                        destFileStream.WriteByte((byte)byteRead);
                                    }
                                }
                            }
                        }


Using this, i am getting an error like, 'The magic number in GZip header is not correct. Make sure you are passing in a GZip stream.'

Could anyone please help to do this.

Thanks in advance.
Posted
Comments
Tomas Takac 27-Nov-14 9:11am    
You have the code to decompress ZIP files. Then you feed it the INF file and it complains that it's not a ZIP file. So my guess is: INF != ZIP. What's an INF file anyway?
Richard MacCutchan 27-Nov-14 9:30am    
How was it compressed?
Dave Kreskowiak 27-Nov-14 10:30am    
Without knowing exactly how the data was "compressed" it's going to be pretty much impossible for us to know how to decompress it.

If you have the code used for compressing it, that makes it much easier to decompress it.

1 solution

Hi,

maybe your *.in_ file can be extracted by the tool expand.exe
which can be found on your windows installation.

If you are able to expand your *.in_ file by using this tool

e.g. expand.exe Template.in_ Template.inf

then a solution could be to call this tool from your C# programme
as described below.

"process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden"
suppresses any output, so you do not see any command prompt pop up.

C#
Process process = new Process();
process.StartInfo.FileName = "expand.exe";
process.StartInfo.Arguments = "Template.in_ Template.inf";
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.Start();


Make sure to have
using System.Diagnostics;
in your project.

Best regards,
Stephan
 
Share this answer
 

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