0

Is possible do convert GZ to ZIP format use objective-c?

NSFileManager *fileManger = [NSFileManager defaultManager];
NSError *error;

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [paths objectAtIndex:0];
paths = nil;
path = [path stringByAppendingPathComponent:@"text.zip"];

if([fileManger fileExistsAtPath:path ] == NO){
NSString *testPath = [[NSBundle mainBundle] pathForResource:@"text" ofType:@"gz"];
[fileManger copyItemAtPath:@"" toPath:@"" error:&error]; 
}

converted gz file from mainBundle to zip file placed to docuemtn directory.

But can not open zip file by ZipArchive class.

Developer
  • 1
  • 1
  • 3

1 Answers1

2

gzip is only compressing data, while ZIP is both a compressor and archiver. A gzip stream can only compress one file while ZIP can compress several. So simply renaming the file cannot work.

You need to decompress the gzip stream to a file, then recompress as ZIP.

Community
  • 1
  • 1
DarkDust
  • 90,870
  • 19
  • 190
  • 224
  • Often `.gz` is used with `tar`, so there is that. However the solution is to unpack into a temporary directory and re-pack that directory using `zip`. – trojanfoe Nov 13 '14 at 10:37
  • @trojanfoe: Right. But you'd either need to know/expect the file to be a `tar.gz/tgz` file or check by inspecting the decompressed file before you can [untar the file](http://stackoverflow.com/questions/1811608/untar-file-on-iphone) . – DarkDust Nov 13 '14 at 10:50