| Shreeman's profileShreemanBlogLists | Help |
|
March 28 Compression and Zip Support in .NET:-This is not a new functionality and you might alreday be using one or the other version of tools and code for providing this functionalities in your application.However if you think for using a Zip component in a Enterprise Application for production environment most probably you are using some thirdparty library and/or tools to support these functionalities.
In this post I ll try to Cover both Data as well as File Compression tools as well as what all approaches and techniques and tools avaialble for you to build one out of the box in the .NET framework itself.So to start with When I saw the System.IO.compression available in the .NET framework 2.0 my initial thought was that it supprot out of box compression for both Data and Files but I was Wrong and although you can now compress your data there was no out of box support for file compression although you can ship one with your own.Further to that be remember that the .Zip compression format is owned by PKZip and thus you don't have it available out of box .Something similar to the PDF for ADOBE until the openxml comes into the picture with the Office 07.
Without much writing into the historical piece let me dive directly into the topic itself:-What all approaches you have in the framework to provide FileCompression:- IO.Compression,CAB and SHell Api and using J# library using any of these you can provide functionlity to Zip a file but to implement A recursive Folder Routine into .ZIP is still distant and the Compression ratio is also debatable that is why most of the Enterprise App falls into the Thirdparty .However Saying so does not restrict you to bundle your data stream in a Compressed format or your compresssed your fiel and you are always welcome and hookup your own data.Further to a few sample linbe of codes I ll also provide quite a few useful links so that you can take this forward.
Now to use the System.IO you might code something like the following:-
using System.IO.Compression;
using System.IO;
private static void Compress(Stream source, Stream destination)
{
using(GZipStream output = new GZipStream(destination, CompressionMode.Compress))
{
Pump(source, output);
}
}
private static void Decompress(Stream source, Stream destination)
{
using(GZipStream input = new GZipStream(source, CompressionMode.Decompress))
{
Pump(input, destination);
}
}
private static void Pump(Stream input, Stream output)
{
byte[] bytes = new byte[4096];
int n;
while((n = input.Read(bytes, 0, bytes.Length)) != 0)
{
output.Write(bytes, 0, n);
}
}
OR you might use something like :-
private static void compress()
{
FileStream inputFile = null;
GZipStream compressedZipStream = null;
try
{
// Open and read the contents of the file
inputFile = new FileStream(@"filepath to zip", FileMode.Open,
FileAccess.Read, FileShare.Read);
byte[] buffer = new byte[inputFile.Length];
int count = inputFile.Read(buffer, 0, buffer.Length);
inputFile.Close();
MemoryStream memoryBuffer = new MemoryStream();
compressedZipStream = new GZipStream(memoryBuffer,
CompressionMode.Compress, true);
compressedZipStream.Write(buffer, 0, buffer.Length);
compressedZipStream.Close();
FileStream str=File.Open(@"Compressed File path",FileMode.OpenOrCreate);
str.Write(buffer,0,buffer.Length);
str.Close();
}
finally
{
if (inputFile != null) inputFile.Close();
if (compressedZipStream!= null) compressedZipStream.Close();
}
}
Here are few links covering different approaches for this:- Using GZipStream for Compression in .NET [Brian Grunkemeyer] http://blogs.msdn.com/bclteam/archive/2005/06/15/429542.aspx
Compression Classes Enhance I/O in .NET 2.0 http://www.developer.com/net/net/article.php/11087_3510026_1
Using Data Compression in .NET 2.0 http://www.windowsdevcenter.com/pub/a/windows/2006/09/12/using-data-compression-in-net-20.html?page=1
Compression support in ASP.NET 2.0 http://www.microsoft.com/belux/msdn/nl/community/columns/desmet/compression.mspx>
NET System.IO.Compression and zip files http://blogs.msdn.com/dotnetinterop/archive/2006/04/05/.NET-System.IO.Compression-and-zip-files.aspx
Cabinet File (*.CAB) Compression and Extraction By Elmue http://www.codeproject.com/cs/files/CABCompressExtract.asp
Using J# Library http://msdn.microsoft.com/msdnmag/issues/03/06/ZipCompression/
3.0 ZipPackage Class http://msdn2.microsoft.com/en-us/library/system.io.packaging.zippackage.aspx
Dfaltestream class http://msdn2.microsoft.com/en-us/library/system.io.compression.deflatestream.aspx
Compress Using ShellApi http://geraldgibson.net/dnn/Home/CZipFileCompression/tabid/148/Default.aspx
DeCompress Using ShellApi http://geraldgibson.net/dnn/Home/CZipFileDecompression/tabid/149/Default.aspx
There are many third-party library available and the one I have pointed above are due to the fact that I involved with those during different project implementations.One final Word is that the IO compression Classes were not meant for the File Compression and .Zip is not the extn due to the legal requirements. Ok Now that I have mentioned few lines for the Compression there are other related story which I want to separate from the Stream Compression like MTOM,HTTP compression Support in IIS which were more specific to ASP.NET & WebSvc Scenario.If you are looking for the guidelines and more into this side of the story do checkout the following:- Yasser moving lots of data http://blogs.msdn.com/yassers/archive/2006/01/21/515887.aspx
A study of compression and SOAP http://mercury.it.swin.edu.au/ctg/AWSA05/Papers/ng.pdf
WSFile utility http://training.franklins.net/dotnet.aspx
Roman kiss DIme Bridge http://www.codeproject.com/cs/webservices/DIMEBridge.asp
I ll update this post later with more info on the compression including the Zip,Data Compression,File Compression,SOAP and HTTP comression.For the time being I hope that these will provide a quick start and guidance. March 27 The Silence is Over:-Back to BloggingOk..Here you go ..the silence is over ...I was not blogging for past few days due to hectic schedule and travel programme..but not to waste much of the time and let me first try to update on the what and how happens on tech world during this time as well as provide few resources and starts blogging in full speed.Here you go
2006 Tech Ed06 Hols :- http://blogs.msdn.com/charles_sterling/archive/2006/09/05/740899.aspx
BPEL for work flows http://www.microsoft.com/downloads/details.aspx?FamilyID=6D0DAF00-F689-4E61-88E6-CBE6F668E6A3&displaylang=en
training kit for wcf,wf,cardspace http://www.netfx3.com/files/folders/6957/download.aspx
oracle and .net http://cshay.blogspot.com/
ssps site with dual Auth http://www.andrewconnell.com/blog/articles/HowToConfigPublishingSiteWithDualAuthProvidersAndAnonAccess.aspx
Online index sql05 http://download.microsoft.com/download/8/5/e/85eea4fa-b3bb-4426-97d0-7f7151b2011c/OnlineIndex.doc
March CTP of Orcas http://www.microsoft.com/downloads/details.aspx?familyid=cf76fcba-07af-47ac-8822-4ad346210670&displaylang=en Ent Lib 3.0 CTP http://www.codeplex.com/entlib
p&p perf testing http://www.codeplex.com/perftesting
Workflow for ssps virtual labs http://msevents.microsoft.com/cui/webcasteventdetails.aspx?eventid=1032304181&eventcategory=3&culture=en-us&countrycode=us
Download the MOSS SDK: http://www.microsoft.com/downloads/details.aspx?familyid=6D94E307-67D9-41AC-B2D6-0074D6286FA9&displaylang=en
Download the WSS SDK: http://www.microsoft.com/downloads/details.aspx?familyid=05e0dd12-8394-402b-8936-a07fe8afaffd&displaylang=en
SSPS best practice analyzer http://www.microsoft.com/downloads/details.aspx?familyid=cb944b27-9d6b-4a1f-b3e1-778efda07df8&displaylang=en
Active Directory screencasts http://channel9.msdn.com/ShowPost.aspx?PostID=130700
IIS7 quick videos http://news.zdnet.com/2036-11363_22-6153496.html
|
|
|