]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/tarstrm.h
2381dfd888b3e61bb909c15a21e3c7edb17b2648
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxTar* classes
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
10 /** wxTarEntry::GetTypeFlag() values */
13 wxTAR_REGTYPE
= '0', //!< regular file
14 wxTAR_LNKTYPE
= '1', //!< hard link
15 wxTAR_SYMTYPE
= '2', //!< symbolic link
16 wxTAR_CHRTYPE
= '3', //!< character special
17 wxTAR_BLKTYPE
= '4', //!< block special
18 wxTAR_DIRTYPE
= '5', //!< directory
19 wxTAR_FIFOTYPE
= '6', //!< named pipe
20 wxTAR_CONTTYPE
= '7' //!< contiguous file
23 /** Archive Formats (use wxTAR_PAX, it's backward compatible) used by wxTarEntry */
26 wxTAR_USTAR
, //!< POSIX.1-1990 tar format
27 wxTAR_PAX
//!< POSIX.1-2001 tar format
32 @class wxTarInputStream
34 Input stream for reading tar files.
36 wxTarInputStream::GetNextEntry() returns a wxTarEntry object containing the
37 meta-data for the next entry in the tar (and gives away ownership).
38 Reading from the wxTarInputStream then returns the entry's data.
39 wxTarInputStream::Eof() becomes @true after an attempt has been made to read
40 past the end of the entry's data.
42 When there are no more entries, wxTarInputStream::GetNextEntry() returns @NULL
43 and sets wxTarInputStream::Eof().
45 Tar entries are seekable if the parent stream is seekable. In practice this
46 usually means they are only seekable if the tar is stored as a local file and
50 @category{archive,streams}
52 @see @ref overview_archive_byname
54 class wxTarInputStream
: public wxArchiveInputStream
59 Constructor. In a Unicode build the second parameter @a conv is
60 used to translate fields from the standard tar header into Unicode.
62 It has no effect on the stream's data. @a conv is only used for the standard
63 tar headers, any pax extended headers are always UTF-8 encoded.
65 If the parent stream is passed as a pointer then the new filter stream
66 takes ownership of it. If it is passed by reference then it does not.
68 wxTarInputStream(wxInputStream
& stream
,
69 wxMBConv
& conv
= wxConvLocal
);
70 wxTarInputStream(wxInputStream
* stream
,
71 wxMBConv
& conv
= wxConvLocal
);
75 Closes the current entry.
76 On a non-seekable stream reads to the end of the current entry first.
81 Closes the current entry if one is open, then reads the meta-data for
82 the next entry and returns it in a wxTarEntry object, giving away ownership.
83 The stream is then open and can be read.
85 wxTarEntry
* GetNextEntry();
88 Closes the current entry if one is open, then opens the entry specified
89 by the @a entry object.
91 @a entry should be from the same tar file, and the tar should be on a
94 bool OpenEntry(wxTarEntry
& entry
);
100 @class wxTarClassFactory
102 Class factory for the tar archive format.
103 See the base class for details.
106 @category{archive,streams}
108 @see @ref overview_archive, @ref overview_archive_generic,
109 wxTarEntry, wxTarInputStream, wxTarOutputStream
111 class wxTarClassFactory
: public wxArchiveClassFactory
120 @class wxTarOutputStream
122 Output stream for writing tar files.
124 wxTarOutputStream::PutNextEntry() is used to create a new entry in the output tar,
125 then the entry's data is written to the wxTarOutputStream.
126 Another call to wxTarOutputStream::PutNextEntry() closes the current entry
132 @see @ref overview_archive, wxTarEntry, wxTarInputStream
134 class wxTarOutputStream
: public wxArchiveOutputStream
139 If the parent stream is passed as a pointer then the new filter stream
140 takes ownership of it. If it is passed by reference then it does not.
142 In a Unicode build the third parameter @a conv is used to translate the
143 headers fields into an 8-bit encoding. It has no effect on the stream's data.
145 When the @a format is @e wxTAR_PAX, pax extended headers are generated
146 when any header field will not fit the standard tar header block or if it
147 uses any non-ascii characters.
149 Extended headers are stored as extra 'files' within the tar, and will be
150 extracted as such by any other tar program that does not understand them.
151 The @a conv parameter only affect the standard tar headers, the extended
152 headers are always UTF-8 encoded.
154 When the @a format is @e wxTAR_USTAR, no extended headers are generated,
155 and instead a warning message is logged if any header field overflows.
157 wxTarOutputStream(wxOutputStream
& stream
,
158 wxTarFormat format
= wxTAR_PAX
,
159 wxMBConv
& conv
= wxConvLocal
);
160 wxTarOutputStream(wxOutputStream
* stream
,
161 wxTarFormat format
= wxTAR_PAX
,
162 wxMBConv
& conv
= wxConvLocal
);
166 The destructor calls Close() to finish writing the tar if it has
167 not been called already.
169 virtual ~wxTarOutputStream();
172 Finishes writing the tar, returning @true if successful.
173 Called by the destructor if not called explicitly.
178 Close the current entry.
180 It is called implicitly whenever another new entry is created with
181 CopyEntry() or PutNextEntry(), or when the tar is closed.
186 See wxArchiveOutputStream::CopyArchiveMetaData().
187 For the tar format this function does nothing.
189 bool CopyArchiveMetaData(wxTarInputStream
& s
);
192 Takes ownership of @a entry and uses it to create a new entry in the tar.
193 @a entry is then opened in @a inputStream and its contents copied to this stream.
195 For some other archive formats CopyEntry() is much more efficient than
196 transferring the data using Read() and Write() since it will copy them
197 without decompressing and recompressing them.
198 For tar however it makes no difference.
200 For tars on seekable streams, @a entry must be from the same tar file
201 as @a inputStream. For non-seekable streams, @a entry must also be the
202 last thing read from @a inputStream.
204 bool CopyEntry(wxTarEntry
* entry
, wxTarInputStream
& inputStream
);
208 The tar is zero padded to round its size up to @e BlockingFactor * 512 bytes.
210 The blocking factor defaults to 10 for @e wxTAR_PAX and 20 for @e wxTAR_USTAR
211 (see wxTarOutputStream()), as specified in the POSIX standards.
213 int GetBlockingFactor() const;
214 void SetBlockingFactor(int factor
);
218 Create a new directory entry (see wxArchiveEntry::IsDir()) with the given
221 PutNextEntry() can also be used to create directory entries, by supplying
222 a name with a trailing path separator.
224 bool PutNextDirEntry(const wxString
& name
, const wxDateTime
& dt
= wxDateTime::Now());
227 Takes ownership of entry and uses it to create a new entry in the tar.
229 bool PutNextEntry(wxTarEntry
* entry
);
232 Create a new entry with the given name, timestamp and size.
234 bool PutNextEntry(const wxString
& name
, const wxDateTime
& dt
= wxDateTime::Now(),
235 wxFileOffset size
= wxInvalidOffset
);
243 Holds the meta-data for an entry in a tar.
245 @section tarentry_fields Field availability
247 The tar format stores all the meta-data for an entry ahead of its data,
248 therefore GetNextEntry() always returns a fully populated wxTarEntry object,
249 both when reading from seekable and non-seekable streams.
252 @category{archive,streams}
254 @see @ref overview_archive, wxTarInputStream, wxTarOutputStream
256 class wxTarEntry
: public wxArchiveEntry
262 The tar archive format stores the entry's size ahead of the entry's data.
263 Therefore when creating an archive on a non-seekable stream it is necessary
264 to supply the correct size when each entry is created.
266 wxTarEntry(const wxString
& name
= wxEmptyString
,
267 const wxDateTime
& dt
= wxDateTime::Now(),
268 wxFileOffset size
= wxInvalidOffset
);
273 wxTarEntry(const wxTarEntry
& entry
);
277 Gets/sets the entry's access time stamp.
278 See also wxArchiveEntry::GetDateTime() and wxArchiveEntry::SetDateTime().
280 wxDateTime
GetAccessTime() const;
281 void SetAccessTime(const wxDateTime
& dt
);
286 The entry's creation time stamp.
287 See also wxArchiveEntry::GetDateTime() and wxArchiveEntry::SetDateTime().
289 wxDateTime
GetCreateTime() const;
290 void SetCreateTime(const wxDateTime
& dt
);
295 OS specific IDs defining a device; these are only meaningful when
296 wxTarEntry::GetTypeFlag() is @e wxTAR_CHRTYPE or @e wxTAR_BLKTYPE.
298 int GetDevMajor() const;
299 int GetDevMinor() const;
300 void SetDevMajor(int dev
);
301 void SetDevMinor(int dev
);
306 The user ID and group ID that has permissions (see wxTarEntry::GetMode())
309 These values aren't usually useful unless the file will only be
310 restored to the same system it originated from.
311 wxTarEntry::GetGroupName() and wxTarEntry::GetUserName() can be used instead.
313 int GetGroupId() const;
314 int GetUserId() const;
315 void SetGroupId(int id
);
316 void SetUserId(int id
);
321 The names of the user and group that has permissions (see wxTarEntry::GetMode())
322 over this entry. These are not present in very old tars.
324 wxString
GetGroupName() const;
325 wxString
GetUserName() const;
326 void SetGroupName(const wxString
& group
);
327 void SetUserName(const wxString
& user
);
332 The filename of a previous entry in the tar that this entry is a link to.
333 Only meaningful when wxTarEntry::GetTypeFlag() is set to @e wxTAR_LNKTYPE
336 wxString
GetLinkName() const;
337 void SetLinkName(const wxString
& link
);
342 UNIX permission bits for this entry.
343 Giving read, write and execute permissions to the file's user and group
344 (see GetGroupName() and GetUserName()) and to others.
346 The integer is one or more ::wxPosixPermissions flags OR-combined.
349 void SetMode(int mode
);
354 The size of the entry's data in bytes.
356 The tar archive format stores the entry's size ahead of the entry's data.
357 Therefore when creating an archive on a non-seekable stream it is necessary to
358 supply the correct size when each entry is created.
360 For seekable streams this is not necessary as wxTarOutputStream will attempt
361 to seek back and fix the entry's header when the entry is closed, though it is
362 still more efficient if the size is given beforehand.
364 void SetSize(wxFileOffset size
);
365 wxFileOffset
GetSize() const;
370 Returns/Sets the type of the entry as a ::wxTarType value.
372 When creating archives use only one of ::wxTarType values.
373 When reading archives, GetTypeFlag() may return a value which does not
374 match any value of ::wxTarType; in this case the returned value should be
375 treated as @e wxTAR_REGTYPE.
377 int GetTypeFlag() const;
378 void SetTypeFlag(int type
);
382 Returns the entry's filename in the internal format used within the archive.
384 The name can include directory components, i.e. it can be a full path.
385 The names of directory entries are returned without any trailing path separator.
386 This gives a canonical name that can be used in comparisons.
388 wxString
GetInternalName() const;
391 A static member that translates a filename into the internal format used
394 If the third parameter is provided, the bool pointed to is set to indicate
395 whether the name looks like a directory name (i.e. has a trailing path separator).
397 static wxString
GetInternalName(const wxString
& name
,
398 wxPathFormat format
= wxPATH_NATIVE
,
399 bool* pIsDir
= NULL
);
404 wxTarEntry
& operator operator=(const wxTarEntry
& entry
);