I need compress library for following needs:
1) Packing directory in one file with extension of my choice ( .pack for example )
2) Work with content in this file (directory) without unpaking it
3) Mechanism for encrypting
I already know about zlib, but for me it is ugly documented and not written anywhere what features are support from it
Packing directory in one file with extension of my choice ( .pack for example )
Most archivers don't require you to use a particular file extension. Regardless, one can still invoke file on a file to guess its content type.
Work with content in this file (directory) without unpaking it
It's possible to create a file list manually and prepend any archive file with that. Often, .sh installers for Linux contain a shell script in the beginning, followed by some magic line like __ARCHIVE_START__ followed by a binary archive. Hence it is possible to read lines from a file until __ARCHIVE_START__ line has been read. The rest of the file is an archive file.
Mechanism for encrypting
One easy way is to use different libraries for archiving and encrypting:
Bundle the files into one .tar.
Archive .tar into say .tar.xz.
Prepend the .tar.xz with file list followed by __ARCHIVE_START__ line.
Encrypt the file with any encryption library you please.
What you want is not a compression library. You want a compression, archiving, and encryption library or libraries. You need archiving to put a directory of files into a single file.
You can use zlib to do the compress part, but not archive or encrypt. zlib is documented in zlib.h and you can see a usage example there, as well as many examples in the source distribution package.
You can construct your own archiving format, or you can use existing ones for which there are libraries such as zip or tar, both of which use or can be directed to use zlib.
You can use OpenSSL for strong encryption.
Related
We need to store some data as c++ header file, so that we can then include it in the build bundle and shipped with any applications that use it.
To do that we use
xxd -i data.png > data.h
This works well, but the data.h files is now as 6X large as the data.png file. That means, if the data.png is 4MB, the data.h would be 24MB.
May I ask if there is a way to compress the data.h file to a smaller size?
Thanks!
--- update ---
Thank you all for the suggestions! I think I could clarify the need here to provide more context!
the ideal way for us to consume the file is we can open it as input stream like
std::ifstream is;
infile.open("data.png");
somefunc(is) // a api function that takes std::istream as input
p.s. the file is not png file but a scripted model, I use png as example because I find it as a more generic problem of "xxd -i"
we didn't find a way to make it available as a file to be read, as the file system the codes actually searching would be in Android/iOS. (only files on the mobile system are available and the source codes would be zipped in the .so file)
with the header file we can do something like
std::stringstream is;
is.write((char*)data_byte_array, data_byte_array_len)
somefunc(is)
The source codes would end up built as a lib.so. In our tests, A 70KB data.h would end up adding 45KB to the lib.so.
May I ask if there is a way to compress the data.h file to a smaller size?
You can use any lossless compression algorithm. The gzip program is a common default choice on POSIX systems.
You can compile any binary file into an object file using objcopy -I binary. See C/C++ with GCC: Statically add resource files to executable/library for more details
how do i add/remove specific file in zip file with zlib?
there are data.zip.
it has 1.bmp and 2.bmp.
T want to add 3.bmp and remove 2.bmp.
how do i do?
Except deleting data.zip and compress 1/3.bmp to data.zip.
zlib does not support ZIP files by itself, only DEFLATE streams. ZIP uses DEFLATE, but it is not the same. You need a library such as libzip, zziplib, minizip, etc which support ZIP files, most of which in turn use zlib.
Is there a way to create a zip archive with the full folder content or multi-files.
I actually looked the example on the web but each time it's a compression of file only based on a buffer like for example : gzip_compressor() or gzwrite()
I can't give a full path in input but only a file buffer.
=> Then no folder compression nor multi-file compression ???
Please note that I would like to use zlib/gzip or boost (the only library i can link)
I think I missed something there...
Can you please help me ?
Marc.
There are several libraries out there to handle zip files. They use zlib for the compression, decompression, and crc32 operations. You should look at libzip and DotNetZip.
It looks like this will work. If you are on a Unix environment you may have to run the Java version:
http://www.7-zip.org/sdk.html
I want to Unzip a multi zip files or a split files directly in my application in iPad.
For this i have minizip a framework in langage C (thats work for a simple .zip file).
So my question is how Unzip a file like .z01, .z02 or/and a file .zip.001, .zip.002 in one of this language C, C++ or/and Objective-C (if possible an example of how make this)?
I try (in Objective-C) too take data of all files and assemble in one file that doesn't worked, so an other response possible is to explain how a split of zip is made (just data cut or somethings else)?
Thanks in advance for your consideration
Finally,
when you split a zip file in multi files like zip.001 zip.002 etc... you just cut the data of source file.
So for unzip this type of files just take data of all files and concat in one file, after this just unzip this new file with framework minizip and in Objective-C use the code project ZipArchive (that use minizip) in google source code.
P.S : Thanks to David H for his help.
How can I zip directory in C++. I read this question: How do I zip a directory of files using C++? But I'd prefer a way that uses something like gzip, zlib and boost(because I do not want to add new libs to the project). Winapi-way is also acceptable (if it exists). And I do not want to start new process.
I would like a code sample. Thanks in advance
You want zip but you don't want to use any libraires?
Do you want to be bound by a particular licence - if so then simply copy all the code from zlib and the zip add-on into your own code.
If you can't use their licence then get the specs and write your own clean room implementation - make sure that you haven't seen the zlib or zip code base though.
The other alternative is to bundle a freely available zip command line client and call it with a system() call
edit: if you mean you are already using zlib then minizip does the directory stuff - it's usually included with zlib in the contrib directory
You can use boost iostream which includes compression functionalities. Have a look at the documentation here: http://www.boost.org/doc/libs/1_46_1/libs/iostreams/doc/index.html
It seems that in fact in this case that won't work for a directory of files.