-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathReadme.htm
309 lines (303 loc) · 18.1 KB
/
Readme.htm
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<html>
<head>
<meta http-equiv="Content-Language" content="de">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>LibTar</title>
</head>
<body>
<h1><font face="Verdana">LibTar</font></h1>
<p><font face="Verdana" size="2">Native ObjectPascal Library for accessing <b>tar</b> (<i>T</i>ape
<i>Ar</i>chive) files</font></p>
<p><font face="Verdana" size="2">Author: Stefan Heymann, E-Mail <a href="mailto:stefan@destructor.de">stefan@destructor.de</a></font></p>
<h2><font face="Verdana">Purpose</font></h2>
<p><font face="Verdana" size="2">LibTar is a Library which contains the ObjectPascal class <b>TTarArchive.</b>
Using this class, you can read the contents (Directory entries and file contents) of a tar file.</font></p>
<h2><font face="Verdana">About <i>tar</i></font></h2>
<p><font face="Verdana" size="2">tar is a format widely used on Unix and Linux systems.
"tar" is short for "Tape Archive". The format was intended primarily for use
with tape backup devices. However, tar files are also stored on disks. The common extension for
tar files is ".tar".</font></p>
<p><font face="Verdana" size="2">A tar file contains several files, making one file out of them.
There is no compression. The tar file just contains a directory entry for each file (which holds
information like the name of the file, size, last modified date, access permissions, etc.). and
the file itself.</font></p>
<h2><font face="Verdana">TTarArchive</font></h2>
<p><font face="Verdana" size="2">Using the TTarArchive class, you scan through the tar file,
thereby reading out the directory entries and – if you want – the files.</font></p>
<table border="0" cellpadding="3">
<tr>
<td bgcolor="#40C0C0" valign="top" align="left"><font size="2" face="Verdana"><b>Step</b></font></td>
<td bgcolor="#40C0C0" valign="top" align="left">
<font size="2" face="Verdana"><b>Code</b></font>
</td>
</tr>
<tr>
<td bgcolor="#9FDFDF" valign="top" align="left"><b><font face="Verdana" size="2"> Choose a constructor</font></b>
<p><font face="Verdana" size="2">You can either pass a TStream instance or a filename</font></td>
<td bgcolor="#9FDFDF" valign="top" align="left">
<pre>constructor Create (Stream : TStream); overload;
constructor Create (Filename : STRING); overload;
</pre>
</td>
</tr>
<tr>
<td bgcolor="#9FDFDF" valign="top" align="left"><b><font face="Verdana" size="2"> Make an instance of TTarArchive</font></b></td>
<td bgcolor="#9FDFDF" valign="top" align="left">
<pre>TA := TTarArchive.Create (Filename);</pre>
</td>
</tr>
<tr>
<td bgcolor="#9FDFDF" valign="top" align="left"><b><font face="Verdana" size="2">Prepare
your scan</font></b></td>
<td bgcolor="#9FDFDF" valign="top" align="left">
<pre>TA.Reset;</pre>
</td>
</tr>
<tr>
<td bgcolor="#9FDFDF" valign="top" align="left"><b><font face="Verdana" size="2">Scan
through the archive</font></b></td>
<td bgcolor="#9FDFDF" valign="top" align="left">
<pre>while TA.FindNext (DirRec) do begin</pre>
</td>
</tr>
<tr>
<td bgcolor="#9FDFDF" valign="top" align="left"><b><font face="Verdana" size="2"> Evaluate the DirRec for each file</font></b></td>
<td bgcolor="#9FDFDF" valign="top" align="left">
<pre> ListBox.Items.Add (DirRec.Name);</pre>
</td>
</tr>
<tr>
<td bgcolor="#9FDFDF" valign="top" align="left"><b><font face="Verdana" size="2"> Read out the current file</font></b>
<p><font face="Verdana" size="2">You can leave this step out if you don't want to read the
file</font></td>
<td bgcolor="#9FDFDF" valign="top" align="left">
<pre> TA.ReadFile (DestFilename);
END; </pre>
</td>
</tr>
<tr>
<td bgcolor="#9FDFDF" valign="top" align="left"><b><font face="Verdana" size="2">You're done</font></b></td>
<td bgcolor="#9FDFDF" valign="top" align="left">
<pre>TA.Free</pre>
</td>
</tr>
</table>
<h2><font face="Verdana">FindNext, TTarDirRec</font></h2>
<p><font face="Verdana" size="2">The <b>FindNext</b> function returns two values:</font></p>
<p><font face="Verdana" size="2">The function return value (boolean) is true, when there was
another file found in the archive and false when the end of the archive has been reached. So you
can use it in a "while FindNext () do" loop. Using this loop, you hop from file to
file, accessing one at a time.</font></p>
<p><font face="Verdana" size="2">There is a var parameter, named DirRec of type TTarDirRec. This
record gives all the informations about the current file in the archive has the following
fields:</font></p>
<div align="left">
<table border="0" cellpadding="3">
<tr>
<td bgcolor="#40C0C0" valign="top" align="left"><font face="Verdana" size="2"><b>Field Name</b></font></td>
<td bgcolor="#40C0C0" valign="top" align="left"><b><font face="Verdana" size="2">Content</font></b></td>
</tr>
<tr>
<td bgcolor="#9FDFDF" valign="top" align="left"><font face="Verdana" size="2"><b>Name</b></font></td>
<td bgcolor="#9FDFDF" valign="top" align="left"><font face="Verdana" size="2">The file's path and file name. The
path is usually divided with slash characters, because tar is a Unix format</font></td>
</tr>
<tr>
<td bgcolor="#9FDFDF" valign="top" align="left"><font face="Verdana" size="2"><b>Size</b></font></td>
<td bgcolor="#9FDFDF" valign="top" align="left"><font face="Verdana" size="2">The size of the file in bytes</font></td>
</tr>
<tr>
<td bgcolor="#9FDFDF" valign="top" align="left"><font face="Verdana" size="2"><b>DateTime</b></font></td>
<td bgcolor="#9FDFDF" valign="top" align="left"><font face="Verdana" size="2">Last last modification date and time.
Note that this time is given in UTC (GMT). You must probably convert it to your local
time before using it for comparisons.</font></td>
</tr>
<tr>
<td bgcolor="#9FDFDF" valign="top" align="left"><font face="Verdana" size="2"><b>Permissions</b></font></td>
<td bgcolor="#9FDFDF" valign="top" align="left"><font size="2" face="Verdana">A set telling who had which access
rights to the file at the time it was written to the archive:</font>
<div align="left">
<table border="0" cellpadding="3">
<tr>
<td valign="top" align="left" bgcolor="#C5EBEB"><font size="2" face="Verdana">tpReadByOwner,<br>
tpWriteByOwner,<br>
tpExecuteByOwner</font></td>
<td valign="top" align="left" bgcolor="#C5EBEB"><font face="Verdana" size="2">The file owner has
permission to read/write/execute it</font></td>
</tr>
<tr>
<td valign="top" align="left" bgcolor="#C5EBEB"><font size="2" face="Verdana">tpReadByGroup,<br>
tpWriteByGroup,<br>
tpExecuteByGroup</font></td>
<td valign="top" align="left" bgcolor="#C5EBEB"><font face="Verdana" size="2">The user's group has
permission to read/write/execute the file</font></td>
</tr>
<tr>
<td valign="top" align="left" bgcolor="#C5EBEB"><font size="2" face="Verdana"> tpReadByOther,<br>
tpWriteByOther,<br>
tpExecuteByOther</font></td>
<td valign="top" align="left" bgcolor="#C5EBEB"><font face="Verdana" size="2">All other users have
permission to read/write/execute the file</font></td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td bgcolor="#9FDFDF" valign="top" align="left"><font face="Verdana" size="2"><b>FileType</b></font></td>
<td bgcolor="#9FDFDF" valign="top" align="left"><font size="2" face="Verdana">The type of the file:</font>
<table border="0" cellpadding="3">
<tr>
<td valign="top" align="left" bgcolor="#40C0C0"><font size="2" face="Verdana"><b>TFileType</b></font></td>
<td valign="top" align="left" bgcolor="#40C0C0"><font size="2" face="Verdana"><b>Description</b></font></td>
</tr>
<tr>
<td valign="top" align="left" bgcolor="#C5EBEB"><font size="2" face="Verdana">ftNormal</font></td>
<td valign="top" align="left" bgcolor="#C5EBEB"><font size="2" face="Verdana">A regular file</font></td>
</tr>
<tr>
<td valign="top" align="left" bgcolor="#C5EBEB"><font size="2" face="Verdana">ftLink</font></td>
<td valign="top" align="left" bgcolor="#C5EBEB"><font size="2" face="Verdana">A link to another, previously archived, file. There is no data stored for a
link. The name of the file which the link refers to is stored in the
"LinkName" field of TTarDirRec</font></td>
</tr>
<tr>
<td valign="top" align="left" bgcolor="#C5EBEB"><font size="2" face="Verdana">ftSymbolicLink</font></td>
<td valign="top" align="left" bgcolor="#C5EBEB"><font size="2" face="Verdana">A symbolic link to another file. There is no data stored for a link. The name of
the file which the link refers to is stored in the "LinkName" field of
TTarDirRec</font></td>
</tr>
<tr>
<td valign="top" align="left" bgcolor="#C5EBEB"><font size="2" face="Verdana">ftCharacter, ftBlock</font></td>
<td valign="top" align="left" bgcolor="#C5EBEB"><font size="2" face="Verdana">Character/Block special files. Unix specific. Can be treated as a regular file
by other OSes</font></td>
</tr>
<tr>
<td valign="top" align="left" bgcolor="#C5EBEB"><font size="2" face="Verdana">ftDirectory</font></td>
<td valign="top" align="left" bgcolor="#C5EBEB"><font size="2" face="Verdana">A subdirectory entry. There is no data stored for a directory. The
"Size" field of TTarDirRec is zero (unlimited) or gives the maximum
number of bytes which may be stored in the directory.</font></td>
</tr>
<tr>
<td valign="top" align="left" bgcolor="#C5EBEB"><font size="2" face="Verdana">ftFifo</font></td>
<td valign="top" align="left" bgcolor="#C5EBEB"><font size="2" face="Verdana">FIFO special file. There is no data stored for a FIFO file.</font></td>
</tr>
<tr>
<td valign="top" align="left" bgcolor="#C5EBEB"><font size="2" face="Verdana">ftContiguous</font></td>
<td valign="top" align="left" bgcolor="#C5EBEB"><font size="2" face="Verdana">If supported by the OS, the file shall be stored in contiguous blocks of the
storage medium. Otherwise, it can be treated like a regular file.</font></td>
</tr>
<tr>
<td valign="top" align="left" bgcolor="#C5EBEB"><font size="2" face="Verdana">ftDumpDir</font></td>
<td valign="top" align="left" bgcolor="#C5EBEB"><font size="2" face="Verdana">This represents a directory and a list of files created by the -G option of tar.
The Size field gives the total size of the associated list of files. Each filename
is preceded by either a 'Y' (meaning the file should be in this archive) or an 'N'
(The file is a directory, or is not stored in the archive). Each filename is
terminated by a null. There is an additional null after the last filename.</font></td>
</tr>
<tr>
<td valign="top" align="left" bgcolor="#C5EBEB"><font size="2" face="Verdana">ftMultivolume</font></td>
<td valign="top" align="left" bgcolor="#C5EBEB"><font size="2" face="Verdana">This represents a file continued from another volume of a multi-volume archive
created with the -M option of tar. The original type of the file is not given
here. Size field gives the maximum size of this piece of the file (assuming the
volume does not end before the file is written out). The offset field gives the
offset from the beginning of the file where this part of the file begins. Thus
size plus offset should equal the original size of the file.</font></td>
</tr>
<tr>
<td valign="top" align="left" bgcolor="#C5EBEB"><font size="2" face="Verdana">ftVolumeHeader</font></td>
<td valign="top" align="left" bgcolor="#C5EBEB"><font size="2" face="Verdana">This file type is used to mark the volume header that was given with
the -V option when the archive was created. The Name field contains the name given after the
-V option. The Size field is zero. Only the first file in each volume of an archive should have this type.</font></td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="#9FDFDF" valign="top" align="left"><font size="2" face="Verdana"><b>LinkName</b></font></td>
<td bgcolor="#9FDFDF" valign="top" align="left"><font size="2" face="Verdana">If the
FileType is ftLink or ftSymbolicLink, the LinkName field contains the name of the file
where the link is going to.</font></td>
</tr>
<tr>
<td bgcolor="#9FDFDF" valign="top" align="left"><font size="2" face="Verdana"><b>UID, GID</b></font></td>
<td bgcolor="#9FDFDF" valign="top" align="left"><font size="2" face="Verdana">Numerical
User ID and Group ID</font></td>
</tr>
<tr>
<td bgcolor="#9FDFDF" valign="top" align="left"><font size="2" face="Verdana"><b>UserName,
GroupName</b></font></td>
<td bgcolor="#9FDFDF" valign="top" align="left"><font size="2" face="Verdana">User Name
and Group Name</font></td>
</tr>
<tr>
<td bgcolor="#9FDFDF" valign="top" align="left"><font size="2" face="Verdana"><b>CheckSumOK</b></font></td>
<td bgcolor="#9FDFDF" valign="top" align="left"><font size="2" face="Verdana">True, if the
checksum of the tar header was checked OK, false if not.</font></td>
</tr>
<tr>
<td bgcolor="#9FDFDF" valign="top" align="left"><font size="2" face="Verdana"><b>Mode</b></font></td>
<td bgcolor="#9FDFDF" valign="top" align="left"><font size="2" face="Verdana">I don't know
enough about tar to tell you what the heck this means. Sorry.</font></td>
</tr>
<tr>
<td bgcolor="#9FDFDF" valign="top" align="left"><font size="2" face="Verdana"><b>Magic</b></font></td>
<td bgcolor="#9FDFDF" valign="top" align="left"><font size="2" face="Verdana">Contains the
string in the "magic" field of the tar header. Possible values are 'ustar' and
'GNUtar'. If it is 'ustar', then the UserName and GroupName field can be considered
valid. If it is 'GNUtar' then there is a GNU format dump entry.</font></td>
</tr>
<tr>
<td bgcolor="#9FDFDF" valign="top" align="left"><font size="2" face="Verdana"><b>MajorDevNo,
MinorDevNo</b></font></td>
<td bgcolor="#9FDFDF" valign="top" align="left"><font size="2" face="Verdana">Major and
Minor Device Number for Files of type ftCharacter or ftBlock</font></td>
</tr>
<tr>
<td bgcolor="#9FDFDF" valign="top" align="left"><font size="2" face="Verdana"><b>FilePos</b></font></td>
<td bgcolor="#9FDFDF" valign="top" align="left"><font size="2" face="Verdana">The Position
in the tar file. This corresponds to the byte position of the first byte of the current
header record. You can use the "SetFilePos" method to return to this position
at any time later.</font></td>
</tr>
</table>
</div>
<h2><font face="Verdana">File Position</font></h2>
<p><font face="Verdana" size="2">There are several methods you can use to retrieve or set the
Current Position in the tar file during or after scanning:</font></p>
<ul>
<li><font face="Verdana" size="2">Every <i>TTarDirRec</i> contains a field <i>FilePos</i>
which contains the Current Position of the beginning of the corresponding tar header record.</font></li>
<li><font face="Verdana" size="2">You can call the <i>GetFilePos</i> method at any time to
retrieve the Current Position (Current) and the size (Size) of the whole tar file. Both
values are given in bytes. You could use these values for display of a progress bar. The
percentage is calculated:<br>
<code>Percent := Current * 100 DIV Size;</code></font></li>
<li><font face="Verdana" size="2">You can return to a position given by <i>TTarDirRec.FilePos</i>
or <i>GetFilePos</i> with the <i>SetFilePos</i> method. After the call to <i>SetFilePos,</i>
you must call <i>FindNext</i> to re-read the Directory record entry. After the call to <i>FindNext,</i>
you can read the file contents using a call to <i>ReadFile.</i></font></li>
</ul>
<h2><font face="Verdana">Source, Legals ("Licence")</font></h2>
<p><font face="Verdana" size="2">The official site to get this code is <a href="http://www.destructor.de"> http://www.destructor.de</a><br>
<br>
Usage and Distribution of this Source Code is ruled by the "Destructor.de Source code Licence" (DSL) which comes with this file or
can be downloaded at http://www.destructor.de<br>
<br>
IN SHORT: Usage and distribution of this source code is free. You use it completely on your own risk.</font></p>
<h2><font face="Verdana">Support</font></h2>
<p><font face="Verdana" size="2">Please send support requests to <a href="mailto:stefan@destructor.de">stefan@destructor.de</a>.
I'll do my best to help you.</font></p>
<h2><font face="Verdana">Postcardware</font></h2>
<p><font face="Verdana" size="2">If you like this code, please send a postcard of your city to my
address (anonymous if you want):</font></p>
<pre> Stefan Heymann
Eschenweg 3
72076 Tübingen
GERMANY</pre>
<hr>
<p><font face="Verdana" size="1" color="#808080">2001-04-28, Stefan Heymann</font></p>
</body>
</html>