iPhone解压缩代码

编程入门 行业动态 更新时间:2024-10-28 11:28:44
本文介绍了iPhone解压缩代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

试图编写代码以解压缩iPhone上的文件或目录。

Really stuck on trying to write code to unzip a file or directory on the iPhone.

下面是一些示例代码,我使用它来尝试和解压缩一个简单的文本文件。

Below is some sample code that Im using to try and unzip a simple text file.

它解压缩文件,但损坏。

It unzips the file but its corrupt. Would be really grateful is someone has an example or any pointers.

感谢您

Tony

(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);

}

推荐答案

sample.zip真的是用gZip创建的吗? .zip扩展名通常用于由WinZip创建的存档。这些也可以使用zLib解压缩,但你必须解析标题和使用其他例程。

Has "sample.zip" really been created with gZip? The .zip extension usually is used for archives created by WinZip. Those can also be decompressed using zLib, but you'd have to parse the header and use other routines.

要检查,看看前两个字节的文件。如果是'PK',它是WinZip,如果它是0x1F8B,它的gZip。

To check, have a look at the first two bytes of the file. If it is 'PK', it's WinZip, if it's 0x1F8B, it's gZip.

因为这是iPhone特定的,看看这个 iPhone SDK论坛讨论其中 miniZip 。看来这可以处理WinZip文件。

Because this is iPhone specific, have a look at this iPhone SDK forum discussion where miniZip is mentioned. It seems this can handle WinZip files.

但如果它真的是一个WinZip文件,你应该看看 WinZip规范,并尝试自己解析文件。它基本上应该解析一些头值,寻找压缩流位置和使用zLib例程解压缩它。

But if it's really a WinZip file, you should have a look at the WinZip specification and try to parse the file yourself. It basically should be parsing some header values, seeking the compressed stream position and using zLib routines to decompress it.

更多推荐

iPhone解压缩代码

本文发布于:2023-10-30 01:14:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1541330.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:解压缩   代码   iPhone

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!