Best strategy to "save as"? #489
Replies: 2 comments 3 replies
-
Here is my implementation for OpenXLSX, I hope I don't get shunned for doing a CPP wrapper: It appears that it is unavoidable to wrap a save operation in the below calls, as done starting from
|
Beta Was this translation helpful? Give feedback.
-
I'm sad to hear that. If you can give us more concrete feedback, we can work on improving it.
This is currently not supported directly, but wouldn't be hard to add. We'll discuss this internally and get back to you.
in-place might be misleading here: libzip writes the new archive to a temporary file and once complete, replaces the original file with that.
No, they are only read from the supplied source when
True, see above for details.
You can read changed data by calling
Currently, yes. Unless you're using a filesystem that supports file cloning (btrfs on Linux and APFS on macOS), this is basically what
Yes. However, unless you're using a file system that supports cloning, a new file will have to be written from scratch for each save anyway.
You only have to call For an archive with many entries, this introduces some overhead. We've discussed implementing a way to flush the changes to disk (or memory in your case) while keeping the archive open, but that introduces a lot of additional complexity in an already complex section of the code, with many corner cases that could introduce subtle bugs, so we've decided against adding it. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am honestly a bit lost in the libzip documentation, most of the functions I have to learn by trial & error / copying code from examples. So my apologies if I am missing something obvious, but:
How would I go about modifying an existing zip file and then saving the modified archive to a NEW file?
Currently, my understanding is that
Accordingly, it is not possible to read changes that have been written to the archive (zip_t) without first saving and re-opening (not so bad, just prevents direct plausibility checks after a write).
Furthermore, it appears that - in order to accomplish a "save as" function, I would have to create a new archive from scratch, and add all the files to that new archive for saving.
Is that really how I need to do it? So - assuming I want to provide a User API "save as" function, and the user calls that repeatedly for different file names - does that also mean I have to re-create the full archive each time a new save file is desired?
Or is
https://github.com/aseprite/libzip/blob/master/examples/in-memory.c
the way to do it, i.e., I need to work with the archive raw data to save it?
Edit: I just managed to "save as" with the in-memory example, but that raises the next question: How do I prevent the
zip_close
? Or is re-opening viazip_open_from_source
a non-issue in terms of performance, even for large archives?Beta Was this translation helpful? Give feedback.
All reactions