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

Remove the distinction between mutable and immutable archives #24

Closed
mikeabdullah opened this issue Feb 6, 2013 · 2 comments
Closed

Comments

@mikeabdullah
Copy link
Contributor

In Cocoa, an immutable object is one whose contents cannot change.

For example, an immutable array holds a unchanging list of objects. Yes, properties etc. of those objects might change, but the actual objects referred to does not.

And again NSData consists of a pointer (to some bytes) and a length. Neither of those can change. In rare setups, the memory pointed to can change, but the NSData object itself does not.

ZZArchive follows a similar pattern, having a mutable subclass, but oddly does not adhere fully; a regular ZZArchive can be mutated at any time by calling the -load: method.

There is little to advantage to having a truly immutable archive; unlike arrays and strings etc. apps do not tend to pass them around too much internally (particularly when memory mapping means entries can have their content changed out underneath them anyhow).

Thus I argue there is no point in having ZZMutableArchive as a separate class. ZZArchive should be mutable, and that would be it. For apps that do feel the need to pass around archives internally, it's simpler to just agree not to mutate it, or define a protocol and pass around objects promising only that they conform to it.

@pixelglow
Copy link
Owner

Your idea has merit. Zip archive objects don't follow the usual "all changes in memory, then safe-save to disk" behaviour of Foundation containers, they behave more like Core Data objects with incremental updates. I'm all for simplifying the interface if it will ease the burden of working with the API.

However:

There is little to advantage to having a truly immutable archive; unlike arrays and strings etc. apps do not tend to pass them around too much internally (particularly when memory mapping means entries can have their content changed out underneath them anyhow).

You can and should pass around and reference archive objects. It's just that the archive entry objects will go invalid when load: or updateEntries:error: is called. Thus you should be careful if you pass around or keep references to archive entries.

In terms of memory mapping allowing entries to change out underneath them, this is no different from using NSData with memory mapping; after all we use NSData in that way under the covers. zipzap does not support consistent multi-user access, as with any use of memory mapping without locking at some level.

What do the other watchers think of getting rid of a distinct ZZMutableArchive ?

@pixelglow
Copy link
Owner

No further feedback, so I'm closing the issue.

pixelglow added a commit that referenced this issue Sep 4, 2014
* No more separate mutable archive subclass (ref #24).

* Initializers and factory methods may now return nil, along with error information.

* Initializers now take an options dictionary, which allows for expansion. For now, you can set ZZOpenOptionsEncodingKey for string encoding and ZZOpenOptionsCreateIfMissingKey to create the archive file if it is missing.

* Drop the public load: method, as initializers and updateEntries: do any necessary loading. It’s fairly cheap to create a new archive object to reload changed contents, and we no longer lazily load contents and entries.

* The redesign prevents creating erroneous objects e.g. file not found may be a legitimate problem, and prevents swallowing of read errors during lazy loading.

* Update podspec to version 8.0.
macguru pushed a commit to ulyssesapp/zipzap that referenced this issue Jul 18, 2020
…rties to feature/docx

ULYSSES-4821 Translate Section Settings to DOCX

* commit 'fc8a022bfe138f7b3408a33879ef3fc74a511930':
  Adds comment to keyword support
  Restores iOS compatibility
  Fixes keyword support
  Adds support for core properties
  Adds test case for document properties
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants