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

Creates an NSDictionary of file names and entries. #167

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ZipZap/ZZArchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ NS_ASSUME_NONNULL_BEGIN
* The array of ZZArchiveEntry entries within this archive.
*/
@property (readonly, nonatomic) NSArray<ZZArchiveEntry*>* entries;
@property (readonly, nonatomic) NSDictionary<NSString *, ZZArchiveEntry*>* entriesDictionary;

/**
* Creates a new archive with the zip file at the given file URL.
Expand Down
11 changes: 9 additions & 2 deletions ZipZap/ZZArchive.mm
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ - (BOOL)loadCanMiss:(BOOL)canMiss error:(out NSError**)error
ZZCentralFileHeader* nextCentralFileHeader = (ZZCentralFileHeader*)(beginContent
+ endOfCentralDirectoryRecord->offsetOfStartOfCentralDirectoryWithRespectToTheStartingDiskNumber);
NSMutableArray<ZZArchiveEntry*>* entries = [NSMutableArray array];
NSMutableDictionary<NSString *, ZZArchiveEntry*> *entriesDictionary = [NSMutableDictionary dictionary];

for (NSUInteger index = 0; index < endOfCentralDirectoryRecord->totalNumberOfEntriesInTheCentralDirectory; ++index)
{
// sanity check:
Expand All @@ -159,15 +161,20 @@ - (BOOL)loadCanMiss:(BOOL)canMiss error:(out NSError**)error
ZZLocalFileHeader* nextLocalFileHeader = (ZZLocalFileHeader*)(beginContent
+ nextCentralFileHeader->relativeOffsetOfLocalHeader);

[entries addObject:[[ZZOldArchiveEntry alloc] initWithCentralFileHeader:nextCentralFileHeader
localFileHeader:nextLocalFileHeader]];
ZZOldArchiveEntry *entry = [[ZZOldArchiveEntry alloc] initWithCentralFileHeader:nextCentralFileHeader
localFileHeader:nextLocalFileHeader];

[entries addObject:entry];
[entriesDictionary setObject:entry forKey:entry.fileName];


nextCentralFileHeader = nextCentralFileHeader->nextCentralFileHeader();
}

// having successfully negotiated the new contents + entries, replace in one go
_contents = contents;
_entries = entries;
_entriesDictionary = entriesDictionary;
return YES;
}

Expand Down