zipper
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
what should I do
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 !
What I want to overwrite is the file inside the zip, this enum cannot solve the problem
Hi ! It should not! If possible, can you give me your basic example for deeper investigation? Thanks
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
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?
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.
@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.
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.
Can this problem be solved or is there any other solution
@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).
Is there an API for deleting files
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();
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.