-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: archive/zip: add support for appending files #15626
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
Comments
The proposal #14386 switches the object format to be using zip files and requires the ability to append to files. Currently the proposal seems to indicate that it will use some internal logic to handle appending to zip files. |
@james-tech for starters here is something that might solve the problem for you https://github.com/rsc/zipmerge by @rsc. |
There is a fork of std/zip by @rogpeppe that supports this. Some discussion on the initial implementation is here: https://groups.google.com/forum/#!topic/golang-dev/ZSubqlF2G4k |
Any news on if/when this can be included? |
Following up on Russ' comment in the linked email thread, it would be preferable if any suggested API allowed replacing and deleting existing files (since the appending a new central directory record can simply omit references to "deleted" files). True deletion would require rewriting the entire ZIP file, so there is no need for a new API for that. |
I'm working on this and I have two proposals. First, adding new method For example, deleting file is bellow.
In the replacing case, comparing header then copy or write. I believe that these can cover most cases. |
Assuming that the API isn't concerned with true deletion, one possibility is to mimick that of libzip. Adapted for Go:
|
Marking as proposal, so this goes through the appropriate process. |
It seems awfully strange for a type named Currently archive/zip has a seekable reader and a streaming writer. This proposal is about adding some mechanism that permits modifying an existing zip file. I don't see how starting with |
I'm not entirely familiar with the details of zip file operations, but can we consider a
If the changes were to be minimally invasive, then possibly adding a new
to mirror the structure of Reader allows the usage of file offset information to perform append, replace, and delete. The usage of the API would then be very similar to how it is for Reader, except we can do more operations.
|
A good API proposal here will need to both consider Go API norms as well as consideration for how zip files work. It'd be worth researching the zip format a bit first. Notably, the TOC is at the end. We'd need an API that lets you open something, do some reads, do some mutations (tracking the TOC changes while appending to the file), and then let you do the final Close (writing the new TOC footer). We might be able to reuse the Writer type if there were a new constructor for it, but we don't have any appending+io.ReaderAt type (WriterReaderAt?), so you might need to define such an interface first. It'd need to clarify that it writes to the end. But then we never reuse the TOC space, or fill in any other holes from deleted files, if that's desirable. If that's going to be a goal, we need a different read+writer type. |
At one point I thought I wanted this, but I don't remember why. Does anyone want this? Maybe it is fine in external packages instead of stuffing it into the standard library. |
Declined for now. Seems like the API we'd need to add wouldn't necessarily be worth it, considering the low number of potential users. Let's see this happen outside of the standard library first. |
Please answer these questions before submitting your issue. Thanks!
go version
)?1.6.2
go env
)?mac
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
I found that the archive/zip package release realization is uncompleted.
I want to append a dir or some files into an exists zip file without unzip it, but the functions are not supported.
I use the exec.Command to call
zip -r
command in the system. may be is not the good way.I hope the next version archive/zip will support it.
The text was updated successfully, but these errors were encountered: