]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/tarstrm.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxTar* classes
4 // Author: wxWidgets team
5 // Licence: wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
9 /** wxTarEntry::GetTypeFlag() values */
12 wxTAR_REGTYPE
= '0', //!< regular file
13 wxTAR_LNKTYPE
= '1', //!< hard link
14 wxTAR_SYMTYPE
= '2', //!< symbolic link
15 wxTAR_CHRTYPE
= '3', //!< character special
16 wxTAR_BLKTYPE
= '4', //!< block special
17 wxTAR_DIRTYPE
= '5', //!< directory
18 wxTAR_FIFOTYPE
= '6', //!< named pipe
19 wxTAR_CONTTYPE
= '7' //!< contiguous file
22 /** Archive Formats (use wxTAR_PAX, it's backward compatible) used by wxTarEntry */
25 wxTAR_USTAR
, //!< POSIX.1-1990 tar format
26 wxTAR_PAX
//!< POSIX.1-2001 tar format
31 @class wxTarInputStream
33 Input stream for reading tar files.
35 wxTarInputStream::GetNextEntry() returns a wxTarEntry object containing the
36 meta-data for the next entry in the tar (and gives away ownership).
37 Reading from the wxTarInputStream then returns the entry's data.
38 wxTarInputStream::Eof() becomes @true after an attempt has been made to read
39 past the end of the entry's data.
41 When there are no more entries, wxTarInputStream::GetNextEntry() returns @NULL
42 and sets wxTarInputStream::Eof().
44 Tar entries are seekable if the parent stream is seekable. In practice this
45 usually means they are only seekable if the tar is stored as a local file and
49 @category{archive,streams}
51 @see @ref overview_archive_byname
53 class wxTarInputStream
: public wxArchiveInputStream
58 Constructor. In a Unicode build the second parameter @a conv is
59 used to translate fields from the standard tar header into Unicode.
61 It has no effect on the stream's data. @a conv is only used for the standard
62 tar headers, any pax extended headers are always UTF-8 encoded.
64 If the parent stream is passed as a pointer then the new filter stream
65 takes ownership of it. If it is passed by reference then it does not.
67 wxTarInputStream(wxInputStream
& stream
,
68 wxMBConv
& conv
= wxConvLocal
);
69 wxTarInputStream(wxInputStream
* stream
,
70 wxMBConv
& conv
= wxConvLocal
);
74 Closes the current entry.
75 On a non-seekable stream reads to the end of the current entry first.
80 Closes the current entry if one is open, then reads the meta-data for
81 the next entry and returns it in a wxTarEntry object, giving away ownership.
82 The stream is then open and can be read.
84 wxTarEntry
* GetNextEntry();
87 Closes the current entry if one is open, then opens the entry specified
88 by the @a entry object.
90 @a entry should be from the same tar file, and the tar should be on a
93 bool OpenEntry(wxTarEntry
& entry
);
99 @class wxTarClassFactory
101 Class factory for the tar archive format.
102 See the base class for details.
105 @category{archive,streams}
107 @see @ref overview_archive, @ref overview_archive_generic,
108 wxTarEntry, wxTarInputStream, wxTarOutputStream
110 class wxTarClassFactory
: public wxArchiveClassFactory
119 @class wxTarOutputStream
121 Output stream for writing tar files.
123 wxTarOutputStream::PutNextEntry() is used to create a new entry in the output tar,
124 then the entry's data is written to the wxTarOutputStream.
125 Another call to wxTarOutputStream::PutNextEntry() closes the current entry
131 @see @ref overview_archive, wxTarEntry, wxTarInputStream
133 class wxTarOutputStream
: public wxArchiveOutputStream
138 If the parent stream is passed as a pointer then the new filter stream
139 takes ownership of it. If it is passed by reference then it does not.
141 In a Unicode build the third parameter @a conv is used to translate the
142 headers fields into an 8-bit encoding. It has no effect on the stream's data.
144 When the @a format is @e wxTAR_PAX, pax extended headers are generated
145 when any header field will not fit the standard tar header block or if it
146 uses any non-ascii characters.
148 Extended headers are stored as extra 'files' within the tar, and will be
149 extracted as such by any other tar program that does not understand them.
150 The @a conv parameter only affect the standard tar headers, the extended
151 headers are always UTF-8 encoded.
153 When the @a format is @e wxTAR_USTAR, no extended headers are generated,
154 and instead a warning message is logged if any header field overflows.
156 wxTarOutputStream(wxOutputStream
& stream
,
157 wxTarFormat format
= wxTAR_PAX
,
158 wxMBConv
& conv
= wxConvLocal
);
159 wxTarOutputStream(wxOutputStream
* stream
,
160 wxTarFormat format
= wxTAR_PAX
,
161 wxMBConv
& conv
= wxConvLocal
);
165 The destructor calls Close() to finish writing the tar if it has
166 not been called already.
168 virtual ~wxTarOutputStream();
171 Finishes writing the tar, returning @true if successful.
172 Called by the destructor if not called explicitly.
177 Close the current entry.
179 It is called implicitly whenever another new entry is created with
180 CopyEntry() or PutNextEntry(), or when the tar is closed.
185 See wxArchiveOutputStream::CopyArchiveMetaData().
186 For the tar format this function does nothing.
188 bool CopyArchiveMetaData(wxTarInputStream
& s
);
191 Takes ownership of @a entry and uses it to create a new entry in the tar.
192 @a entry is then opened in @a inputStream and its contents copied to this stream.
194 For some other archive formats CopyEntry() is much more efficient than
195 transferring the data using Read() and Write() since it will copy them
196 without decompressing and recompressing them.
197 For tar however it makes no difference.
199 For tars on seekable streams, @a entry must be from the same tar file
200 as @a inputStream. For non-seekable streams, @a entry must also be the
201 last thing read from @a inputStream.
203 bool CopyEntry(wxTarEntry
* entry
, wxTarInputStream
& inputStream
);
207 The tar is zero padded to round its size up to @e BlockingFactor * 512 bytes.
209 The blocking factor defaults to 10 for @e wxTAR_PAX and 20 for @e wxTAR_USTAR
210 (see wxTarOutputStream()), as specified in the POSIX standards.
212 int GetBlockingFactor() const;
213 void SetBlockingFactor(int factor
);
217 Create a new directory entry (see wxArchiveEntry::IsDir()) with the given
220 PutNextEntry() can also be used to create directory entries, by supplying
221 a name with a trailing path separator.
223 bool PutNextDirEntry(const wxString
& name
, const wxDateTime
& dt
= wxDateTime::Now());
226 Takes ownership of entry and uses it to create a new entry in the tar.
228 bool PutNextEntry(wxTarEntry
* entry
);
231 Create a new entry with the given name, timestamp and size.
233 bool PutNextEntry(const wxString
& name
, const wxDateTime
& dt
= wxDateTime::Now(),
234 wxFileOffset size
= wxInvalidOffset
);
242 Holds the meta-data for an entry in a tar.
244 @section tarentry_fields Field availability
246 The tar format stores all the meta-data for an entry ahead of its data,
247 therefore GetNextEntry() always returns a fully populated wxTarEntry object,
248 both when reading from seekable and non-seekable streams.
251 @category{archive,streams}
253 @see @ref overview_archive, wxTarInputStream, wxTarOutputStream
255 class wxTarEntry
: public wxArchiveEntry
261 The tar archive format stores the entry's size ahead of the entry's data.
262 Therefore when creating an archive on a non-seekable stream it is necessary
263 to supply the correct size when each entry is created.
265 wxTarEntry(const wxString
& name
= wxEmptyString
,
266 const wxDateTime
& dt
= wxDateTime::Now(),
267 wxFileOffset size
= wxInvalidOffset
);
272 wxTarEntry(const wxTarEntry
& entry
);
276 Gets/sets the entry's access time stamp.
277 See also wxArchiveEntry::GetDateTime() and wxArchiveEntry::SetDateTime().
279 wxDateTime
GetAccessTime() const;
280 void SetAccessTime(const wxDateTime
& dt
);
285 The entry's creation time stamp.
286 See also wxArchiveEntry::GetDateTime() and wxArchiveEntry::SetDateTime().
288 wxDateTime
GetCreateTime() const;
289 void SetCreateTime(const wxDateTime
& dt
);
294 OS specific IDs defining a device; these are only meaningful when
295 wxTarEntry::GetTypeFlag() is @e wxTAR_CHRTYPE or @e wxTAR_BLKTYPE.
297 int GetDevMajor() const;
298 int GetDevMinor() const;
299 void SetDevMajor(int dev
);
300 void SetDevMinor(int dev
);
305 The user ID and group ID that has permissions (see wxTarEntry::GetMode())
308 These values aren't usually useful unless the file will only be
309 restored to the same system it originated from.
310 wxTarEntry::GetGroupName() and wxTarEntry::GetUserName() can be used instead.
312 int GetGroupId() const;
313 int GetUserId() const;
314 void SetGroupId(int id
);
315 void SetUserId(int id
);
320 The names of the user and group that has permissions (see wxTarEntry::GetMode())
321 over this entry. These are not present in very old tars.
323 wxString
GetGroupName() const;
324 wxString
GetUserName() const;
325 void SetGroupName(const wxString
& group
);
326 void SetUserName(const wxString
& user
);
331 The filename of a previous entry in the tar that this entry is a link to.
332 Only meaningful when wxTarEntry::GetTypeFlag() is set to @e wxTAR_LNKTYPE
335 wxString
GetLinkName() const;
336 void SetLinkName(const wxString
& link
);
341 UNIX permission bits for this entry.
342 Giving read, write and execute permissions to the file's user and group
343 (see GetGroupName() and GetUserName()) and to others.
345 The integer is one or more ::wxPosixPermissions flags OR-combined.
348 void SetMode(int mode
);
353 The size of the entry's data in bytes.
355 The tar archive format stores the entry's size ahead of the entry's data.
356 Therefore when creating an archive on a non-seekable stream it is necessary to
357 supply the correct size when each entry is created.
359 For seekable streams this is not necessary as wxTarOutputStream will attempt
360 to seek back and fix the entry's header when the entry is closed, though it is
361 still more efficient if the size is given beforehand.
363 void SetSize(wxFileOffset size
);
364 wxFileOffset
GetSize() const;
369 Returns/Sets the type of the entry as a ::wxTarType value.
371 When creating archives use only one of ::wxTarType values.
372 When reading archives, GetTypeFlag() may return a value which does not
373 match any value of ::wxTarType; in this case the returned value should be
374 treated as @e wxTAR_REGTYPE.
376 int GetTypeFlag() const;
377 void SetTypeFlag(int type
);
381 Returns the entry's filename in the internal format used within the archive.
383 The name can include directory components, i.e. it can be a full path.
384 The names of directory entries are returned without any trailing path separator.
385 This gives a canonical name that can be used in comparisons.
387 wxString
GetInternalName() const;
390 A static member that translates a filename into the internal format used
393 If the third parameter is provided, the bool pointed to is set to indicate
394 whether the name looks like a directory name (i.e. has a trailing path separator).
396 static wxString
GetInternalName(const wxString
& name
,
397 wxPathFormat format
= wxPATH_NATIVE
,
398 bool* pIsDir
= NULL
);
403 wxTarEntry
& operator operator=(const wxTarEntry
& entry
);