3

Is there any way of modifying a zip on android without having to extract its contents? I only need to add/remove about 10 files. If I had to extract the zip it could go up to 200mb.

nebkat
  • 8,445
  • 9
  • 41
  • 60
  • +1, interesting question; I suspect that android uses some standard java libraries for modifying compressed files, so you may want to search for that on this site. – jcollum Jan 05 '11 at 22:41
  • @jcollum: I don't have any code yet, but I'm waiting to see whether I will need third party code or `java.util.zip` is enough. – nebkat Jan 05 '11 at 22:48
  • java.util.zip doesn't give you what you need. From native code you could use something like build/tools/zipalign/ZipFile.cpp, which can delete entries and add compressed data without recompressing it (e.g. adding a gzipped file to a zip archive), but that's not part of the public API so I can't really recommend it. – fadden Jan 06 '11 at 00:15

2 Answers2

2

Seems its not possible without 3rd party packages. Appending files to a zip file with Java

I'll still wait for answers...

Community
  • 1
  • 1
nebkat
  • 8,445
  • 9
  • 41
  • 60
0

I don't think you are going to find an easy way to do this with built in libraries. If this is a core function of your application, you may want to write your own (parsing zip isn't that hard).

Here's the general approach: start reading the zip, identify the first zip entry header - when you find the header for the entry you want to exclude, just keep reading to the next entry - otherwise, write out. Keep track of the output offset of each zipentry. Then write your own zip trailer at the end of the file.

The zip format is well defined (and not particularly complex - especially b/c you won't have to muck with flate or deflate or encryption or anything like that), and what you are trying to do is straightforward: http://www.pkware.com/documents/casestudies/APPNOTE.TXT

On the other hand, if this is not a core piece of functionality for your app, find and license a library that can do it (I doubt that you'll find open source implementations that do) and move on.

Kevin Day
  • 16,067
  • 8
  • 44
  • 68