Click here to Skip to main content
15,886,012 members
Articles / Desktop Programming / WPF

Zip My Code

Rate me:
Please Sign up or sign in to vote.
4.78/5 (17 votes)
20 Dec 2009CPOL3 min read 71.6K   2K   48  
A utility stripping your source code to the essential core and then compressing it to a nice CodeProject article attachment.
		if(data == null) return null;
		MemoryStream ins = null;
		MemoryStream outs = null;
		InflaterInputStream iis = null;
		try{
			ins = new MemoryStream(data);
			outs = new MemoryStream();
			iis = new InflaterInputStream(ins);
			byte[] buff = new byte[data.Length];
			while(true)
			{
				int r = iis.Read(buff, 0, buff.Length);
				if(r <= 0) break;
				outs.Write(buff, 0, r);
			}
			outs.Flush();
			outs.Seek(0, SeekOrigin.Begin);
		}
		finally
		{
			if(ins != null) ins.Close();
			if(iis != null) iis.Close();
			ins = null;
			iis = null;
		}
		return outs;

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Axis Communications
Sweden Sweden
Got my first computer in the 90's and loved it even though it sounded like a coffeemaker.

Now getting paid for designing cool applications, and drinks the coffee instead of listening to it being made.

Comments and Discussions