pixelglow / ZipZap

zip file I/O library for iOS, macOS and tvOS
BSD 2-Clause "Simplified" License
1.22k stars 199 forks source link

How to zip multiple file and directory into one? #132

Closed ylchoo-personal closed 8 years ago

ylchoo-personal commented 8 years ago

I'm trying to zip some files and directories into a single zip file. I don't want to zip them inside another directory cause I need them to be at the root of the zip.

[newArchive updateEntries:
         [newArchive.entries arrayByAddingObject:
          [ZZArchiveEntry archiveEntryWithFileName:fileName
                                          compress:NO
                                         dataBlock:^(NSError** error)
           {
               return data;
           }]]
                            error:&error];

Tried this but this only take NSData but I have no clue how to get NSData for entire directory.

screen shot 2015-12-30 at 10 27 32 am

I'm trying to zip the 4 files "_rels", "[Content_Types]", "deoProps", "word" as one zip file which they will be the root.

pixelglow commented 8 years ago

Here's a rough outline of what you want:

  1. Create an NSMutableArray<ZZArchiveEntry>.
  2. Add a ZZArchiveEntry for each file you want in there. The filename should include any subdirectory name.
  3. Call updateEntries: with this array.

Most unzip utilities are OK with a zip file that doesn't have directory entries as I've suggested. If you need a directory entry, insert the directory entry before you insert the file entries.

You can look at this for guidance for a suitable recursive routine although it talks about unzipping instead.