Popular recipes tagged "tar"http://code.activestate.com/recipes/tags/tar/2013-05-28T04:02:15-07:00ActiveState Code Recipescar.py (Ctypes ARchiver in PYthon [libarchive ffi wrapper]) (Python) 2013-05-28T04:02:15-07:00Mike 'Fuzzy' Partinhttp://code.activestate.com/recipes/users/4179778/http://code.activestate.com/recipes/578531-carpy-ctypes-archiver-in-python-libarchive-ffi-wra/ <p style="color: grey"> Python recipe 578531 by <a href="/recipes/users/4179778/">Mike 'Fuzzy' Partin</a> (<a href="/recipes/tags/bzip2/">bzip2</a>, <a href="/recipes/tags/cpio/">cpio</a>, <a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/ffi/">ffi</a>, <a href="/recipes/tags/gzip/">gzip</a>, <a href="/recipes/tags/lzma/">lzma</a>, <a href="/recipes/tags/pax/">pax</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/tar/">tar</a>). Revision 3. </p> <p>CTypes libarchive wrapper, handles extraction only with no arguments.</p> Creating a tar archive (without using the tarfile module) (Python) 2010-10-11T06:18:42-07:00Benjamin Sergeanthttp://code.activestate.com/recipes/users/4039626/http://code.activestate.com/recipes/577422-creating-a-tar-archive-without-using-the-tarfile-m/ <p style="color: grey"> Python recipe 577422 by <a href="/recipes/users/4039626/">Benjamin Sergeant</a> (<a href="/recipes/tags/compression/">compression</a>, <a href="/recipes/tags/tar/">tar</a>, <a href="/recipes/tags/unix/">unix</a>). </p> <p>Creating a tar file is easy if you read the spec (you can look it up on wikipedia). Not every kind of files are supported (it support regular files, folders ans symlinks) and it's generating archives for the original tar file format (path length are limited to 100 chars, no extended attributes, ...). It wasn't tested very much but it was a fun hack :) ... I cheated just a little by looking at the python tarfile code from the stdlib for the checksum computation.</p> <p>A tar file is very simple, it's a list of header/payload for each entry (file|folder|symlink) you want to archive. There's only a payload for file contents. The header is 512 bytes long and can be written in ascii. Numbers (attributes) needs to be written in octal. The files themselves needs to be written in chunks of 512 bytes, which mean you have to fill the last chunk with zeros when the file size is not a multiple of 512 bytes.</p> <p>Use it like that: </p> <pre class="prettyprint"><code>python batar.py /tmp/foo.tar `find .` &amp;&amp; tar tf /tmp/foo.tar # or xf if you want to extract it </code></pre>