Exploring the CodeFluent Runtime: ZipFile
Since the day it was born, the CodeFluent Entities Runtime embarks a cool ZipFile class that allows you to create .ZIP files from other files, directories and streams, and extract from .ZIP files files, directories of files and streams!
The class is found in the CodeFluent.Runtime.Compression namespace and is very easy to use:
using CodeFluent.Runtime.Compression;
namespace ZipTest
{
class Program
{
static void Main(string[] args)
{
// compress
using (ZipFile file = new ZipFile("newzip.zip", ZipFile.Mode.Overwrite))
{
file.AddFile(myFile1);
file.AddFile(myFile2);
file.AddDirectory(myDirectory); // recursive, keep relative paths in
}
// decompress
using (ZipFile file = new ZipFile("newzip.zip", ZipFile.Mode.Read))
{
file.GetFiles(myOutputDirectory); // recursive, keep relative paths out
}
}
}
}
For CPU performance and memory usage reasons, and contrary to other popular .NET zip implementations (http://www.icsharpcode.net/opensource/sharpziplib/, or http://dotnetzip.codeplex.com/), CodeFluent Entities’ ZipFile implementation is unmanaged.
It means you will have to copy a native Windows DLL (that is shipped with the product) named “CodeFluent.Runtime.Compression.dll” in the bin directory of your application for this to work. Since it’s unmanaged, there are two versions of this dll, one for X86 processes, and another for X64 processes.
It’s fun to see Microsoft has finally taken the same unmanaged route for ZIP handling, this year, in 2012, as we did 7 years ago, when we shipped our first version of CodeFluent Entities
The CodeFluent Runtime is available in two flavors:
- With the full CodeFluent Entities product.
- With the CodeFluent Runtime Client 100% free assembly. This one is available directly from Nuget.
Happy zip-ing!
The R&D team.