I have kept my sqlite database in the S3 server in the .gz format. When my iOS App starts, I want to download the database in .gz file and decompress it in the documents directory.
Download part is working fine but decompression is not working.
I tried ZipArchive, but it doesn't decompress .gz file. It is able to unzip ZIP files. Below is the code, I tried.
ZipArchive *za = [[ZipArchive alloc] init];
if ([za UnzipOpenFile:filePath]) {
BOOL ret = [za UnzipFileTo:destPath overWrite:YES];
[za UnzipCloseFile];
[za release];
if (ret == YES) {
[self stopSpinner];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[appDelegate encTitle] message:@"Update successful.\nPlease restart the application for changes to take effect." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
} else {
//Didn't work
}
}
I found GZIP for decompression in iOS, but don't have any idea to use this. If anyone has idea, please share with me. Link for GZIP :: https://github.com/nicklockwood/GZIP
If anyone knows any other library for .gz decompression.....they are also welcome.
I maintain a lightweight Swift 3+ wrapper library around Apple's own compression library called DataCompression. Among others it also supports the GZIP format.
Decompressing a .gz text file and printing the content would look like this:
You may refer to the README for a complete overview of the interface and other compression formats.
What specifically are you having difficulty with using the GZIP library?
All you need to do is call
gunzippedData
on anNSData
instance and it will return a newNSData
object with the unzipped data.Update
The GZIP library does not work with files, however it works directly with instances of
NSData
. This means you will have to construct anNSData
object from your compressed .gz file manually, uncompress it, and write the uncompressed data to the documents directory...