<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Michael E. Chancey Jr. &#187; Stream</title>
	<atom:link href="http://michael.chanceyjr.com/tag/stream/feed/" rel="self" type="application/rss+xml" />
	<link>http://michael.chanceyjr.com</link>
	<description></description>
	<lastBuildDate>Fri, 20 May 2011 03:43:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>TCP Message Framework</title>
		<link>http://michael.chanceyjr.com/useful-code/tcp-message-framework/</link>
		<comments>http://michael.chanceyjr.com/useful-code/tcp-message-framework/#comments</comments>
		<pubDate>Fri, 03 Dec 2010 03:33:25 +0000</pubDate>
		<dc:creator>Michael E. Chancey Jr.</dc:creator>
				<category><![CDATA[Useful Code]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[Binary]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C-Sharp]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Compression]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Extension]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[Message]]></category>
		<category><![CDATA[Serialize]]></category>
		<category><![CDATA[Stream]]></category>
		<category><![CDATA[String]]></category>
		<category><![CDATA[TCP]]></category>
		<category><![CDATA[TCP/IP]]></category>

		<guid isPermaLink="false">http://michael.chanceyjr.com/?p=692</guid>
		<description><![CDATA[TCP Message Framework is a simple framework built to make transport of TCP messages via C# a little easier. I have devised a method of sending messages and unpacking them on the other side that requires no additional coding to handle any new message type a programmer might come up with. Need to create a [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://michael.chanceyjr.com/site/wp-content/uploads/2010/12/MessageFramework.png"><img src="http://michael.chanceyjr.com/site/wp-content/uploads/2010/12/MessageFramework-150x109.png" alt="" title="MessageFramework" width="150" height="109" class="alignleft size-thumbnail wp-image-689" /></a><br />
TCP Message Framework is a simple framework built to make transport of TCP messages via C# a little easier.  I have devised a method of sending messages and unpacking them on the other side that requires no additional coding to handle any new message type a programmer might come up with.  Need to create a keep-alive packet.  Simply inherit the message class, write the server side and client side code and you are done.  The transport and unwrapping of the message is all handled by the framework.</p>
<p>I used a very similar method when writing my instant messenger client/server.  There is some overhead but when weighed out against it&#8217;s simplcity its very minimal.  If you would like you can download the entire sample project or view the code through this website.<br />
<h3><a href="http://michael.chanceyjr.com/site/wp-content/uploads/2010/12/MessageFramework.zip">Download Sample Project</a> &#8211; <a href="http://michael.chanceyjr.com/free-stuff/tcp-message-framework/">View Code</a></h3>



Share


	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=TCP%20Message%20Framework%20-%20http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Ftcp-message-framework%2F" title="Twitter"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Ftcp-message-framework%2F&amp;title=TCP%20Message%20Framework&amp;bodytext=%0D%0ATCP%20Message%20Framework%20is%20a%20simple%20framework%20built%20to%20make%20transport%20of%20TCP%20messages%20via%20C%23%20a%20little%20easier.%20%20I%20have%20devised%20a%20method%20of%20sending%20messages%20and%20unpacking%20them%20on%20the%20other%20side%20that%20requires%20no%20additional%20coding%20to%20handle%20any%20new%20messa" title="Digg"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Ftcp-message-framework%2F&amp;title=TCP%20Message%20Framework" title="StumbleUpon"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Ftcp-message-framework%2F&amp;title=TCP%20Message%20Framework&amp;notes=%0D%0ATCP%20Message%20Framework%20is%20a%20simple%20framework%20built%20to%20make%20transport%20of%20TCP%20messages%20via%20C%23%20a%20little%20easier.%20%20I%20have%20devised%20a%20method%20of%20sending%20messages%20and%20unpacking%20them%20on%20the%20other%20side%20that%20requires%20no%20additional%20coding%20to%20handle%20any%20new%20messa" title="del.icio.us"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://michael.chanceyjr.com/useful-code/tcp-message-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Read File From FTP Using C#</title>
		<link>http://michael.chanceyjr.com/useful-code/read-file-from-ftp-using-c/</link>
		<comments>http://michael.chanceyjr.com/useful-code/read-file-from-ftp-using-c/#comments</comments>
		<pubDate>Tue, 18 May 2010 15:30:36 +0000</pubDate>
		<dc:creator>Michael E. Chancey Jr.</dc:creator>
				<category><![CDATA[Useful Code]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C-Sharp]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[FTP]]></category>
		<category><![CDATA[Network]]></category>
		<category><![CDATA[Stream]]></category>
		<category><![CDATA[TCP/IP]]></category>

		<guid isPermaLink="false">http://michael.chanceyjr.com/?p=624</guid>
		<description><![CDATA[Here is a small snippet on reading a text file from an FTP server. This could be replaced with a binary file or any other type; I just used a text file to keep it simple. Code //CREATE AN FTP REQUEST WITH THE DOMAIN AND CREDENTIALS System.Net.FtpWebRequest tmpReq = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(&#34;ftp://domain.com/file.txt&#34;); tmpReq.Credentials = new System.Net.NetworkCredential(&#34;userName&#34;, &#34;Password&#34;); [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a small snippet on reading a text file from an FTP server.  This could be replaced with a binary file or any other type; I just used a text file to keep it simple.</p>
<h3>Code</h3>
<hr/>
<pre class="brush: csharp;">
            //CREATE AN FTP REQUEST WITH THE DOMAIN AND CREDENTIALS
            System.Net.FtpWebRequest tmpReq = (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(&quot;ftp://domain.com/file.txt&quot;);
            tmpReq.Credentials = new System.Net.NetworkCredential(&quot;userName&quot;, &quot;Password&quot;);

            //GET THE FTP RESPONSE
            using (System.Net.WebResponse tmpRes = tmpReq.GetResponse())
            {
                //GET THE STREAM TO READ THE RESPONSE FROM
                using (System.IO.Stream tmpStream = tmpRes.GetResponseStream())
                {
                    //CREATE A TXT READER (COULD BE BINARY OR ANY OTHER TYPE YOU NEED)
                    using (System.IO.TextReader tmpReader = new System.IO.StreamReader(tmpStream))
                    {
                        //STORE THE FILE CONTENTS INTO A STRING
                        string fileContents = tmpReader.ReadToEnd();

                        //DO SOMETHING WITH SAID FILE CONTENTS
                    }
                }
            }
</pre>



Share


	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Read%20File%20From%20FTP%20Using%20C%23%20-%20http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fread-file-from-ftp-using-c%2F" title="Twitter"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fread-file-from-ftp-using-c%2F&amp;title=Read%20File%20From%20FTP%20Using%20C%23&amp;bodytext=Here%20is%20a%20small%20snippet%20on%20reading%20a%20text%20file%20from%20an%20FTP%20server.%20%20This%20could%20be%20replaced%20with%20a%20binary%20file%20or%20any%20other%20type%3B%20I%20just%20used%20a%20text%20file%20to%20keep%20it%20simple.%0D%0A%0D%0ACode%0D%0A%0D%0A%5Bcsharp%5D%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%2F%2FCREATE%20AN%20FTP%20REQUEST%20WITH%20THE%20DOMAIN%20AND%20C" title="Digg"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fread-file-from-ftp-using-c%2F&amp;title=Read%20File%20From%20FTP%20Using%20C%23" title="StumbleUpon"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fread-file-from-ftp-using-c%2F&amp;title=Read%20File%20From%20FTP%20Using%20C%23&amp;notes=Here%20is%20a%20small%20snippet%20on%20reading%20a%20text%20file%20from%20an%20FTP%20server.%20%20This%20could%20be%20replaced%20with%20a%20binary%20file%20or%20any%20other%20type%3B%20I%20just%20used%20a%20text%20file%20to%20keep%20it%20simple.%0D%0A%0D%0ACode%0D%0A%0D%0A%5Bcsharp%5D%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20%2F%2FCREATE%20AN%20FTP%20REQUEST%20WITH%20THE%20DOMAIN%20AND%20C" title="del.icio.us"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://michael.chanceyjr.com/useful-code/read-file-from-ftp-using-c/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Interapplication Communication with Named Pipes</title>
		<link>http://michael.chanceyjr.com/useful-code/interapplication-communication-with-named-pipes/</link>
		<comments>http://michael.chanceyjr.com/useful-code/interapplication-communication-with-named-pipes/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 16:30:00 +0000</pubDate>
		<dc:creator>Michael E. Chancey Jr.</dc:creator>
				<category><![CDATA[Useful Code]]></category>
		<category><![CDATA[Application Communication]]></category>
		<category><![CDATA[Background Communication]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C-Sharp]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Named Pipes]]></category>
		<category><![CDATA[Stream]]></category>

		<guid isPermaLink="false">http://michael.chanceyjr.com/?p=506</guid>
		<description><![CDATA[Ever make two separate applications but need them to be able to send information back and forth. Say an Instant Messenger and a Business app which need direct integration between one another. Named pipes is a pretty simple solution to achieve this. .NET 3.5 has made this much simpler by including Named Pipes in its [...]]]></description>
			<content:encoded><![CDATA[<p>Ever make two separate applications but need them to be able to send information back and forth.  Say an Instant Messenger and a Business app which need direct integration between one another.  Named pipes is a pretty simple solution to achieve this.  .NET 3.5 has made this much simpler by including Named Pipes in its release, this used to be real nasty when trying to achieve this in any other language then C++.</p>
<h3>//Application</h3>
<hr/>
<pre class="brush: csharp;">
using System;
using System.IO;
using System.IO.Pipes;

class Program
{
    /// &lt;summary&gt;
    /// MAIN APPLICATION THREAD
    /// &lt;/summary&gt;
    /// &lt;param name=&quot;args&quot;&gt;NOTHING IS ACCEPTED HERE&lt;/param&gt;
    static void Main(string[] args)
    {
        //HOLDS THE SECLECTION A USER MAKES AS TO WHAT THEY WANT TO RUN
        string tmpSelection = string.Empty;

        //ASK THE USER WHAT THEY WANT TO DO
        Console.Write(&quot;Please Enter A Selection 1(Server) or 2(Client): &quot;);
        tmpSelection = Console.ReadLine();

        //CLEAR THE SCREEN AND BEGIN RUNNING THE USERS SELECTION
        Console.Clear();
        if (tmpSelection == &quot;1&quot;)
        {
            //START A PIPE SERVER
            pipeServer();
        }
        else if (tmpSelection == &quot;2&quot;)
        {
            //START A PIPE CLIENT
            pipeClient();
        }
        else
        {
            //LET THE USER KNOW THEY HAVE MADE AN INVALID SELECTION
            Console.WriteLine(&quot;Invalid selection made.  This app will now close.&quot;);
            Console.ReadLine();
        }
    }

    /// &lt;summary&gt;
    /// RUNS A PIPE CLIENT FOR SENDING MESSAGES
    /// &lt;/summary&gt;
    private static void pipeClient()
    {
        //LET THE USER KNOW WHAT IS GOING ON
        Console.WriteLine(&quot;Starting Client!&quot;);

        //LOOP FOREVER FOR TESTING PURPOSES
        while (true)
        {
            //CREATE A CONNECTION TO A NAMED PIPE ON THE LOCAL MACHINE NAMED testPipe
            using (NamedPipeClientStream tmpPipe = new NamedPipeClientStream(&quot;.&quot;, &quot;testPipe&quot;, PipeDirection.Out))
            {
                string tmpSendMessage;

                //GET SOME TEXT TO SEND THROUGH THE PIPE
                Console.Write(&quot;Enter Some Text To Send: &quot;);
                tmpSendMessage = Console.ReadLine();

                //SEND THE MESSAGE THROUGH THE PIPE
                tmpPipe.Connect();
                using (TextWriter tmpWriter = new StreamWriter(tmpPipe))
                {
                    tmpWriter.WriteLine(tmpSendMessage);
                }
            }
        }
    }

    /// &lt;summary&gt;
    /// RUNS A PIPE SERVER FOR ACCEPTING MESSAGES
    /// &lt;/summary&gt;
    private static void pipeServer()
    {
        //LET THE USER KNOW WHAT IS GOING ON
        Console.WriteLine(&quot;Starting Server!&quot;);

        //LOOP FOREVER FOR TESTING PURPOSES
        while (true)
        {
            //CREATE A NAMED PIPE ON THE LOCAL MACHINE NAMED testPipe
            using (NamedPipeServerStream tmpPipe = new NamedPipeServerStream(&quot;testPipe&quot;, PipeDirection.In))
            {
                //READ THE DATA ON THE PIPE
                tmpPipe.WaitForConnection();
                using (TextReader tmpReader = new StreamReader(tmpPipe))
                {
                    Console.WriteLine(tmpReader.ReadLine());
                }
            }
        }
    }
}
</pre>



Share


	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Interapplication%20Communication%20with%20Named%20Pipes%20-%20http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Finterapplication-communication-with-named-pipes%2F" title="Twitter"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Finterapplication-communication-with-named-pipes%2F&amp;title=Interapplication%20Communication%20with%20Named%20Pipes&amp;bodytext=Ever%20make%20two%20separate%20applications%20but%20need%20them%20to%20be%20able%20to%20send%20information%20back%20and%20forth.%20%20Say%20an%20Instant%20Messenger%20and%20a%20Business%20app%20which%20need%20direct%20integration%20between%20one%20another.%20%20Named%20pipes%20is%20a%20pretty%20simple%20solution%20to%20achieve%20this." title="Digg"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Finterapplication-communication-with-named-pipes%2F&amp;title=Interapplication%20Communication%20with%20Named%20Pipes" title="StumbleUpon"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Finterapplication-communication-with-named-pipes%2F&amp;title=Interapplication%20Communication%20with%20Named%20Pipes&amp;notes=Ever%20make%20two%20separate%20applications%20but%20need%20them%20to%20be%20able%20to%20send%20information%20back%20and%20forth.%20%20Say%20an%20Instant%20Messenger%20and%20a%20Business%20app%20which%20need%20direct%20integration%20between%20one%20another.%20%20Named%20pipes%20is%20a%20pretty%20simple%20solution%20to%20achieve%20this." title="del.icio.us"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://michael.chanceyjr.com/useful-code/interapplication-communication-with-named-pipes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Compress and UnCompress Stream Extension</title>
		<link>http://michael.chanceyjr.com/useful-code/compress-and-uncompress-stream-extension/</link>
		<comments>http://michael.chanceyjr.com/useful-code/compress-and-uncompress-stream-extension/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 06:53:57 +0000</pubDate>
		<dc:creator>Michael E. Chancey Jr.</dc:creator>
				<category><![CDATA[Useful Code]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C-Sharp]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Extension]]></category>
		<category><![CDATA[Stream]]></category>

		<guid isPermaLink="false">http://michael.chanceyjr.com/site/?p=395</guid>
		<description><![CDATA[/// &#60;summary&#62; /// READS FROM SOURCE STREAM AND WRITES COMPRESSED VERSION TO THE DEST STREAM /// &#60;/summary&#62; /// &#60;param name=&#34;src&#34;&#62;SOURCE STREAM TO COMPRESS&#60;/param&#62; /// &#60;param name=&#34;dest&#34;&#62;DEST OF COMPRESSED STREAM&#60;/param&#62; public static void Compress(this Stream src, Stream dest) { //CREATE A COMPRESSING GZIP STREAM using(GZipStream tmpCompressor = new GZipStream(dest, CompressionMode.Compress)) { int count; byte[] buffer = [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush: csharp;">
        /// &lt;summary&gt;
        /// READS FROM SOURCE STREAM AND WRITES COMPRESSED VERSION TO THE DEST STREAM
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;src&quot;&gt;SOURCE STREAM TO COMPRESS&lt;/param&gt;
        /// &lt;param name=&quot;dest&quot;&gt;DEST OF COMPRESSED STREAM&lt;/param&gt;
        public static void Compress(this Stream src, Stream dest)
        {
            //CREATE A COMPRESSING GZIP STREAM
            using(GZipStream tmpCompressor = new GZipStream(dest, CompressionMode.Compress))
            {
                int count;
                byte[] buffer = new byte[1024];

                //WHILE WE ARE STILL ABLE TO READ BYTES FROM THE SOURCE WRITE THEM TO THE DEST
                while ((count = src.Read(buffer, 0, buffer.Length)) != 0)
                {
                    tmpCompressor.Write(buffer, 0, count);
                }

                //FLUSH THE STREAM SO ALL DATA IS MOVED INTO THE STREAM
                tmpCompressor.Flush();
            }
        }

        /// &lt;summary&gt;
        /// READS COMPRESSED SOURCE STREAM AND WRITES UNCOMPRESSED VERSION TO THE DEST STREAM
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;src&quot;&gt;SOURCE OF COMPRESSED STREAM&lt;/param&gt;
        /// &lt;param name=&quot;dest&quot;&gt;DEST OF UNCOMPRESSED STREAM&lt;/param&gt;
        public static void Uncompress(this Stream src, Stream dest)
        {
            //CREATE A DECOMPRESSING GZIP STREAM
            using (GZipStream tmpDecompressor = new GZipStream(src, CompressionMode.Decompress))
            {
                int count;
                byte[] buffer = new byte[1024];

                //WHILE WE ARE STILL ABLE TO READ BYTES FROM THE SOURCE WRITE THEM TO THE DEST
                while ((count = tmpDecompressor.Read(buffer, 0, buffer.Length)) != 0)
                {
                    dest.Write(buffer, 0, count);
                }

                //FLUSH THE STREAM SO ALL DATA IS MOVED INTO THE STREAM
                dest.Flush();
            }
        }
</pre>



Share


	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Compress%20and%20UnCompress%20Stream%20Extension%20-%20http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fcompress-and-uncompress-stream-extension%2F" title="Twitter"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fcompress-and-uncompress-stream-extension%2F&amp;title=Compress%20and%20UnCompress%20Stream%20Extension&amp;bodytext=%5Bcsharp%5D%0D%0A%20%20%20%20%20%20%20%20%2F%2F%2F%20%26lt%3Bsummary%26gt%3B%0D%0A%20%20%20%20%20%20%20%20%2F%2F%2F%20READS%20FROM%20SOURCE%20STREAM%20AND%20WRITES%20COMPRESSED%20VERSION%20TO%20THE%20DEST%20STREAM%0D%0A%20%20%20%20%20%20%20%20%2F%2F%2F%20%26lt%3B%2Fsummary%26gt%3B%0D%0A%20%20%20%20%20%20%20%20%2F%2F%2F%20%26lt%3Bparam%20name%3D%26quot%3Bsrc%26quot%3B%26gt%3BSOURCE%20STREAM%20TO%20COMPRESS%26lt%3B%2Fparam%26gt%3B%0D%0A%20%20%20%20%20%20%20" title="Digg"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fcompress-and-uncompress-stream-extension%2F&amp;title=Compress%20and%20UnCompress%20Stream%20Extension" title="StumbleUpon"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fcompress-and-uncompress-stream-extension%2F&amp;title=Compress%20and%20UnCompress%20Stream%20Extension&amp;notes=%5Bcsharp%5D%0D%0A%20%20%20%20%20%20%20%20%2F%2F%2F%20%26lt%3Bsummary%26gt%3B%0D%0A%20%20%20%20%20%20%20%20%2F%2F%2F%20READS%20FROM%20SOURCE%20STREAM%20AND%20WRITES%20COMPRESSED%20VERSION%20TO%20THE%20DEST%20STREAM%0D%0A%20%20%20%20%20%20%20%20%2F%2F%2F%20%26lt%3B%2Fsummary%26gt%3B%0D%0A%20%20%20%20%20%20%20%20%2F%2F%2F%20%26lt%3Bparam%20name%3D%26quot%3Bsrc%26quot%3B%26gt%3BSOURCE%20STREAM%20TO%20COMPRESS%26lt%3B%2Fparam%26gt%3B%0D%0A%20%20%20%20%20%20%20" title="del.icio.us"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://michael.chanceyjr.com/useful-code/compress-and-uncompress-stream-extension/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MD5 Stream Extension</title>
		<link>http://michael.chanceyjr.com/useful-code/md5-stream-extension/</link>
		<comments>http://michael.chanceyjr.com/useful-code/md5-stream-extension/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 06:52:52 +0000</pubDate>
		<dc:creator>Michael E. Chancey Jr.</dc:creator>
				<category><![CDATA[Useful Code]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C-Sharp]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Extension]]></category>
		<category><![CDATA[Stream]]></category>

		<guid isPermaLink="false">http://michael.chanceyjr.com/site/?p=392</guid>
		<description><![CDATA[/// &#60;summary&#62; /// COMPUTE THE HASH VALUE OF THE FILE STREAM /// &#60;/summary&#62; /// &#60;param name=&#34;s&#34;&#62;STREAM TO COMPUTE THE VALUE OF&#60;/param&#62; /// &#60;param name=&#34;closeStream&#34;&#62;BOOLEAN TO DETERMINE IF THE STREAM SHOULD BE CLOSED UPON EXIT&#60;/param&#62; /// &#60;returns&#62;RETURNS AN MD5 HASH OF THE FILE&#60;/returns&#62; public static string ComputeMD5(this Stream s, bool closeStream) { try { //SEEK TO [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush: csharp;">
        /// &lt;summary&gt;
        /// COMPUTE THE HASH VALUE OF THE FILE STREAM
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;s&quot;&gt;STREAM TO COMPUTE THE VALUE OF&lt;/param&gt;
        /// &lt;param name=&quot;closeStream&quot;&gt;BOOLEAN TO DETERMINE IF THE STREAM SHOULD BE CLOSED UPON EXIT&lt;/param&gt;
        /// &lt;returns&gt;RETURNS AN MD5 HASH OF THE FILE&lt;/returns&gt;
        public static string ComputeMD5(this Stream s, bool closeStream)
        {
            try
            {
                //SEEK TO THE BEGINING OF THE STREAM
                s.Seek(0, SeekOrigin.Begin);

                //CREATE AN MD5 AND COMPUTE THE HASH VALUE
                return BitConverter.ToString(MD5.Create().ComputeHash(s)).Replace(&quot;-&quot;, &quot;&quot;);
            }
            catch
            {
                //THROW AN ERROR BECAUSE WE WERE UNABLE TO SEEK IN THE FILE OR POSSIBLY READ
                throw new ArgumentException(&quot;Invalid stream, must be able to seek and read.&quot;);
            }
            finally
            {
                //IF WE ARE SUPPOSED TO CLOSE THE STREAM WHEN WE ARE DONE THEN DO SO
                if (closeStream)
                    s.Close();
            }

        }
</pre>



Share


	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=MD5%20Stream%20Extension%20-%20http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fmd5-stream-extension%2F" title="Twitter"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fmd5-stream-extension%2F&amp;title=MD5%20Stream%20Extension&amp;bodytext=%5Bcsharp%5D%0D%0A%20%20%20%20%20%20%20%20%2F%2F%2F%20%26lt%3Bsummary%26gt%3B%0D%0A%20%20%20%20%20%20%20%20%2F%2F%2F%20COMPUTE%20THE%20HASH%20VALUE%20OF%20THE%20FILE%20STREAM%0D%0A%20%20%20%20%20%20%20%20%2F%2F%2F%20%26lt%3B%2Fsummary%26gt%3B%0D%0A%20%20%20%20%20%20%20%20%2F%2F%2F%20%26lt%3Bparam%20name%3D%26quot%3Bs%26quot%3B%26gt%3BSTREAM%20TO%20COMPUTE%20THE%20VALUE%20OF%26lt%3B%2Fparam%26gt%3B%0D%0A%20%20%20%20%20%20%20%20%2F%2F%2F%20%26lt%3Bparam%20name%3D%26quot%3Bclo" title="Digg"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fmd5-stream-extension%2F&amp;title=MD5%20Stream%20Extension" title="StumbleUpon"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fmichael.chanceyjr.com%2Fuseful-code%2Fmd5-stream-extension%2F&amp;title=MD5%20Stream%20Extension&amp;notes=%5Bcsharp%5D%0D%0A%20%20%20%20%20%20%20%20%2F%2F%2F%20%26lt%3Bsummary%26gt%3B%0D%0A%20%20%20%20%20%20%20%20%2F%2F%2F%20COMPUTE%20THE%20HASH%20VALUE%20OF%20THE%20FILE%20STREAM%0D%0A%20%20%20%20%20%20%20%20%2F%2F%2F%20%26lt%3B%2Fsummary%26gt%3B%0D%0A%20%20%20%20%20%20%20%20%2F%2F%2F%20%26lt%3Bparam%20name%3D%26quot%3Bs%26quot%3B%26gt%3BSTREAM%20TO%20COMPUTE%20THE%20VALUE%20OF%26lt%3B%2Fparam%26gt%3B%0D%0A%20%20%20%20%20%20%20%20%2F%2F%2F%20%26lt%3Bparam%20name%3D%26quot%3Bclo" title="del.icio.us"><img src="http://michael.chanceyjr.com/site/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://michael.chanceyjr.com/useful-code/md5-stream-extension/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

