0

I need to replace a file on a zip using iOS. I tried many libraries with no results. The only one that kind of did the trick was zipzap (https://github.com/pixelglow/zipzap) but this one is no good for me, because what really do is re-zip the file again with the change and besides of this process be to slow for me, also do something that loads the whole file on memory and make my application crash.

PS: If this is not possible or way to complicated, I can settle for rename or delete an specific file.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Alejandro Cotilla
  • 2,501
  • 1
  • 20
  • 35
  • 1
    Not possible. The idea of ZIP itself is to maintain the whole section as a single file. Even in that sense, if you wish to change certain part of it, you need to open it, make your changes and save it again. Other options which you should consider is what kind of compression are you using in zipping the files? – Dunes Buggy Jul 15 '13 at 08:11
  • What do you mean when you say "you need to open it, make your changes and save it again", because thats exactly what I need to do. What I mean on my question is that I don´t want to uncompress and compress the entire zip file for one change. And to answer your question if by "kind of compression" you mean zip, gzip, bzip, etc, I have no option here, it has to be zip. Thanks for the reply. – Alejandro Cotilla Jul 15 '13 at 16:18

3 Answers3

0

You need to find a framework where you can modify how data is read and written. You would then use some form of mmap to essentially read and write small chunks. Searching on NSData and mmap resulted in this Post, however you can use mmap from the posix level too. Ps it will be slower than using pure memory no way around that.

Community
  • 1
  • 1
David H
  • 40,852
  • 12
  • 92
  • 138
  • Hi, thanks for the reply. I don´t understand how I can relate this to a zip file. A ZIP file is not just data, because it needs a description and compression for every file inside the ZIP. I would appreciate your help. Thanks. – Alejandro Cotilla Jul 15 '13 at 16:35
  • There is no reason that any ZIP software needs to read in or create a file in memory first. Its quite possible to write the ZIP data as it gets created, file by file, or in the decompression stage. Using MMAP is the way to do that - the software gets pointers and reads and writes, and the system manages the various pages. However, its not something that you could easily add to code that already reads everything into memory. So my point is, someone can do it properly so that very large files can be handled. Now you have to find someone who did it open source. – David H Jul 15 '13 at 21:14
0

Got it WORKING!! JXZip (https://github.com/JanX2/JXZip) has made exactly what I need, they link to libzip (http://www.nih.at/libzip/) that is a fully equiped library for working with ZIP files and JXZip have all the necessary Objective-C wrapper code. Thanks for all the replys.

Alejandro Cotilla
  • 2,501
  • 1
  • 20
  • 35
0

For archive purposes, as the author of zipzap:

Actually zipzap does exactly what you want. If you replace an entry within a zip file, zipzap will do the minimum necessary to update it: it will skip writing all entries before the replaced entry, then write out the entry, then write out all entries after the replaced entry without recompressing. At the moment, it does require sufficient memory for the entries after the replaced entry though.

Glen Low
  • 4,379
  • 1
  • 30
  • 36
  • I recently fixed that last issue: zipzap now doesn't require additional memory for entries after the replaced entry. – Glen Low Aug 21 '13 at 23:03