1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
.\" -*- mode: troff; coding: utf-8 -*-
.\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
.ie n \{\
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds C`
. ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
. if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{\
. nr % 0
. nr F 2
. \}
. \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "Archive::Tar::File 3perl"
.TH Archive::Tar::File 3perl 2024-02-11 "perl v5.38.2" "Perl Programmers Reference Guide"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH NAME
Archive::Tar::File \- a subclass for in\-memory extracted file from Archive::Tar
.SH SYNOPSIS
.IX Header "SYNOPSIS"
.Vb 1
\& my @items = $tar\->get_files;
\&
\& print $_\->name, \*(Aq \*(Aq, $_\->size, "\en" for @items;
\&
\& print $object\->get_content;
\& $object\->replace_content(\*(Aqnew content\*(Aq);
\&
\& $object\->rename( \*(Aqnew/full/path/to/file.c\*(Aq );
.Ve
.SH DESCRIPTION
.IX Header "DESCRIPTION"
Archive::Tar::Files provides a neat little object layer for in-memory
extracted files. It's mostly used internally in Archive::Tar to tidy
up the code, but there's no reason users shouldn't use this API as
well.
.SS Accessors
.IX Subsection "Accessors"
A lot of the methods in this package are accessors to the various
fields in the tar header:
.IP name 4
.IX Item "name"
The file's name
.IP mode 4
.IX Item "mode"
The file's mode
.IP uid 4
.IX Item "uid"
The user id owning the file
.IP gid 4
.IX Item "gid"
The group id owning the file
.IP size 4
.IX Item "size"
File size in bytes
.IP mtime 4
.IX Item "mtime"
Modification time. Adjusted to mac-time on MacOS if required
.IP chksum 4
.IX Item "chksum"
Checksum field for the tar header
.IP type 4
.IX Item "type"
File type \-\- numeric, but comparable to exported constants \-\- see
Archive::Tar's documentation
.IP linkname 4
.IX Item "linkname"
If the file is a symlink, the file it's pointing to
.IP magic 4
.IX Item "magic"
Tar magic string \-\- not useful for most users
.IP version 4
.IX Item "version"
Tar version string \-\- not useful for most users
.IP uname 4
.IX Item "uname"
The user name that owns the file
.IP gname 4
.IX Item "gname"
The group name that owns the file
.IP devmajor 4
.IX Item "devmajor"
Device major number in case of a special file
.IP devminor 4
.IX Item "devminor"
Device minor number in case of a special file
.IP prefix 4
.IX Item "prefix"
Any directory to prefix to the extraction path, if any
.IP raw 4
.IX Item "raw"
Raw tar header \-\- not useful for most users
.SH Methods
.IX Header "Methods"
.ie n .SS "Archive::Tar::File\->new( file => $path )"
.el .SS "Archive::Tar::File\->new( file => \f(CW$path\fP )"
.IX Subsection "Archive::Tar::File->new( file => $path )"
Returns a new Archive::Tar::File object from an existing file.
.PP
Returns undef on failure.
.ie n .SS "Archive::Tar::File\->new( data => $path, $data, $opt )"
.el .SS "Archive::Tar::File\->new( data => \f(CW$path\fP, \f(CW$data\fP, \f(CW$opt\fP )"
.IX Subsection "Archive::Tar::File->new( data => $path, $data, $opt )"
Returns a new Archive::Tar::File object from data.
.PP
\&\f(CW$path\fR defines the file name (which need not exist), \f(CW$data\fR the
file contents, and \f(CW$opt\fR is a reference to a hash of attributes
which may be used to override the default attributes (fields in the
tar header), which are described above in the Accessors section.
.PP
Returns undef on failure.
.ie n .SS "Archive::Tar::File\->new( chunk => $chunk )"
.el .SS "Archive::Tar::File\->new( chunk => \f(CW$chunk\fP )"
.IX Subsection "Archive::Tar::File->new( chunk => $chunk )"
Returns a new Archive::Tar::File object from a raw 512\-byte tar
archive chunk.
.PP
Returns undef on failure.
.ie n .SS "$bool = $file\->extract( [ $alternative_name ] )"
.el .SS "\f(CW$bool\fP = \f(CW$file\fP\->extract( [ \f(CW$alternative_name\fP ] )"
.IX Subsection "$bool = $file->extract( [ $alternative_name ] )"
Extract this object, optionally to an alternative name.
.PP
See \f(CW\*(C`Archive::Tar\->extract_file\*(C'\fR for details.
.PP
Returns true on success and false on failure.
.ie n .SS "$path = $file\->full_path"
.el .SS "\f(CW$path\fP = \f(CW$file\fP\->full_path"
.IX Subsection "$path = $file->full_path"
Returns the full path from the tar header; this is basically a
concatenation of the \f(CW\*(C`prefix\*(C'\fR and \f(CW\*(C`name\*(C'\fR fields.
.ie n .SS "$bool = $file\->validate"
.el .SS "\f(CW$bool\fP = \f(CW$file\fP\->validate"
.IX Subsection "$bool = $file->validate"
Done by Archive::Tar internally when reading the tar file:
validate the header against the checksum to ensure integer tar file.
.PP
Returns true on success, false on failure
.ie n .SS "$bool = $file\->has_content"
.el .SS "\f(CW$bool\fP = \f(CW$file\fP\->has_content"
.IX Subsection "$bool = $file->has_content"
Returns a boolean to indicate whether the current object has content.
Some special files like directories and so on never will have any
content. This method is mainly to make sure you don't get warnings
for using uninitialized values when looking at an object's content.
.ie n .SS "$content = $file\->get_content"
.el .SS "\f(CW$content\fP = \f(CW$file\fP\->get_content"
.IX Subsection "$content = $file->get_content"
Returns the current content for the in-memory file
.ie n .SS "$cref = $file\->get_content_by_ref"
.el .SS "\f(CW$cref\fP = \f(CW$file\fP\->get_content_by_ref"
.IX Subsection "$cref = $file->get_content_by_ref"
Returns the current content for the in-memory file as a scalar
reference. Normal users won't need this, but it will save memory if
you are dealing with very large data files in your tar archive, since
it will pass the contents by reference, rather than make a copy of it
first.
.ie n .SS "$bool = $file\->replace_content( $content )"
.el .SS "\f(CW$bool\fP = \f(CW$file\fP\->replace_content( \f(CW$content\fP )"
.IX Subsection "$bool = $file->replace_content( $content )"
Replace the current content of the file with the new content. This
only affects the in-memory archive, not the on-disk version until
you write it.
.PP
Returns true on success, false on failure.
.ie n .SS "$bool = $file\->rename( $new_name )"
.el .SS "\f(CW$bool\fP = \f(CW$file\fP\->rename( \f(CW$new_name\fP )"
.IX Subsection "$bool = $file->rename( $new_name )"
Rename the current file to \f(CW$new_name\fR.
.PP
Note that you must specify a Unix path for \f(CW$new_name\fR, since per tar
standard, all files in the archive must be Unix paths.
.PP
Returns true on success and false on failure.
.ie n .SS "$bool = $file\->chmod $mode)"
.el .SS "\f(CW$bool\fP = \f(CW$file\fP\->chmod \f(CW$mode\fP)"
.IX Subsection "$bool = $file->chmod $mode)"
Change mode of \f(CW$file\fR to \f(CW$mode\fR. The mode can be a string or a number
which is interpreted as octal whether or not a leading 0 is given.
.PP
Returns true on success and false on failure.
.ie n .SS "$bool = $file\->chown( $user [, $group])"
.el .SS "\f(CW$bool\fP = \f(CW$file\fP\->chown( \f(CW$user\fP [, \f(CW$group\fP])"
.IX Subsection "$bool = $file->chown( $user [, $group])"
Change owner of \f(CW$file\fR to \f(CW$user\fR. If a \f(CW$group\fR is given that is changed
as well. You can also pass a single parameter with a colon separating the
use and group as in 'root:wheel'.
.PP
Returns true on success and false on failure.
.SH "Convenience methods"
.IX Header "Convenience methods"
To quickly check the type of a \f(CW\*(C`Archive::Tar::File\*(C'\fR object, you can
use the following methods:
.ie n .IP $file\->is_file 4
.el .IP \f(CW$file\fR\->is_file 4
.IX Item "$file->is_file"
Returns true if the file is of type \f(CW\*(C`file\*(C'\fR
.ie n .IP $file\->is_dir 4
.el .IP \f(CW$file\fR\->is_dir 4
.IX Item "$file->is_dir"
Returns true if the file is of type \f(CW\*(C`dir\*(C'\fR
.ie n .IP $file\->is_hardlink 4
.el .IP \f(CW$file\fR\->is_hardlink 4
.IX Item "$file->is_hardlink"
Returns true if the file is of type \f(CW\*(C`hardlink\*(C'\fR
.ie n .IP $file\->is_symlink 4
.el .IP \f(CW$file\fR\->is_symlink 4
.IX Item "$file->is_symlink"
Returns true if the file is of type \f(CW\*(C`symlink\*(C'\fR
.ie n .IP $file\->is_chardev 4
.el .IP \f(CW$file\fR\->is_chardev 4
.IX Item "$file->is_chardev"
Returns true if the file is of type \f(CW\*(C`chardev\*(C'\fR
.ie n .IP $file\->is_blockdev 4
.el .IP \f(CW$file\fR\->is_blockdev 4
.IX Item "$file->is_blockdev"
Returns true if the file is of type \f(CW\*(C`blockdev\*(C'\fR
.ie n .IP $file\->is_fifo 4
.el .IP \f(CW$file\fR\->is_fifo 4
.IX Item "$file->is_fifo"
Returns true if the file is of type \f(CW\*(C`fifo\*(C'\fR
.ie n .IP $file\->is_socket 4
.el .IP \f(CW$file\fR\->is_socket 4
.IX Item "$file->is_socket"
Returns true if the file is of type \f(CW\*(C`socket\*(C'\fR
.ie n .IP $file\->is_longlink 4
.el .IP \f(CW$file\fR\->is_longlink 4
.IX Item "$file->is_longlink"
Returns true if the file is of type \f(CW\*(C`LongLink\*(C'\fR.
Should not happen after a successful \f(CW\*(C`read\*(C'\fR.
.ie n .IP $file\->is_label 4
.el .IP \f(CW$file\fR\->is_label 4
.IX Item "$file->is_label"
Returns true if the file is of type \f(CW\*(C`Label\*(C'\fR.
Should not happen after a successful \f(CW\*(C`read\*(C'\fR.
.ie n .IP $file\->is_unknown 4
.el .IP \f(CW$file\fR\->is_unknown 4
.IX Item "$file->is_unknown"
Returns true if the file type is \f(CW\*(C`unknown\*(C'\fR
|