The title pretty much states it.
Is there a way for me to unzip .tbz files in C#? Either using a third party library or just using normal libs to unzip .tbz files?
A tbz file is a tar + bzip2 compression archive.
You can try this open source library.
#ziplib (SharpZipLib, formerly NZipLib) is a Zip, GZip, Tar and BZip2
library written entirely in C# for the
.NET platform.
Related
I am currently working on converting .JPEG file to .WSQ file, I have successfully done it in Java using a library from http://sourceforge.net/projects/jmrtd/.
Now I wanted to do the same thing in C#, I converted the .jar files into .dll files using IKVM and I can call the libraries of Java in my C# application. But there is a problem, in Java, I found out that the function to convert JPEG to WSQ is available in the external library which is added as an external SPI from the META-INF/service folder. Something like http://docs.oracle.com/javase/tutorial/sound/SPI-intro.html.
The external library is called "indirectly" in Java from what I understand, how can I do this in C#? Is this even possible?
If the "external library" a second jar file then compile both jar files in one step with the parenthesis syntax. Then it should work.
For details see the IKVM wiki:
Convert a jar file to a dll and use it as library
ClassLoader
Microsoft introduces improvements for ZIP file handling in .NET 4.5 in the System.IO.Compression namespace. Namely the classes ZipArchive and ZipFile.
However, I have not yet seen a way to use native .NET ZIP file handling for password protected files. Is there a way to achieve this? (I am aware that there are pretty good 3rd party zip file libraries, that is not the question.)
Unfortunately not. There is no support within the .Net Framework 4.5 for password protected zip files. In this case you have to switch to one of the well known 3rd party libraries.
As pointed out, DotNetZip is your friend. Unpacking your zip file is as easy as
using ( ZipFile archive = new ZipFile( #"c:\path\to\your\password\protected\archive.zip",) )
{
archive.Password = "your-pass-word-here" ;
archive.Encryption = EncryptionAlgorithm.PkzipWeak ; // the default: you might need to select the proper value here
archive.StatusMessageTextWriter = Console.Out;
archive.ExtractAll( #"c:\path\to\unzip\directory\", ExtractExistingFileAction.Throw ) ;
}
In my experience, DotNetZip runs about as fast as Info-Zip's open source unzip utility and uses roughly the same amount of memory.
Edited To Note: DotNetZip used to live at Codeplex. Codeplex has been shut down. The old archive is still available at Codeplex. It looks like the code has migrated to Github:
https://github.com/DinoChiesa/DotNetZip. Looks to be the original author's repo.
https://github.com/haf/DotNetZip.Semverd. This looks to be the currently maintained version. It's also packaged up an available via Nuget at https://www.nuget.org/packages/DotNetZip/
The ionic method is awesome. I tried three other approaches, and it is by far the best. Don't waste time, just use it.
https://dotnetzip.codeplex.com/wikipage?title=PS-Examples
Supports password encrypted, and other zip options.
In looking at the methods provided by the 4.5 framework there is not a method that allows passwords with zip files. As mentioned in your question 3rd party is going to be your best bet.
There does not appear to be any support for password protected zip files in the native .net 4.5 library, similar to how there does not appear to be support in windows explorer, even with Windows 10!
Some people have reported that they have zip corruption issues using the 3rd party DotNetLib, so make sure you extensively test if you do go down that path or try SharpZipLib instead.
For those targeting .Net Standard 2.0, SharpZipLib does a great work, handling gracefully extraction of in memory password protected zip files to byte[].
https://github.com/icsharpcode/SharpZipLib
Tried Ionic for the same scenario but was enable to extract files with the ZipInputStream, which generated corrupt extracted byte arrays.
I found the way is very simple to unzip in c#
Install PM (you can find new version if available!)
Install-Package Ionic.Zip -Version 1.9.1.8
Code C#
string zipFile = #"C:\Users\Fesslersoft\Desktop\ZipTest\Test.zip";
string targetDirectory = #"C:\Users\Fesslersoft\Desktop\ZipTest\";
using (Ionic.Zip.ZipFile zip = Ionic.Zip.ZipFile.Read(zipFile))
{
zip.Password = "1234";
zip.ExtractAll(targetDirectory, Ionic.Zip.ExtractExistingFileAction.DoNotOverwrite);
}
Console.WriteLine("Zip file has been successfully extracted.");
Console.Read();
Source: https://codesnippets.fesslersoft.de/extract-a-password-protected-zip-file-using-dotnetzip/
I'm new to c# and programming in general. I've started to create my own powerpoint plugin. I've got it to where a user can browse for a zip file but now I need to know - How do I parse information from a file within that zip or compound file in c#?
Do I have to use a library? If so how do I go about that?
As others have mentioned, the System.IO.Compression namespace has the ZipFile class for creating/extracting zip files. However, they are only available in .NET 4.5 however, which is currently only available as part of the Visual Studio 2012 RC.
See System.IO.Compression in:
.NET 4
.NET 4.5
Up until this point, the de-facto standard for working with zip files in .NET has been the DotNetZip Library. It is available under the open-source MS-PL license.
Also see:
Handling Zip Files Without Third Party Lib in .NET 4.0?
To work with ZIP-files in general, use the ZipArchive class that represents a ZIP file, or the members of the static ZipFile class to work with ZIP files, and use the DeflateStream class to read the contents of a compressed file.
To easily read the contents of a binary file, use the BinaryReader class. Otherwise, use the StreamReader class for text files.
I used apktool to extract an APK file contents. But for some reasons I need such a tool written in .NET so I do not need to install the JDK in the server.
Is there such a tool?
No. There is no such a tool. You need to start a Process in C# and run the batch file with the arguments using ProcessStartInfo class
I think in another approach, take the APK file and create a Java program that extracts the info I need such as package name, icon resource etc... and then expose it as COM object and use it in my .NET project.
After deep research we can not extract that info in standard functions in Java, since the only way to extract the info is to unzip the APK via the APKTool and read the manifest from the file system.
Another way but hard is to write your own extractor which involves in deep knowledge in the format of the APK.
Im looking for an example of how to decompress a bz2 file. I download the file via a control flow in an SSIS package, I would like to kick off a Script Task using some C# code to decompress the downloaded bz2 file. It doesn't seem that the decompression library that comes with .net handles bz2 files. Could someone show me an implimentation that could? or direct me to an example of decompressing a bz2 file to a specified folder?
SharpZipLib is what you're looking for.
#ziplib (SharpZipLib, formerly NZipLib) is a Zip, GZip, Tar and BZip2 library written entirely in C# for the .NET platform.
7-zip comes with bzip2 support (and many many more formats) and a C# wrapper.