<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: &#8220;import zlib&#8221; vs. .NET Framework</title>
	<atom:link href="http://mathieu.fenniak.net/import-zlib-vs-net-framework/feed/" rel="self" type="application/rss+xml" />
	<link>http://mathieu.fenniak.net/import-zlib-vs-net-framework/</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Tue, 31 Mar 2009 04:37:44 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Fuzzyman</title>
		<link>http://mathieu.fenniak.net/import-zlib-vs-net-framework/comment-page-1/#comment-68</link>
		<dc:creator>Fuzzyman</dc:creator>
		<pubDate>Sat, 02 Jun 2007 13:21:04 +0000</pubDate>
		<guid isPermaLink="false">http://mathieu.fenniak.net/import-zlib-vs-net-framework/#comment-68</guid>
		<description>Unfortunately the example posted by Max doesn&#039;t work - because the StreamReader loses information when you read the compressed data in as a string &#039;StreamReader(ms).ReadToEnd()&#039;.

The best solution (IMHO) is to leave the compressed data as bytes (which is what it is).

http://www.ironpython.info/index.php/Compression_with_DeflateStream</description>
		<content:encoded><![CDATA[<p>Unfortunately the example posted by Max doesn&#8217;t work &#8211; because the StreamReader loses information when you read the compressed data in as a string &#8216;StreamReader(ms).ReadToEnd()&#8217;.</p>
<p>The best solution (IMHO) is to leave the compressed data as bytes (which is what it is).</p>
<p><a href="http://www.ironpython.info/index.php/Compression_with_DeflateStream" rel="nofollow">http://www.ironpython.info/index.php/Compression_with_DeflateStream</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Max</title>
		<link>http://mathieu.fenniak.net/import-zlib-vs-net-framework/comment-page-1/#comment-67</link>
		<dc:creator>Max</dc:creator>
		<pubDate>Wed, 23 Aug 2006 09:42:46 +0000</pubDate>
		<guid isPermaLink="false">http://mathieu.fenniak.net/import-zlib-vs-net-framework/#comment-67</guid>
		<description>This is untested, but it should do exactly what you want in a much more concise way. Note that you can actually leave out the explicit Close statements and rely on the GC to reclaim the memory and save yourself 3 further lines of code instantly :). In fact, if you do that you can write decompress in one line ;).

from System.IO import StreamReader, MemoryStream
from System.IO.Compression import CompressionMode, DeflateStream
from System.Text import Encoding

def decompress(data):
    gz = DeflateStream(MemoryStream(Encoding.ASCII.GetBytes(data)), CompressionMode.Decompress)
    str = StreamReader(gz).ReadToEnd()
    gz.Close()
    return str

def compress(data):
    ms = MemoryStream()
    gz = DeflateStream(ms, CompressionMode.Compress, True)
    bytes = Encoding.ASCII.GetBytes(data)
    gz.Write(bytes, 0, bytes.Length)
    gz.Close()
    string = StreamReader(ms).ReadToEnd()
    ms.Close()
    return string</description>
		<content:encoded><![CDATA[<p>This is untested, but it should do exactly what you want in a much more concise way. Note that you can actually leave out the explicit Close statements and rely on the GC to reclaim the memory and save yourself 3 further lines of code instantly <img src='http://mathieu.fenniak.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . In fact, if you do that you can write decompress in one line <img src='http://mathieu.fenniak.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<p>from System.IO import StreamReader, MemoryStream<br />
from System.IO.Compression import CompressionMode, DeflateStream<br />
from System.Text import Encoding</p>
<p>def decompress(data):<br />
    gz = DeflateStream(MemoryStream(Encoding.ASCII.GetBytes(data)), CompressionMode.Decompress)<br />
    str = StreamReader(gz).ReadToEnd()<br />
    gz.Close()<br />
    return str</p>
<p>def compress(data):<br />
    ms = MemoryStream()<br />
    gz = DeflateStream(ms, CompressionMode.Compress, True)<br />
    bytes = Encoding.ASCII.GetBytes(data)<br />
    gz.Write(bytes, 0, bytes.Length)<br />
    gz.Close()<br />
    string = StreamReader(ms).ReadToEnd()<br />
    ms.Close()<br />
    return string</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: casey</title>
		<link>http://mathieu.fenniak.net/import-zlib-vs-net-framework/comment-page-1/#comment-66</link>
		<dc:creator>casey</dc:creator>
		<pubDate>Mon, 12 Jun 2006 18:59:44 +0000</pubDate>
		<guid isPermaLink="false">http://mathieu.fenniak.net/import-zlib-vs-net-framework/#comment-66</guid>
		<description>IronPython really needs to provide simpler class and namespace names, maybe some aliases or an emulation of the sys, os, and other essentials.  OTW it is still almost as much typing as C#!</description>
		<content:encoded><![CDATA[<p>IronPython really needs to provide simpler class and namespace names, maybe some aliases or an emulation of the sys, os, and other essentials.  OTW it is still almost as much typing as C#!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Calvin Spealman</title>
		<link>http://mathieu.fenniak.net/import-zlib-vs-net-framework/comment-page-1/#comment-64</link>
		<dc:creator>Calvin Spealman</dc:creator>
		<pubDate>Tue, 06 Jun 2006 01:11:14 +0000</pubDate>
		<guid isPermaLink="false">http://mathieu.fenniak.net/import-zlib-vs-net-framework/#comment-64</guid>
		<description>You shouldn&#039;t look at this as something that is so much harder to do in IronPython than CPython. Instead, as Fredrik pointed out, its a much simpler implementation of zlib than that for CPython, so wrap this up in a zlib for .Net and everyone one else can reap the benefits of your work!</description>
		<content:encoded><![CDATA[<p>You shouldn&#8217;t look at this as something that is so much harder to do in IronPython than CPython. Instead, as Fredrik pointed out, its a much simpler implementation of zlib than that for CPython, so wrap this up in a zlib for .Net and everyone one else can reap the benefits of your work!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lawrence Oluyede</title>
		<link>http://mathieu.fenniak.net/import-zlib-vs-net-framework/comment-page-1/#comment-63</link>
		<dc:creator>Lawrence Oluyede</dc:creator>
		<pubDate>Mon, 05 Jun 2006 14:21:16 +0000</pubDate>
		<guid isPermaLink="false">http://mathieu.fenniak.net/import-zlib-vs-net-framework/#comment-63</guid>
		<description>Ouch. That means it can&#039;t be shortened :-D</description>
		<content:encoded><![CDATA[<p>Ouch. That means it can&#8217;t be shortened <img src='http://mathieu.fenniak.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mathieu Fenniak</title>
		<link>http://mathieu.fenniak.net/import-zlib-vs-net-framework/comment-page-1/#comment-62</link>
		<dc:creator>Mathieu Fenniak</dc:creator>
		<pubDate>Mon, 05 Jun 2006 13:42:57 +0000</pubDate>
		<guid isPermaLink="false">http://mathieu.fenniak.net/import-zlib-vs-net-framework/#comment-62</guid>
		<description>Lawrence - The .NET version of this code does use the System.IO.Compression.DeflateStream class.</description>
		<content:encoded><![CDATA[<p>Lawrence &#8211; The .NET version of this code does use the System.IO.Compression.DeflateStream class.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lawrence Oluyede</title>
		<link>http://mathieu.fenniak.net/import-zlib-vs-net-framework/comment-page-1/#comment-61</link>
		<dc:creator>Lawrence Oluyede</dc:creator>
		<pubDate>Mon, 05 Jun 2006 13:35:57 +0000</pubDate>
		<guid isPermaLink="false">http://mathieu.fenniak.net/import-zlib-vs-net-framework/#comment-61</guid>
		<description>AFAIK with http://msdn2.microsoft.com/en-us/system.io.compression.aspx it should be shorter.</description>
		<content:encoded><![CDATA[<p>AFAIK with <a href="http://msdn2.microsoft.com/en-us/system.io.compression.aspx" rel="nofollow">http://msdn2.microsoft.com/en-us/system.io.compression.aspx</a> it should be shorter.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fredrik</title>
		<link>http://mathieu.fenniak.net/import-zlib-vs-net-framework/comment-page-1/#comment-65</link>
		<dc:creator>Fredrik</dc:creator>
		<pubDate>Mon, 05 Jun 2006 07:02:16 +0000</pubDate>
		<guid isPermaLink="false">http://mathieu.fenniak.net/import-zlib-vs-net-framework/#comment-65</guid>
		<description>On the other hand, the source code for the zlib module is 1000 lines long, so 45 lines for a partial implementation isn&#039;t all that bad...</description>
		<content:encoded><![CDATA[<p>On the other hand, the source code for the zlib module is 1000 lines long, so 45 lines for a partial implementation isn&#8217;t all that bad&#8230;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
