tags:

views:

32

answers:

1

I am forced to use an older version of the SharpZipLib and the standard Microsoft libraries to perform this. I have a gziped file whose name is different than the filename inside the archive. I need to parse the gzip file header to return the original filename. Here is documentation on the gzip website:

http://www.gzip.org/zlib/rfc-gzip.html#conventions

And a java example that looks like it might be doing what I want. it looks like it checks for the file header, but doesn't actually read the file name.

(Sorry couldn't post more than 1 hyperlink) (http://www).java2s.com/Open-Source/Java-Document/6.0-JDK-Modules/j2me/java/util/zip/GZIPInputStream.java.htm

Any help on this problem would be much appreciated. Thanks!

A: 

Well if finally figured it out. Its not the safest way or best but i needed a quick and dirty way to do it and this works. So if anyone else needs to know this or want to improve on it, here you go.

using (FileStream stream = File.OpenRead(filePath))
        {
            int size = 2048;
            byte[] data = new byte[2048];
            size = stream.Read(data,0,size);

            if (data[3] == 8)
            {
                List<byte> byteList = new List<byte>();

                int i = 10;
                while (data[i] != 0)
                {
                    byteList.Add(data[i]);
                    i++;
                }
                string test = System.Text.ASCIIEncoding.ASCII.GetString(byteList.ToArray());
                Console.WriteLine(test);

            }
        }
Eric Pritchett