zipper icon indicating copy to clipboard operation
zipper copied to clipboard

Add the file to the zip and overwrite the original file, but now a new file of filename_1 will be created

Open Tabstone opened this issue 4 years ago • 12 comments

what should I do

Tabstone avatar Jul 10 '20 06:07 Tabstone

Hi ! I'm not the original author I'm just helping fixing bugs. I think use Overwrite ( enum zipFlags { Overwrite = 0x01, Append = 0x02, Store = 0x04, Faster = 0x08, Better = 0x10, NoPaths = 0x20, SaveHierarchy = 0x40 };) inside:

    bool add(std::istream& source, const std::tm& timestamp, const std::string& nameInZip = std::string(), zipFlags flags = Better);
    bool add(std::istream& source, const std::string& nameInZip = std::string(), zipFlags flags = Better);
    bool add(const std::string& fileOrFolderPath, zipFlags flags = Better);

This should be better documented I agree !

Lecrapouille avatar Jul 10 '20 23:07 Lecrapouille

What I want to overwrite is the file inside the zip, this enum cannot solve the problem

Tabstone avatar Jul 11 '20 00:07 Tabstone

Hi ! It should not! If possible, can you give me your basic example for deeper investigation? Thanks

Lecrapouille avatar Jul 11 '20 09:07 Lecrapouille

I want to modify a file in the zip, I first extract an entry from the zip and then modify and add it to the previous zip, what should I do

Tabstone avatar Jul 11 '20 09:07 Tabstone

yeah adding another entry with the same name/path as an already added entry will not overwrite the entry, instead, it adds another one with the same name/path, also if u will fix this could add a method to delete entries, please?

Mylifeismyhome avatar Jul 13 '20 04:07 Mylifeismyhome

I'll investigate. The problem is that this API is based on an out of date Minizip version which has evolved so much that I cannot easily update it.

Lecrapouille avatar Jul 13 '20 16:07 Lecrapouille

@Mylifeismyhome I read in minizip.h: There is no delete function into a zipfile. If you want delete file into a zipfile, you must open a zipfile, and create another. Of course, you can use RAW reading and writing to copy the file you did not want delete. As a consequence @Tabstone I guess updating a file is not possible. We may have a routine to hide this.

After looking inside the code, I see that zipFlags is a mishmash for multiple methods. Overwrite is not used for add() method but for constructor initFile() and not passed as param but set as local variable. add() methods only use Faster or Better. This is a little touchy.

Lecrapouille avatar Jul 13 '20 17:07 Lecrapouille

Overwriting files inside the zip is not managed. Buts flags overwrite, append to pass in the add() methods are in fact private flags to overwriting the zip archive.

Lecrapouille avatar Feb 13 '21 12:02 Lecrapouille

Can this problem be solved or is there any other solution

Tabstone avatar Feb 17 '21 08:02 Tabstone

@Tabstone For now as far as I understand this not possible. I guess you achieve it only by unzipping and zipping back. Better would contact original authors directly @sebastiandev @fbergmann (if they answer). I guess with the latest minizip version https://github.com/zlib-ng/minizip-ng/ this is directly possible but currently, this project is referencing a SHA1 dated in 2016 (I earnt 1 year of commits but after the API is broken).

Lecrapouille avatar Feb 17 '21 20:02 Lecrapouille

Is there an API for deleting files

Tabstone avatar Feb 19 '21 16:02 Tabstone

I know this will not be easy: but this code can help (untested')

Unzipper unzipper("zipfile.zip");
unzipper.extract("myFolder");
remove("unwanted file");

Aipper zipper("zipfile.zip");
zipper.add("myFolder");

We could improve API by adding such methods:

Extract all file except given files

Unzipper::extractAllExcept(vector undesired files);
// maybe equivalent to
std::map<std::string, std::string> alternativeNames = { {"UndesiredFile", ""} };
unzipper.extract(".", alternativeNames);

Extract from zip and insert to another zip:

Unzipper::extract(Zipper&);
// or:
Unzipper::Unzipper(Zipper&); + Unzipper::extract();

Lecrapouille avatar Feb 19 '21 18:02 Lecrapouille

Close since in v2.x.y these flags are used for replacing or appending the zip file and replacing elements in zip is not possible.

Lecrapouille avatar Sep 12 '22 23:09 Lecrapouille