Appending to a file in a zip archive - c++

I have written a zip class that uses functions and code from miniz to: Open an archive, Close an archive, Open a file in the archive, Close a file in the archive, and write to the currently open file in the archive.
Currently opening a file in an archive overwrites it if it already exists. I would like to know if it is possible to APPEND to a file within a zip archive that has already been closed?
I want to say that it is possible but I would have to edit all offsets in each of the other file's internal states and within the central directory. If it is possible - is this the right path to look in to?
Note:
I deal with large files so decompressing and compressing again is not ideal and neither is doing any copying of files. I would just like to "open" a file in the zip archive to continue writing compressed data to it.

I would just like to "open" a file in the zip archive to continue writing compressed data to it.
Compressed files aren't working like a file system or folder, where you could change individual files. They keep e.g. check sums, that need to apply for the whole archive.
So no, you can't do such inplace, but have to unpack the compressed file, apply your changes and compress everything again.

Related

How to store data other than text in c++ files

I want to store videos and images in c++ files. Can we store data other than text in c++ files. Like images, and videos.
Yes. If you install any picture onto your computer, you can just change the file extension to cpp. The file type is a C++ file, however, if you attempt to read the file it will of course be corrupted and not really make sense.
Changing the extension back to .png or .jpg will restore the image file back to its former glory.

Getting error if my source and destination files are same in vips

I am using php libvips library. I applied one image operation on one image file, now i want to store same file in my folder. But vips give me error if my source and destination both file are same. Is there any solution for that?
I am using $image->writeToFile(); for store the my file
libvips is a streaming image-processing library -- pixels are processed from source to destination in a series of small chunks, and entire images are not held in memory. This means the source file and destination file must both exist at the same time, which means you can't use the same filename for both.
The best solution is to write to a temporary file, then rename the temporary file over the source file once processing finishes.

How to extract gz files and rename to xml

I have approximately 130,000 gz files, each containing one file which needs to be renamed with a .xml extension in order to be viewed properly. For example, on gz file might be named 100.san.form.gz and contain the file 100.san.form, which needs to be renamed to 100.san.form.xml to be viewed appropriately.
I am trying to write a script to unzip all of these files and then rename them appropriately, and read them into my program to parse.

delete and modify file in zip with minizip

I wrote code to delete file in zip with minizip.
referenced http://www.winimage.com/zLibDll/del.cpp
I have to delete and modify the file and in zip frequently.
the zip file that used is 1.6 GB.
Deleting the file and in zip means
copy whole zip file except the file to delete to new zip file
delete old zip file.
rename new zip file to old zip file.
so too slow delete and modify(delete and add).
how can I make faster deleting and modifying the file in zip?
is there any idea?
You can write your own code to delete a zip entry in place. That is a little more risky, since if there is a problem or the system goes down in the middle of the operation, you will have lost the file. Your current approach, copying the zip file, assures that you always have one good zip file available if something goes south.
The .ZIP File Format Specification provides all the information you need to write your own deleter. The structure of a zip file is relatively straightforward, but it will take some attention to detail to work through all the possibilities.
The deletion operation will still require copying all of the zip file content that follows the deleted entry down.
Having done that, adding a file in place will be relatively fast, since it just goes at the end, and the central directory is rewritten. If the deletion and additions are the same file or files, then they will naturally end up at the end, and the in-place operations should be faster than copying the whole zip file.

Zipping a file from memory in linux

I'm working on application that must enrypt and zip files. So, I create some data in memory (text, binary or whatever), encrypt it and save to disk (file1 and file2). The I call e.g. "zip out.zip file1 file2 ".
I do not want to save this files to disk, but immediately create zip and pack these files from memory.
How should I do that?
Thanks a lot!
You could try to use the zlib library to be able to create zip files from memory buffers.
The boost:iostreams could also be a good solution.
For zlib there is an extension for zip called minizip in the contribs. For minizip you can find code to work with in-memory buffers on the authors page:
Justin Fletcher wrote a very simple implementation of a memory access method for the ioapi code (ioapi_mem_c.zip).
Note that you must compress first and then encrypt. Encrypted data can't be compressed anymore.
Interestingly enough, I wasn't able to find a library to create ZIP files from C. zlib only allows to (de-)compress individual entries in a ZIP archive.
It comes with contrib/minizip; maybe that can get you started.