javanthropus / archive-zip

A simple Ruby-esque interface to creating, extracting, and updating ZIP archives in 100% Ruby.
https://rubygems.org/gems/archive-zip
MIT License
83 stars 10 forks source link

Delete and replace #15

Closed alexander-williamson closed 8 years ago

alexander-williamson commented 8 years ago

How do you delete or replace items from a zip?

javanthropus commented 8 years ago

I'm working mobile right now, so please pardon my brevity. Basically, you have to create a new archive based on the content of the old one and then replace the old archive with the new one. There's no way to perform deletions or replacements in place.

You should be able to copy the entries from the old archive directly, removing or replacing entries as needed, without the need to extract them. It's been a while since I was in the code, but I'm fairly sure that's true.

alexander-williamson commented 8 years ago

That totally makes sense. Thanks for the reply. Can close this if you feel it shouldn't be added but would be nice if it was supported out of the box.

javanthropus commented 8 years ago

This project used to support in place modification of archives; however, I removed it because it complicated the implementation and took away control of a couple important aspects of exactly how the edit should be performed. For instance, the user may need the new archive to be created in a temporary location on another filesystem due to space constraints and then moved over to replace the original.

In the end, I decided to view this in the same way as directly changing the middle of any file. If you do that, you need to rewrite the file and then replace the original. There's no way to delete any part of the middle in any other way.