Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Archives are corrupt on iOS 10.2 #156

Open
jjxtra opened this issue Jan 13, 2017 · 1 comment
Open

Archives are corrupt on iOS 10.2 #156

jjxtra opened this issue Jan 13, 2017 · 1 comment

Comments

@jjxtra
Copy link

jjxtra commented Jan 13, 2017

Using this code to create an archive, I'm unable to open in Windows or MAC.

        ZZArchive* archive = [[ZZArchive alloc] initWithURL:url options:@{ZZOpenOptionsCreateIfMissingKey : @YES} error:&error];
        if (error == nil)
        {
            NSMutableArray* entries = [NSMutableArray array];
            for (NSURL* fileURL in fileURLs)
            {
                NSURL* fileURLCopy = fileURL;
                fileAttributes = [fm attributesOfItemAtPath:fileURL.path error:&error];
                fileSumSize += fileAttributes.fileSize;
                NSString* subFile = [fileURL.path substringFromIndex:root.length];
                NSString* subDir = [subFile stringByDeletingLastPathComponent];
                if (subDir.length > 0 && ![dirs containsObject:subDir])
                {
                    [dirs addObject:subDir];
                    ZZArchiveEntry* dirEntry = [ZZArchiveEntry archiveEntryWithDirectoryName:subDir];
                    [entries addObject:dirEntry];
                }
                ZZArchiveEntry* entry = [ZZArchiveEntry archiveEntryWithFileName:subFile compress:NO streamBlock:^(NSOutputStream* output, NSError** _error)
                {
                    uint8_t buffer[8192];
                    NSInputStream* input = [NSInputStream inputStreamWithFileAtPath:fileURLCopy.path];
                    NSInteger count;
                    [input open];
                    while ((count = [input read:buffer maxLength:8192]) > 0)
                    {
                        NSInteger written = 0;
                        while (written < count)
                        {
                            written += [output write:buffer + written maxLength:count - written];
                            bytesWritten += written;
                        }
                    }
                    [input close];
                    [self updateProgress:++filesWritten total:fileURLs.count];
                    return YES;
                }];
                [entries addObject:entry];
            }
            if (error == nil)
            {
                [archive updateEntries:entries error:&error];
            }
@pixelglow
Copy link
Owner

From inspection, I don't see any issues with the code.

Please supply a self-contained Xcode project with sample files and the minimal code needed to show the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants