File: tarstrm.h

package info (click to toggle)
wxpython3.0 3.0.2.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 482,760 kB
  • ctags: 518,293
  • sloc: cpp: 2,127,226; python: 294,045; makefile: 51,942; ansic: 19,033; sh: 3,013; xml: 1,629; perl: 17
file content (405 lines) | stat: -rw-r--r-- 13,243 bytes parent folder | download | duplicates (10)
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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
/////////////////////////////////////////////////////////////////////////////
// Name:        tarstrm.h
// Purpose:     interface of wxTar* classes
// Author:      wxWidgets team
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////


/** wxTarEntry::GetTypeFlag() values */
enum wxTarType
{
    wxTAR_REGTYPE   = '0',      //!< regular file
    wxTAR_LNKTYPE   = '1',      //!< hard link
    wxTAR_SYMTYPE   = '2',      //!< symbolic link
    wxTAR_CHRTYPE   = '3',      //!< character special
    wxTAR_BLKTYPE   = '4',      //!< block special
    wxTAR_DIRTYPE   = '5',      //!< directory
    wxTAR_FIFOTYPE  = '6',      //!< named pipe
    wxTAR_CONTTYPE  = '7'       //!< contiguous file
};

/** Archive Formats (use wxTAR_PAX, it's backward compatible) used by wxTarEntry */
enum wxTarFormat
{
    wxTAR_USTAR,                //!< POSIX.1-1990 tar format
    wxTAR_PAX                   //!< POSIX.1-2001 tar format
};


/**
    @class wxTarInputStream

    Input stream for reading tar files.

    wxTarInputStream::GetNextEntry() returns a wxTarEntry object containing the
    meta-data for the next entry in the tar (and gives away ownership).
    Reading from the wxTarInputStream then returns the entry's data.
    wxTarInputStream::Eof() becomes @true after an attempt has been made to read
    past the end of the entry's data.

    When there are no more entries, wxTarInputStream::GetNextEntry() returns @NULL
    and sets wxTarInputStream::Eof().

    Tar entries are seekable if the parent stream is seekable. In practice this
    usually means they are only seekable if the tar is stored as a local file and
    is not compressed.

    @library{wxbase}
    @category{archive,streams}

    @see @ref overview_archive_byname
*/
class wxTarInputStream : public wxArchiveInputStream
{
public:
    //@{
    /**
        Constructor. In a Unicode build the second parameter @a conv is
        used to translate fields from the standard tar header into Unicode.

        It has no effect on the stream's data. @a conv is only used for the standard
        tar headers, any pax extended headers are always UTF-8 encoded.

        If the parent stream is passed as a pointer then the new filter stream
        takes ownership of it. If it is passed by reference then it does not.
    */
    wxTarInputStream(wxInputStream& stream,
                     wxMBConv& conv = wxConvLocal);
    wxTarInputStream(wxInputStream* stream,
                     wxMBConv& conv = wxConvLocal);
    //@}

    /**
        Closes the current entry.
        On a non-seekable stream reads to the end of the current entry first.
    */
    bool CloseEntry();

    /**
        Closes the current entry if one is open, then reads the meta-data for
        the next entry and returns it in a wxTarEntry object, giving away ownership.
        The stream is then open and can be read.
    */
    wxTarEntry* GetNextEntry();

    /**
        Closes the current entry if one is open, then opens the entry specified
        by the @a entry object.

        @a entry should be from the same tar file, and the tar should be on a
        seekable stream.
    */
    bool OpenEntry(wxTarEntry& entry);
};



/**
    @class wxTarClassFactory

    Class factory for the tar archive format.
    See the base class for details.

    @library{wxbase}
    @category{archive,streams}

    @see @ref overview_archive, @ref overview_archive_generic,
         wxTarEntry, wxTarInputStream, wxTarOutputStream
*/
class wxTarClassFactory : public wxArchiveClassFactory
{
public:

};



/**
    @class wxTarOutputStream

    Output stream for writing tar files.

    wxTarOutputStream::PutNextEntry() is used to create a new entry in the output tar,
    then the entry's data is written to the wxTarOutputStream.
    Another call to wxTarOutputStream::PutNextEntry() closes the current entry
    and begins the next.

    @library{wxbase}
    @category{streams}

    @see @ref overview_archive, wxTarEntry, wxTarInputStream
*/
class wxTarOutputStream : public wxArchiveOutputStream
{
public:
    //@{
    /**
        If the parent stream is passed as a pointer then the new filter stream
        takes ownership of it. If it is passed by reference then it does not.

        In a Unicode build the third parameter @a conv is used to translate the
        headers fields into an 8-bit encoding. It has no effect on the stream's data.

        When the @a format is @e wxTAR_PAX, pax extended headers are generated
        when any header field will not fit the standard tar header block or if it
        uses any non-ascii characters.

        Extended headers are stored as extra 'files' within the tar, and will be
        extracted as such by any other tar program that does not understand them.
        The @a conv parameter only affect the standard tar headers, the extended
        headers are always UTF-8 encoded.

        When the @a format is @e wxTAR_USTAR, no extended headers are generated,
        and instead a warning message is logged if any header field overflows.
    */
    wxTarOutputStream(wxOutputStream& stream,
                      wxTarFormat format = wxTAR_PAX,
                      wxMBConv& conv = wxConvLocal);
    wxTarOutputStream(wxOutputStream* stream,
                      wxTarFormat format = wxTAR_PAX,
                      wxMBConv& conv = wxConvLocal);
    //@}

    /**
        The destructor calls Close() to finish writing the tar if it has
        not been called already.
    */
    virtual ~wxTarOutputStream();

    /**
        Finishes writing the tar, returning @true if successful.
        Called by the destructor if not called explicitly.
    */
    bool Close();

    /**
        Close the current entry.

        It is called implicitly whenever another new entry is created with
        CopyEntry() or PutNextEntry(), or when the tar is closed.
    */
    bool CloseEntry();

    /**
        See wxArchiveOutputStream::CopyArchiveMetaData().
        For the tar format this function does nothing.
    */
    bool CopyArchiveMetaData(wxTarInputStream& s);

    /**
        Takes ownership of @a entry and uses it to create a new entry in the tar.
        @a entry is then opened in @a inputStream and its contents copied to this stream.

        For some other archive formats CopyEntry() is much more efficient than
        transferring the data using Read() and Write() since it will copy them
        without decompressing and recompressing them.
        For tar however it makes no difference.

        For tars on seekable streams, @a entry must be from the same tar file
        as @a inputStream. For non-seekable streams, @a entry must also be the
        last thing read from @a inputStream.
    */
    bool CopyEntry(wxTarEntry* entry, wxTarInputStream& inputStream);

    //@{
    /**
        The tar is zero padded to round its size up to @e BlockingFactor * 512 bytes.

        The blocking factor defaults to 10 for @e wxTAR_PAX and 20 for @e wxTAR_USTAR
        (see wxTarOutputStream()), as specified in the POSIX standards.
    */
    int GetBlockingFactor() const;
    void SetBlockingFactor(int factor);
    //@}

    /**
        Create a new directory entry (see wxArchiveEntry::IsDir()) with the given
        name and timestamp.

        PutNextEntry() can also be used to create directory entries, by supplying
        a name with a trailing path separator.
    */
    bool PutNextDirEntry(const wxString& name, const wxDateTime& dt = wxDateTime::Now());

    /**
        Takes ownership of entry and uses it to create a new entry in the tar.
    */
    bool PutNextEntry(wxTarEntry* entry);

    /**
        Create a new entry with the given name, timestamp and size.
    */
    bool PutNextEntry(const wxString& name, const wxDateTime& dt = wxDateTime::Now(),
                      wxFileOffset size = wxInvalidOffset);
};



/**
    @class wxTarEntry

    Holds the meta-data for an entry in a tar.

    @section tarentry_fields Field availability

    The tar format stores all the meta-data for an entry ahead of its data,
    therefore GetNextEntry() always returns a fully populated wxTarEntry object,
    both when reading from seekable and non-seekable streams.

    @library{wxbase}
    @category{archive,streams}

    @see @ref overview_archive, wxTarInputStream, wxTarOutputStream
*/
class wxTarEntry : public wxArchiveEntry
{
public:
    /**
        Constructor.

        The tar archive format stores the entry's size ahead of the entry's data.
        Therefore when creating an archive on a non-seekable stream it is necessary
        to supply the correct size when each entry is created.
    */
    wxTarEntry(const wxString& name = wxEmptyString,
               const wxDateTime& dt = wxDateTime::Now(),
               wxFileOffset size = wxInvalidOffset);

    /**
        Copy constructor.
    */
    wxTarEntry(const wxTarEntry& entry);

    //@{
    /**
        Gets/sets the entry's access time stamp.
        See also wxArchiveEntry::GetDateTime() and wxArchiveEntry::SetDateTime().
    */
    wxDateTime GetAccessTime() const;
    void SetAccessTime(const wxDateTime& dt);
    //@}

    //@{
    /**
        The entry's creation time stamp.
        See also wxArchiveEntry::GetDateTime() and wxArchiveEntry::SetDateTime().
    */
    wxDateTime GetCreateTime() const;
    void SetCreateTime(const wxDateTime& dt);
    //@}

    //@{
    /**
        OS specific IDs defining a device; these are only meaningful when
        wxTarEntry::GetTypeFlag() is @e wxTAR_CHRTYPE or @e wxTAR_BLKTYPE.
    */
    int GetDevMajor() const;
    int GetDevMinor() const;
    void SetDevMajor(int dev);
    void SetDevMinor(int dev);
    //@}

    //@{
    /**
        The user ID and group ID that has permissions (see wxTarEntry::GetMode())
        over this entry.

        These values aren't usually useful unless the file will only be
        restored to the same system it originated from.
        wxTarEntry::GetGroupName() and wxTarEntry::GetUserName() can be used instead.
    */
    int GetGroupId() const;
    int GetUserId() const;
    void SetGroupId(int id);
    void SetUserId(int id);
    //@}

    //@{
    /**
        The names of the user and group that has permissions (see wxTarEntry::GetMode())
        over this entry. These are not present in very old tars.
    */
    wxString GetGroupName() const;
    wxString GetUserName() const;
    void SetGroupName(const wxString& group);
    void SetUserName(const wxString& user);
    //@}

    //@{
    /**
        The filename of a previous entry in the tar that this entry is a link to.
        Only meaningful when wxTarEntry::GetTypeFlag() is set to @e wxTAR_LNKTYPE
        or @e wxTAR_SYMTYPE.
    */
    wxString GetLinkName() const;
    void SetLinkName(const wxString& link);
    //@}

    //@{
    /**
        UNIX permission bits for this entry.
        Giving read, write and execute permissions to the file's user and group
        (see GetGroupName() and GetUserName()) and to others.

        The integer is one or more ::wxPosixPermissions flags OR-combined.
    */
    int GetMode() const;
    void SetMode(int mode);
    //@}

    //@{
    /**
        The size of the entry's data in bytes.

        The tar archive format stores the entry's size ahead of the entry's data.
        Therefore when creating an archive on a non-seekable stream it is necessary to
        supply the correct size when each entry is created.

        For seekable streams this is not necessary as wxTarOutputStream will attempt
        to seek back and fix the entry's header when the entry is closed, though it is
        still more efficient if the size is given beforehand.
    */
    void SetSize(wxFileOffset size);
    wxFileOffset GetSize() const;
    //@}

    //@{
    /**
        Returns/Sets the type of the entry as a ::wxTarType value.

        When creating archives use only one of ::wxTarType values.
        When reading archives, GetTypeFlag() may return a value which does not
        match any value of ::wxTarType; in this case the returned value should be
        treated as @e wxTAR_REGTYPE.
    */
    int GetTypeFlag() const;
    void SetTypeFlag(int type);
    //@}

    /**
        Returns the entry's filename in the internal format used within the archive.

        The name can include directory components, i.e. it can be a full path.
        The names of directory entries are returned without any trailing path separator.
        This gives a canonical name that can be used in comparisons.
    */
    wxString GetInternalName() const;

    /**
        A static member that translates a filename into the internal format used
        within the archive.

        If the third parameter is provided, the bool pointed to is set to indicate
        whether the name looks like a directory name (i.e. has a trailing path separator).
    */
    static wxString GetInternalName(const wxString& name,
                                    wxPathFormat format = wxPATH_NATIVE,
                                    bool* pIsDir = NULL);

    /**
        Assignment operator.
    */
    wxTarEntry& operator operator=(const wxTarEntry& entry);
};