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.
Related
I need to compress the all of the contents of a directory into a single lz4 archive, i couldn't figure out a way to do that. I already have read all the available parameters, still no success. Kindly suggest me how can i achieve this.
Things like lz4, gzip, bzip2, and xz simply compress a stream of bytes. You need another utility, like tar, to convert a set of directories and files into a stream of bytes. The output of tar is then fed to the compressor. That's why you see archives with names like tar.gz or tar.xz.
How to use tar with lz4?
I am trying to compress a folder with Brotli(0.5.2) command line on Ubuntu 15.10
~/brotli-0.5.2$ ./bro -f -i ./dec/ -o folder.br
Then get error message:
failed to read input
Does anyone know how to compress folder with brotli?
Thanks.
brotli can only compress a file or a single stream of data. Just like gzip, xz, lzip, etc. To compress a directory, you would do what all archivers do, which is to convert the information in the directory into a single stream of data and write that to a file.
You did not provide a clue to your operating system in the question or tags, but on Unix-like systems, tar is used to take a directory and all of its contents in files, subdirectories, symbolic links, etc., and convert those to a single stream of data. Then you can use bro on that, as you would use any other compressor gzip, xz, etc. on it.
I'm using zlib and C++ to compress/decompress files.
I can now deflate any file and put it to .z extension. But when inflating .z file I have to manually put the needed extension. Inflating works as it should and I can easily inflate .z file to stdout or file.
I 've read zlib manual but couldn't manage, how to solve my problem. I suppose I need to dig the archive's header for this information?
Any help would be appreciated, thanks!
The zlib library will compress and decompress both zlib and gzip streams. zlib streams have very compact header and trailer with no provision to store file name information. The gzip header and trailer on the other hand can store a file name, which can be used when decompressing. You should read the zlib documentation to see how to use the gzip format, and how to process the gzip header.
I have seen the example in valadoc.com for one file, but is any way to compress a list of files into only compressed package?
Thanks.
GZip does not support doing that. You probably want to make a tar archive which is then compressed with gzip. In that case, use libarchive, for which there are Vala bindings.
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.