discourse-legacysite-perl/site/glist/templates/help/GT/Tar.html
2024-06-17 22:24:05 +10:00

442 lines
10 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>GT::Tar - Perl module to manipulate tar files.</title>
<link rev="made" href="mailto:root@penguin.office.gossamer-threads.com" />
<style type="text/css">
/* $MVD$:fontset("Untitled Font Set 1","ARIEL","HELVETICA","HELV","SANSERIF") */
/* $MVD$:fontset("Arial","Arial") */
/* $MVD$:fontset("Arial Black","Arial Black") */
/* $MVD$:fontset("Algerian","Algerian") */
body {
background-color: white;
font-family: Verdana, Arial, sans-serif;
font-size: small;
color: black;
}
p {
background-color : white;
font-family : Verdana, Arial, sans-serif;
font-size : small;
color : black;
}
h1 {
font-family : Verdana, Arial, sans-serif;
font-weight : bold;
font-size : medium;
background-color : white;
color : maroon;
}
h2 {
font-family : Verdana, Arial, sans-serif;
font-size : medium;
font-weight : bold;
color : blue;
background-color : white;
}
h3 {
font-family : Verdana, Arial, sans-serif;
font-weight : bold;
font-size : medium;
color : black;
background-color : white;
}
h4 {
font-family : Verdana, Arial, sans-serif;
font-weight : bold;
font-size : small;
color : maroon;
background-color : white;
}
h5 {
font-family : Verdana, Arial, sans-serif;
font-weight : bold;
font-size : small;
color : blue;
background-color : white;
}
h6 {
font-family : Verdana, Arial, sans-serif;
font-weight : bold;
font-size : small;
color : black;
background-color : white;
}
ul {
font-family : Verdana, Arial, sans-serif;
font-size : small;
color : black;
}
ol {
font-family : Verdana, Arial, sans-serif;
font-size : small;
color : black;
}
dl {
font-family : Verdana, Arial, sans-serif;
font-size : small;
color : black;
}
li {
font-family : Verdana, Arial, sans-serif;
font-size : small;
color : black;
}
th {
font-family : Verdana, Arial, sans-serif;
font-size : small;
color : black;
}
td {
font-family : Verdana, Arial, sans-serif;
font-size : small;
color : black;
}
dl {
font-family : Verdana, Arial, sans-serif;
font-size : small;
color : black;
}
dd {
font-family : Verdana, Arial, sans-serif;
font-size : small;
color : black;
}
dt {
font-family : Verdana, Arial, sans-serif;
font-size : small;
color : black;
}
code {
font-family : Courier;
font-size : small;
color : black;
}
pre {
font-family : Courier;
font-size : small;
color : black;
}
.mvd-H1 {
font-family : Verdana, Arial, sans-serif;
font-weight : bold;
font-size : 14.0pt;
background-color : transparent;
background-image : none;
color : maroon;
}
.mvd-H2 {
font-family : Verdana, Arial, sans-serif;
font-size : 12.0pt;
color : blue;
}
p.indent {
font-family : "Verdana, Arial, sans-serif";
list-style-type : circle;
list-style-position : inside;
color : black;
margin-left : 16.0pt;
}
.mvd-P-indent {
font-family : Verdana, Arial, sans-serif;
list-style-type : circle;
list-style-position : inside;
color : black;
margin-left : 16.0pt;
}
pre.programlisting {
font-size : 9.0pt;
list-style-type : disc;
margin-left : 16.0pt;
margin-top : -14.0pt;
}
.mvd-PRE-programlisting {
font-size : 9.0pt;
list-style-type : disc;
margin-left : 16.0pt;
margin-top : -14.0pt;
}
.mvd-PRE {
font-size : 9.0pt;
}
p.note {
margin-left : 28.0pt;
}
.mvd-P-note {
margin-left : 28.0pt;
}
.mvd-H4 {
font-family : Verdana, Arial, sans-serif;
font-weight : normal;
font-size : 9.0pt;
color : black;
margin-left : 6.0pt;
margin-top : -14.0pt;
}
.mvd-P {
font-family : Verdana, Arial, sans-serif;
font-size : 10.0pt;
color : black;
}
.mvd-BODY {
font-family : Verdana, Arial, sans-serif;
background-color : white;
}
p.indentnobullet {
font-family : Verdana, Arial, sans-serif;
list-style-type : none;
}
.mvd-P-indentnobullet {
font-family : Verdana, Arial, sans-serif;
list-style-type : none;
}
</style>
</head>
<body style="background-color: white">
<p><a name="__index__"></a></p>
<!-- INDEX BEGIN -->
<ul>
<li><a href="#name">NAME</a></li>
<li><a href="#synopsis">SYNOPSIS</a></li>
<li><a href="#description">DESCRIPTION</a></li>
<ul>
<li><a href="#creating_a_tar_file">Creating a tar file</a></li>
<li><a href="#opening_an_existing_tar_file">Opening an existing tar file</a></li>
<li><a href="#untarring_a_tar_file">Untarring a tar file</a></li>
<li><a href="#adding_files_to_a_tar_file">Adding files to a tar file</a></li>
<li><a href="#getting_a_list_of_files_in_a_tar">Getting a list of files in a tar</a></li>
<li><a href="#getting_an_individual_file_from_a_tar">Getting an individual file from a tar</a></li>
<li><a href="#removing_a_file_from_a_tar">Removing a file from a tar</a></li>
<li><a href="#gt__tar__part">GT::Tar::Part</a></li>
</ul>
<li><a href="#examples">EXAMPLES</a></li>
<li><a href="#copyright">COPYRIGHT</a></li>
<li><a href="#version">VERSION</a></li>
</ul>
<!-- INDEX END -->
<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>GT::Tar - Perl module to manipulate tar files.</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
use GT::Tar;
my $tar = GT::Tar-&gt;open('foo.tar');
$tar-&gt;add_file( '/path/to/file' );
$tar-&gt;write;</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>GT::Tar provides an OO intefrace to a tar file. It allows you to create or edit
tar files, and if you have Compress::Zlib installed, it allows you to work with
.tar.gz files as well!</p>
<p>
</p>
<h2><a name="creating_a_tar_file">Creating a tar file</a></h2>
<p>To create a tar file, you simply call:</p>
<pre>
my $tar = new GT::Tar;</pre>
<p>and then to save it:</p>
<pre>
$tar-&gt;write('filename.tar');</pre>
<p>will save the tar file and any files you have added.</p>
<p>
</p>
<h2><a name="opening_an_existing_tar_file">Opening an existing tar file</a></h2>
<p>To open a tar file you call:</p>
<pre>
my $tar = GT::Tar-&gt;open('/path/to/file.tar')
or die &quot;Can't open: $GT::Tar::error&quot;;</pre>
<p>Note: the tar object keeps an open filehandle to the file, so if you are on
windows, you may not be able to manipulate it until you call $tar-&gt;close_tar, or
the tar object goes out of scope.</p>
<p>
</p>
<h2><a name="untarring_a_tar_file">Untarring a tar file</a></h2>
<p>To untar a tar file, you can simply call:</p>
<pre>
$tar-&gt;untar( \&amp;code_ref );</pre>
<p>or as a class method</p>
<pre>
GT::Tar-&gt;untar('/path/to/tar.tar', \&amp;code_ref );</pre>
<p>The code ref is optional. If provided, you will get passed in the a
GT::Tar::Part object before the file is extracted. This lets you change the
path, or alter any attributes of the file before it is saved to disk.</p>
<p>Alternatively, instead of a code reference you may pass an extraction path - if
passed, all files will be extracted relative to that path.</p>
<p>
</p>
<h2><a name="adding_files_to_a_tar_file">Adding files to a tar file</a></h2>
<p>To add a file:</p>
<pre>
$tar-&gt;add_file( '/path/to/file' );</pre>
<p>Note, if you add a directory, the tar module will recurse and add all files in
that directory.</p>
<p>To add a file that isn't saved:</p>
<pre>
$tar-&gt;add_data( name =&gt; 'Filename', body =&gt; 'File body' );</pre>
<p>You can pass in either a scalar for the body, or an opened file handle.</p>
<p>
</p>
<h2><a name="getting_a_list_of_files_in_a_tar">Getting a list of files in a tar</a></h2>
<p>To get a list of files in a tar:</p>
<pre>
my $files = $tar-&gt;files;</pre>
<p>This returns an array ref of GT::Tar::Part objects. See below for how to access
information from a part.</p>
<p>Note: if you change a part, it will update the tar file if you save it.</p>
<p>
</p>
<h2><a name="getting_an_individual_file_from_a_tar">Getting an individual file from a tar</a></h2>
<p>If you know the name of the file you want:</p>
<pre>
my $file = $tar-&gt;get_file('Filename');</pre>
<p>will return a single GT::Tar::Part object.</p>
<p>
</p>
<h2><a name="removing_a_file_from_a_tar">Removing a file from a tar</a></h2>
<p>To remove a file, you need to know the name of it:</p>
<pre>
$tar-&gt;remove_file('Filename');
$tar-&gt;write;</pre>
<p>and you need to save it before the change will take affect.</p>
<p>
</p>
<h2><a name="gt__tar__part">GT::Tar::Part</a></h2>
<p>Each file is a separate part object. The part object has the following
attributes:</p>
<pre>
name file name
mode file permissions
uid user id
gid group id
size file size
mtime last modified time
type file type
body file body</pre>
<p>You can access or set any of these attributes by just using the attribute name
as the method (as it inherits from <a href="glist.cgi?do=admin_gtdoc&topic=/GT/Base.html">the GT::Base manpage</a>).</p>
<p>You can also call:</p>
<pre>
$file-&gt;write;</pre>
<p>or:</p>
<pre>
$file-&gt;write(&quot;/extraction/path&quot;)</pre>
<p>and the file will be created with the given attributes. Basically untar just
foreach's through each of the objects and calls <code>write()</code> on it.</p>
<p>
</p>
<hr />
<h1><a name="examples">EXAMPLES</a></h1>
<p>To create a new tar and add two directories to it, and save it in
'/tmp/foo.tar';</p>
<pre>
my $tar = new GT::Tar;
$tar-&gt;add_file( '/home/httpd/html' );
$tar-&gt;add_file( '/home/backup' );
$tar-&gt;write('/tmp/foo.tar');</pre>
<p>To open an existing tar file and save all the .pl files in /home/alex.</p>
<pre>
my $tar = GT::Tar-&gt;open('files.tar');
my $files = $tar-&gt;files;
foreach my $file (@$files) {
my $name = $file-&gt;name;
if ($name =~ m,[^/]*\.pl$,) {
$file-&gt;write(&quot;/home/alex&quot;);
}
}</pre>
<p>
</p>
<hr />
<h1><a name="copyright">COPYRIGHT</a></h1>
<p>Copyright (c) 2004 Gossamer Threads Inc. All Rights Reserved.
<a href="http://www.gossamer-threads.com/">http://www.gossamer-threads.com/</a></p>
<p>
</p>
<hr />
<h1><a name="version">VERSION</a></h1>
<p>Revision: $Id: Tar.pm,v 1.54 2005/03/09 01:26:17 jagerman Exp $</p>
</body>
</html>