Content inside zip file - c#

how to use zippackage class to know about the content in .zip file?
for ex to know the type of file inside this zip file.

Once you open the .zip file, you can use the GetParts method to get a collection of all the files inside the .zip. See the PackagePart class.

http://sharpdevelop.net/OpenSource/SharpZipLib/ is a good zip library for CSharp.
Although, you might just want to use something like the DeflateStream class (http://msdn.microsoft.com/en-us/library/system.io.compression.deflatestream.aspx) which provides a compressed stream and doesn't require dealing with the complexities of an archive that handles multiple files.

Related

Unpacking tar/BZ2 files using C#

I have a tar.bz2 file and I want to extract it to a directory. In the examples I only see option of compress or decompress however I want actually to extract or unpack.
Also tried ICSharpCode.SharpZipLib.BZip2 but I didn't find an option to unpack.
While you use a ZipInputStream for .zip files, you should use a BZip2InputStream for .bz2 files (and GZipInputStream for .gz files etc.).
Taken from:
How to decompress .bz2 file in C#?
Decompressing and unpacking are two different operations. A foo.tar.bz2 file is actually a foo.tar file which was then compressed using bz2.
So to get single files you have to do this in the opposite direction. I.e. first decompress it (which you managed to do with sharpziplib). The result of this decompression has then to be untared (which can also be done with sharpziplib) see the docs for details.

Stream dynamic zip files with resume support

Suppose, I have a list of MP3 files on my server. And I want a user to download multiple files (which he wants through any means). For, this what i want is to create the zip file dynamically and while saving it into the Output Stream using the dotnetzip or ioniczip libraries.
Well, that's not the perfect solution if the zip file got heavy in size. As, in that scenario the server doesn't support resumable downloads. So, to overcome this approach, I need to handle the zip file structure internally and provide the resume support.
So, is there any library (open source) which i can use to provide resumable dyanamic zip files stream directly to the Output Stream. Or, if possible I will be happy if someone let me know the structure of zip file specially the header content + data content.
Once a download has started, you should not alter the ZIP file anymore. Because then a resume will just result in a broken ZIP file. So make sure your dynamically created ZIP file stays available!
The issue of providing resume-functionality was solved in this article for .NET 1.1, and it is still valid and functional.

How to read and edit an xml file inside a zip without extracting

I need to read, modify and then write from/to an xml file in a zip I need to do this for lots if files as the xml is kind of an index for what the zip is for.
Saxon 9.5 implements the EXPath ZIP file extensions: take a look, it might do what you need.

How can I extract a multi-volume zip file using SharpZipLib in C#?

I have a single file, Setup1.cab, which is split up into Setup1.zip.001 and Setup1.zip.002 that I used 7zip to archive. Once those volumes reach their destination, I'd like to be able to use C# to extract that file from both archives into the same directory where they will reside. Is this something that SharpZipLib is capable of, or should I be using another tool?
Otherwise, is there a way to combine the two using C# (or another tool - I'm open!) into one zip file, THEN extract it using SharpZipLib?
Thanks!
EDIT: 7zip will not be installed on the destination machines. Also, I'm open to using a different method of archiving the original file; I just need it to be in chunks of under 500MB, and the original file is 570MB.
I would take a look at the SevenZipSharp library and actually use 7zip via C# to handle the decompression.

How to compress a directory into a zip file programmatically

I want to compress an entire directory which can have any number of subdirectories into a single ZIP file.
I am able to compress a single file into a zip file programmatically.
To compress an entire directory, i can think of a recursive program that walks through each subdirectory and compresses it.
But Is there any simple way to compress the entire folder using the similar code, without having to write any recursive functions?
Using DotNetZip, there's an AddDirectory() method on the ZipFile class that does what you want:
using (var zip = new Ionic.Zip.ZipFile())
{
zip.AddDirectory("DirectoryOnDisk", "rootInZipFile");
zip.Save("MyFile.zip");
}
This example, and many others, are available on codeplex.
Take a look at one of these API's:
DotNetZip
SharpZipLib
ZipFile.CreateFromDirectory(<path of folder you need to zip>, <path of zip file with .zip in the end>, CompressionLevel.Fastest, true);
You can see Article about Zip / Unzip folders and files with C#.

Categories