真的坚持尝试编写代码来解压缩 iPhone 上的文件或目录。
下面是我用来尝试解压缩简单文本文件的一些示例代码。
它解压缩文件,但它已损坏。
(void)loadView {
NSString *DOCUMENTS_FOLDER = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString *path = [DOCUMENTS_FOLDER stringByAppendingPathComponent:@"sample.zip"];
NSString *unzipeddest = [DOCUMENTS_FOLDER stringByAppendingPathComponent:@"test.txt"];
gzFile file = gzopen([path UTF8String], "rb");
FILE *dest = fopen([unzipeddest UTF8String], "w");
unsigned char buffer[CHUNK];
int uncompressedLength = gzread(file, buffer, CHUNK);
if(fwrite(buffer, 1, uncompressedLength, dest) != uncompressedLength || ferror(dest)) {
NSLog(@"error writing data");
}
else{
}
fclose(dest);
gzclose(file);
}