How do I create/write a TAR file in OCaml? I know there is the ocaml_tar module, but I couldn't find any examples on how to create/write a TAR file. How do I do it in OCaml?
There is Archive.create to create an archive on a file descriptor (if you want to create a file, use Unix.openfile), to read a file, you have with_next_filefd f where the callback f should use the Header.t to know the length of the data to read. If you just want to extract the content to files, just use extract.
A workaround is to use the existing tar tool of Linux, or relevant tools in Windows. For example, tar -zcvf data.tgz *.doc
And you can use functions in the Sys library to create a system call to the tool tar.
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 new to Python and trying to read .tar.Z file name and trying to list the file names compressed inside it. I just need to know the file name and size. I am using Python 2.7. I am able to do it with .tar file. Can somebody explain that with an example?
Thanks
The compress command and its .Z files is so antiquated that Python doesn't support it directly (and likely never did).
I suggest
#!/bin/sh
for i in *.tar.Z; do
tarname=`basename "$i" .Z`
uncompress "$i"
gzip "$tarname"
done
Then you can just open the tarfiles as shown in the documentation with the 'r:gz' mode.
If you don't want to migrate away from 1980s compress technology, then you should probably look into
zcat tarfile.tar.Z | tar tf -
using the subprocess module.
(For those who are tempted to say "but bzip2 is better" or "but xz is supported in Python 3", yeah, I agree, but gzip is simply more standard).
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.
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.
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.