<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Using a MemoryStream with GZipStream [Lakshan Fernando]</title><link>http://blogs.msdn.com/bclteam/archive/2006/05/10/592551.aspx</link><description>We’ve seen cases where our customers have run into issues when using a MemoryStream with GZip compression. The problem can be frustrating to debug and I thought I’ll blog about it in the hope that others would avoid a similar issue. The code for this</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Using a MemoryStream with GZipStream [Lakshan Fernando]</title><link>http://blogs.msdn.com/bclteam/archive/2006/05/10/592551.aspx#594582</link><pubDate>Wed, 10 May 2006 18:05:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:594582</guid><dc:creator>janmoorlag</dc:creator><description>no</description></item><item><title>Interesting Finds</title><link>http://blogs.msdn.com/bclteam/archive/2006/05/10/592551.aspx#595056</link><pubDate>Thu, 11 May 2006 05:48:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:595056</guid><dc:creator>Jason Haley</dc:creator><description /></item><item><title>re: Using a MemoryStream with GZipStream [Lakshan Fernando]</title><link>http://blogs.msdn.com/bclteam/archive/2006/05/10/592551.aspx#595193</link><pubDate>Thu, 11 May 2006 11:11:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:595193</guid><dc:creator>FullMetal</dc:creator><description>Isn't it a really a non-intuitive behaviour? What is the reason for this strange design decision?</description></item><item><title>re: Using a MemoryStream with GZipStream [Lakshan Fernando]</title><link>http://blogs.msdn.com/bclteam/archive/2006/05/10/592551.aspx#595283</link><pubDate>Thu, 11 May 2006 15:11:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:595283</guid><dc:creator>David Levine</dc:creator><description>I agree that this behavior is not obvious - it would be useful to reconsider the design.&lt;br&gt;&lt;br&gt;The GZip class itself could provide a ToArray method; this would eliminate the need to concern ourselves with the state of the the Stream object, either within or outside the scope of the using statement. The semantics of ToArray could include appending the footer info to the array without closing the zip stream. &lt;br&gt;&lt;br&gt;Also...&lt;br&gt;the code: &lt;br&gt; &lt;br&gt;using (GZipStream zip = new GZipStream(stream, CompressionMode.Compress)&lt;br&gt;&lt;br&gt;will set the internal _leaveOpen field to a value of false, which means that when the zip closes it also closes the underlying stream, so when the code exits the scope of the 'using' statement it closes the MemoryStream - attempts to access the length throw an exception. It should be changed to: &lt;br&gt;&lt;br&gt;using (GZipStream zip = new GZipStream(stream, CompressionMode.Compress,true)&lt;br&gt;{&lt;br&gt;}&lt;br&gt;// access MemoryStream object here...&lt;br&gt;buffer = ms.ToArray();&lt;br&gt;&lt;br&gt;It would also be goodness if the ZIP classes provided better compression - I can only get about a 78% compression ratio on a pure text file - I was getting about a 98% ratio using other libraries. Will this be improved in future versions?&lt;br&gt;&lt;br&gt;&lt;br&gt;</description></item><item><title>re: Using a MemoryStream with GZipStream [Lakshan Fernando]</title><link>http://blogs.msdn.com/bclteam/archive/2006/05/10/592551.aspx#595285</link><pubDate>Thu, 11 May 2006 15:17:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:595285</guid><dc:creator>David Levine</dc:creator><description>Correction...&lt;br&gt;&lt;br&gt;stream.ToArray() does indeed work after closing the stream, but accessing the field&lt;br&gt;stream.Length throws an exception, which is extremely non-intuitive. They should either both work or both not work. And it strikes me as odd (and possibly a security hole) that I can successful convert a closed stream to a valid array. &lt;br&gt;&lt;br&gt;</description></item><item><title>re: Using a MemoryStream with GZipStream [Lakshan Fernando]</title><link>http://blogs.msdn.com/bclteam/archive/2006/05/10/592551.aspx#598223</link><pubDate>Mon, 15 May 2006 21:57:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:598223</guid><dc:creator>dls</dc:creator><description>It sounds like your customers are seeing the GZipStream retain some data due to compression block sizes. Would it be better to call the Flush method rather than relying on the implicit flush during close?</description></item><item><title>re: Using a MemoryStream with GZipStream [Lakshan Fernando]</title><link>http://blogs.msdn.com/bclteam/archive/2006/05/10/592551.aspx#598974</link><pubDate>Tue, 16 May 2006 18:29:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:598974</guid><dc:creator>Lakshan Fernando</dc:creator><description>Thanks a lot for your comments.&lt;br&gt;&lt;br&gt;The footer information is written at GZipStream.Dispose() time and this means that the MemoryStream doesn't have complete data until its closed. As mention earlier, this is not an issue with FileStream since the common usage incorporates Close before decompressing the bits. It seems unintuitive when using the MemoryStream.&lt;br&gt;&lt;br&gt;We are looking into addressing performance and size issues of GZipStream in a future release.&lt;br&gt;Thanks&lt;br&gt;Lakshan Fernando&lt;br&gt;BCL Team&lt;br&gt;</description></item><item><title>An Issue Using A MemoryStream with the Compression classes</title><link>http://blogs.msdn.com/bclteam/archive/2006/05/10/592551.aspx#813270</link><pubDate>Tue, 10 Oct 2006 18:29:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:813270</guid><dc:creator>Darth Coder.Net - Jon Wojtowicz [MVP]</dc:creator><description>&lt;p&gt;While working on compressing view state for web pages I encountered an issue in using the compression...&lt;/p&gt;
</description></item></channel></rss>