Recommendations on a free library to be used for zipping files
UPDATE 2020: There are other choices now, notably Zip4J.
After much searching, I've found three approaches:
A freely available set of source code, suitable for a single file zip. However, there is no license. Usage is AesZipOutputStream.zipAndEcrypt(...).
http://merkert.de/de/info/zipaes/src.zip
(https://forums.oracle.com/forums/thread.jspa?threadID=1526137)
UPDATE: This code is now Apache licensed and released at https://github.com/mobsandgeeks/winzipaes (exported from original home at Google code) . It worked for me (one file in the zip), and fills a hole in Java's opens source libraries nicely.
A commercial product ($500 at the time of writing). I can't verify if this works, as their trial license approach is complex. Its also a ported .NET app:
http://www.nsoftware.com/ipworks/zip/default.aspx
A commercial product ($290 at the time of writing). Suitable only for Wnidows as it uses a dll:
http://www.example-code.com/java/zip.asp
What is a good Java library to zip/unzip files?
I know its late and there are lots of answers but this zip4j is one of the best libraries for zipping I have used. Its simple (no boiler code) and can easily handle password protected files.
import net.lingala.zip4j.exception.ZipException;
import net.lingala.zip4j.core.ZipFile;
public static void unzip(){
String source = "some/compressed/file.zip";
String destination = "some/destination/folder";
String password = "password";
try {
ZipFile zipFile = new ZipFile(source);
if (zipFile.isEncrypted()) {
zipFile.setPassword(password);
}
zipFile.extractAll(destination);
} catch (ZipException e) {
e.printStackTrace();
}
}
The Maven dependency is:
<dependency>
<groupId>net.lingala.zip4j</groupId>
<artifactId>zip4j</artifactId>
<version>1.3.2</version>
</dependency>
Suggestions for a cheap/free .NET library for doing Zip with AES encryption?
How much would you be willing to pay for AES in DotNetZip?
;)
DotNetZip supports AES Encryption, with 128 or 256-bit keys.
http://www.codeplex.com/DotNetZip
Example code:
using (ZipFile zip = new ZipFile())
{
zip.AddFile("ReadMe.txt"); // no password for this entry
// use a password for subsequent entries
zip.Password= "This.Encryption.is.FIPS.197.Compliant!";
zip.Encryption= EncryptionAlgorithm.WinZipAes256;
zip.AddFile("Rawdata-2008-12-18.csv");
zip.Save("Backup-AES-Encrypted.zip");
}
The AES-encrypted zip files produced by DotNetZip can be read and extracted by WinZip, and vice-versa.
You can also just create regular zip files without encryption.
oh, and it's free.
Which zipping library should I use to properly assemble a valid XLSX file in Objective-C?
I found the answer upon doing some research and also having a one to one correspondence with Objective-Zip's developer, flyingdolphinstudio.
First of all, Objective-Zip uses DEFLATE as the default compression method. I also confirmed this with the developer, who told me that using ZipCompressionLevelDefault
, ZipCompressionLevelFastest
or ZipCompressionLevelBest
for the argument compressionLevel:
will guarantee a DEFLATE compression.
So, the problem is coming from the mode:
argument, which is ZipFileModeAppend
in my case. It seems that MiniZip does not have a method to delete the files inside a zip file and that's why I am not overwriting the existing file, but adding a new one. To make it more clear, take a look at how my xl/worksheets
folder look like after zipping it using Objective-Zip:
So, the only way to create a valid XLSX container is to create the zip file from scratch, by adding all the files and also keeping the directory/file structure intact.
I hope this experience would help somebody out.
java library to work with Zip files
A library for doing the hard part of handling Zip files (i.e. the compression) is built right in to Java SE (java.util.zip
):
http://download.oracle.com/javase/1.5.0/docs/api/java/util/zip/package-summary.html
For your higher level functions it wouldn't be that hard to write some functions to recursively traverse a directory and copy the files into a ZipOutputStream
- probably less than 50 lines of code or so.
There's a good example at http://www.javareference.com/jrexamples/viewexample.jsp?id=108 - it needs a little bit of work to do single files.
Open-source zip library for .NET?
SharpZipLib
Regarding the comments and other posts about the internal gzip implementation, they are not the same! GZip does not create the header required for archiving; it is only useful for "zipping" one file or stream.
Proper zip archives contain a header that list all compressed files and where in the compressed data they come and therefore you need something that makes a header. That means SharpZipLib, one of the many commercial versions or using something external with .NET bindings like 7zip.
Just on the offchance somebody wants to say this: "But I see .gz
files in Linux all the time!" - they're just single files and .tar.gz
is no exception - tar is the archive file. The .gz
is that archive compressed.
Library for browsing zip files from Cocoa application
http://code.google.com/p/objective-zip/
Read file out
ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:@"test.zip" mode:ZipFileModeUnzip];
[unzipFile goToFirstFileInZip];
ZipReadStream *read= [unzipFile readCurrentFileInZip];
NSMutableData *data= [[NSMutableData alloc] initWithLength:256];
int bytesRead= [read readDataWithBuffer:data];
[read finishedReading];
[zipFile close];
List files inside
ZipFile *unzipFile= [[ZipFile alloc] initWithFileName:@"test.zip" mode:ZipFileModeUnzip];
NSArray *infos= [unzipFile listFileInZipInfos];
for (FileInZipInfo *info in infos) {
NSLog(@"- %@ %@ %d (%d)", info.name, info.date, info.size, info.level);
// Locate the file in the zip
[unzipFile locateFileInZip:info.name];
// Expand the file in memory
ZipReadStream *read= [unzipFile readCurrentFileInZip];
NSMutableData *data= [[NSMutableData alloc] initWithLength:256];
int bytesRead= [read readDataWithBuffer:data];
[read finishedReading];
}
[zipFile close];
Note about direcotry structure
Please note that inside the zip files there is no representation of a file-folder hierarchy: it is simply embedded in file names (i.e.: a file with a name like x/y/z/file.txt
). It is up to the program that extracts the files to consider these file names as expressing a structure and rebuild it on the file system (and viceversa during creation). Common zippers/unzippers simply follow this rule.
from manual
Recommendations on a free library to be used for zipping files
UPDATE 2020: There are other choices now, notably Zip4J.
After much searching, I've found three approaches:
A freely available set of source code, suitable for a single file zip. However, there is no license. Usage is AesZipOutputStream.zipAndEcrypt(...).
http://merkert.de/de/info/zipaes/src.zip
(https://forums.oracle.com/forums/thread.jspa?threadID=1526137)
UPDATE: This code is now Apache licensed and released at https://github.com/mobsandgeeks/winzipaes (exported from original home at Google code) . It worked for me (one file in the zip), and fills a hole in Java's opens source libraries nicely.
A commercial product ($500 at the time of writing). I can't verify if this works, as their trial license approach is complex. Its also a ported .NET app:
http://www.nsoftware.com/ipworks/zip/default.aspx
A commercial product ($290 at the time of writing). Suitable only for Wnidows as it uses a dll:
http://www.example-code.com/java/zip.asp
Related Topics
Firebaseapp with Name [Default] Doesn't Exist
Compiled VS. Interpreted Languages
Gson - Convert from JSON to a Typed Arraylist<T>
Android/Java -- Post Simple Text to Facebook Wall
Converting a String to an Integer on Android
How to Add a Shadow and a Border on Circular Imageview Android
Retrofit2 Android: Expected Begin_Array But Was Begin_Object at Line 1 Column 2 Path $
Android.Util.Androidruntimeexception: Requestfeature() Must Be Called Before Adding Content
Background Service for Android Oreo
Why I Cant Use the Populateviewholder Override Method
Onclicklistener Not Responding
How to View My Realm File in the Realm Browser
Run Jar File in Command Prompt
How to Connect to Ftps Server with Data Connection Using Same Tls Session
How to Get Pid of Process I'Ve Just Started Within Java Program