Daniel's profileDevoted to technologyBlogLists Tools Help

Blog


    February 26

    ZIP support for .Net

    Hello,
     
    Some time ago I complained that .NET 3.0 ZipArchive class implementation is just so imperfect that it cannot be used with regular zip files.
    That's true. It's designed to support zip based document files like XPS or Office documents. It has to cover special structure inside.
    With that understanding it can be even usable but if you're looking for real 100% zip file compression support for .NET you can go there:
     
     
    and check the component. It's free for non-commercial use so you can evaluate it freely :)
    January 20

    .NET 3.0 gives an illusion of ZIP file support

    Hello again,
     
    Last evening I wasted about 3-4h just to figure out all the details how ZipPackage class in System.IO.Packaging works.
    It comes with .NET 3.0 installed if you add refference for WindowsBase.dll component.
     
    I've made some code.. Initially it has no easy structure like
     
    ZipPackage -> Folders -> Files
     
    Where you could create zip file by some pseudocode like below:
     
    ZipPackage package = new ZipPackage("testPackage.zip",ZipMode.Create,ZipCompression.Maximum);
    package.Folders.Add("MyFolder");
    package.Folders["MyFolder"].AddFile("someFile.txt");
     
    package.Close();
     
    and read in very similar intuitive way.
     
    No.. you have many strange names like Relationships parts, you have to take care about your URI's to put files correctly into the package
    Then Finally you have to know each file MIME..
     
    Lot of strange moves in your code where finally you can write and read ZIP files as you'd really like.
     
    What then? you'll see that this packaging has mimimal effectiveness in context of compression.
     
    It's damn much easier still to make a compression on yourself basing on Deflate and Gzip Streams from System.IO.Compression still I say.
    And compression ratio will be similar I believe.
     
    I haven't tested much handler based on these routines to compare but meantime I found nice articles that defends my theory:
     
     
    Not good. Looks like that ZipPackage is only to help support XPS and Office documents which are ZIPs trully as highly specialized handler not for general use.
     
    If you're still interested there is nice Polish language based presentation from Microsoft Technology Summit 2006 which can explain how to use these terms "parts" and "relationships" fluently in context of new Office (2007) document files which are ZIPs indeed:
     
     
    Of course as always, there is commercial alternative if you don't want to code everything by yourself:
     
     
    Still checking other alternatives and scenarios.