.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Post New Resource Bookmark and Share   

Unzip and DeSerialize

Posted By:Jean Paul       Posted Date: January 01, 2011    Points: 15    Category:    URL: http://www.dotnetspark.com  

Unzip and DeSerialize

public T UnzipAndDeserialize(string zipFileName)
        FileStream compressedStream = new FileInfo(zipFileName).OpenRead();
        MemoryStream destinationStream = new MemoryStream();
        GZipStream gzipStream = new GZipStream(compressedStream, CompressionMode.Decompress);
        byte[] buffer = new byte[4096];

        int numRead;

        while ((numRead = gzipStream.Read(buffer, 0, buffer.Length)) != 0)
            destinationStream.Capacity += numRead;
            destinationStream.Write(buffer, 0, numRead);


        destinationStream.Position = 0;

        XmlSerializer deserializer = new XmlSerializer(typeof(T));
        T result = (T)deserializer.Deserialize(destinationStream);

        return result;


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend