gpt4 book ai didi

iphone - 使用 iOS-libarchive 库提取 .tar 文件时出现问题

转载 作者:行者123 更新时间:2023-12-03 20:53:54 26 4
gpt4 key购买 nike

我正在使用 iOS-libarchive 库在 iPhone 上提取 .tar。我正在使用此链接中给出的示例代码 http://code.google.com/p/libarchive/wiki/Examples 但我在提取 .tar 文件时遇到问题。我将 .tar 文件放在库/模拟器.../Application/617C31E0/Documents 文件夹中。

当我运行应用程序进行提取时,它会成功完成流程,而不会给出任何错误代码。但我无法在机器中的任何位置精炼提取的文件夹。

这是我在我的应用程序中使用的代码

static int copy_data(struct archive *ar, struct archive *aw)
{
int r;
const void *buff;
size_t size;
off_t offset;

for (;;) {
r = archive_read_data_block(ar, &buff, &size, &offset);
if (r == ARCHIVE_EOF)
return (ARCHIVE_OK);
if (r != ARCHIVE_OK)
return (r);
r = archive_write_data_block(aw, buff, size, offset);
if (r != ARCHIVE_OK) {
warn("archive_write_data_block()",
archive_error_string(aw));
return (r);
}
}
}

static int verbose = 0;

static void extract(const char *filename, int do_extract, int flags)
{
struct archive *a;
struct archive *ext;
struct archive_entry *entry;
int r;

a = archive_read_new();
ext = archive_write_disk_new();
archive_write_disk_set_options(ext, flags);
/*
* Note: archive_write_disk_set_standard_lookup() is useful
* here, but it requires library routines that can add 500k or
* more to a static executable.
*/

archive_read_support_format_tar(a);
/*
* On my system, enabling other archive formats adds 20k-30k
* each. Enabling gzip decompression adds about 20k.
* Enabling bzip2 is more expensive because the libbz2 library
* isn't very well factored.
*/

if (filename != NULL && strcmp(filename, "-") == 0)
filename = NULL;
if ((r = archive_read_open_file(a, filename, 10240)))
fail("archive_read_open_file()",
archive_error_string(a), r);
for (;;) {
r = archive_read_next_header(a, &entry);
if (r == ARCHIVE_EOF)
break;
if (r != ARCHIVE_OK)
fail("archive_read_next_header()",
archive_error_string(a), 1);
if (verbose && do_extract)
msg("x ");
if (verbose || !do_extract)
msg(archive_entry_pathname(entry));
if (do_extract) {
r = archive_write_header(ext, entry);
if (r != ARCHIVE_OK)
warn("archive_write_header()",
archive_error_string(ext));
else {
copy_data(a, ext);
r = archive_write_finish_entry(ext);
if (r != ARCHIVE_OK)
fail("archive_write_finish_entry()",
archive_error_string(ext), 1);
}

}
if (verbose || !do_extract)
msg("\n");
}
archive_read_close(a);
archive_read_finish(a);
exit(0);
}

- (void)applicationDidFinishLaunching:(UIApplication *)application
{
// Override point for customization after application launch
[window makeKeyAndVisible];

// Extract files from archive into named dir in the temp dir

NSString* databaseName = @"PIIS147020451170078X.tar";
NSArray* documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDir = [documentPaths objectAtIndex:0];
NSString* make7zResPath = [documentsDir stringByAppendingPathComponent:databaseName];

/*
NSString *tmpDirname = @"Extract7z";
NSString *make7zFilename = @"PIIS147020451170078X";//@"test.7z";
NSString *make7zResPath = [[NSBundle mainBundle] pathForResource:make7zFilename ofType:@"tar"];
*/

extract([make7zResPath cStringUsingEncoding:NSUTF8StringEncoding],1, ARCHIVE_EXTRACT_TIME);

return;
}

请帮我解决这个问题:(。

谢谢!!

最佳答案

我编写了另一个库,它完全可以满足您的需求:https://github.com/mhausherr/Light-Untar-for-iOS

简而言之,我只实现了解压文件的最少功能。完整解释在这里http://blog.octo.com/en/untar-on-ios-the-pragmatic-way/

关于iphone - 使用 iOS-libarchive 库提取 .tar 文件时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6757324/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com