]>
git.saurik.com Git - wxWidgets.git/blob - interface/zipstrm.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxZipNotifier
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
13 If you need to know when a wxZipInputStream
15 you can create a notifier by deriving from this abstract base class,
16 overriding wxZipNotifier::OnEntryUpdated.
17 An instance of your notifier class can then be assigned to wxZipEntry
18 objects, using wxZipEntry::SetNotifier.
20 Setting a notifier is not usually necessary. It is used to handle
21 certain cases when modifying an zip in a pipeline (i.e. between
22 non-seekable streams).
23 See '@ref overview_wxarcnoseek "Archives on non-seekable streams"'.
28 @see @ref overview_wxarcnoseek "Archives on non-seekable streams", wxZipEntry,
29 wxZipInputStream, wxZipOutputStream
35 Override this to receive notifications when
36 an wxZipEntry object changes.
38 void OnEntryUpdated(wxZipEntry
& entry
);
47 Holds the meta-data for an entry in a zip.
52 @see @ref overview_wxarc "Archive formats such as zip", wxZipInputStream,
53 wxZipOutputStream, wxZipNotifier
55 class wxZipEntry
: public wxArchiveEntry
62 wxZipEntry(const wxString
& name
= wxEmptyString
);
63 wxZipEntry(const wxZipEntry
& entry
);
67 Make a copy of this entry.
69 wxZipEntry
* Clone() const;
73 A short comment for this entry.
75 wxString
GetComment();
76 const void SetComment(const wxString
& comment
);
81 The low 8 bits are always the DOS/Windows file attributes for this entry.
82 The values of these attributes are given in the
83 enumeration @c wxZipAttributes.
84 The remaining bits can store platform specific permission bits or
85 attributes, and their meaning depends on the value
86 of @ref systemmadeby() SetSystemMadeBy.
87 If IsMadeByUnix() is @true then the
88 high 16 bits are unix mode bits.
89 The following other accessors access these bits:
90 @ref wxArchiveEntry::isreadonly IsReadOnly/SetIsReadOnly
92 @ref wxArchiveEntry::isdir IsDir/SetIsDir
94 @ref mode() Get/SetMode
96 wxUint32
GetExternalAttributes();
97 const void SetExternalAttributes(wxUint32 attr
);
102 The extra field from the entry's central directory record.
103 The extra field is used to store platform or application specific
104 data. See Pkware's document 'appnote.txt' for information on its format.
106 const char* GetExtra();
107 const size_t GetExtraLen();
108 const void SetExtra(const char* extra
, size_t len
);
113 The extra field from the entry's local record.
114 The extra field is used to store platform or application specific
115 data. See Pkware's document 'appnote.txt' for information on its format.
117 const char* GetLocalExtra();
118 const size_t GetLocalExtraLen();
119 const void SetLocalExtra(const char* extra
, size_t len
);
124 The compression method. The enumeration @c wxZipMethod lists the
126 The default constructor sets this to wxZIP_METHOD_DEFAULT,
127 which allows wxZipOutputStream to
128 choose the method when writing the entry.
131 const void SetMethod(int method
);
136 Sets the DOS attributes
137 in @ref externalattributes() GetExternalAttributes
138 to be consistent with the @c mode given.
139 If IsMadeByUnix() is @true then also
140 stores @c mode in GetExternalAttributes().
141 Note that the default constructor
142 sets @ref systemmadeby() GetSystemMadeBy to
143 wxZIP_SYSTEM_MSDOS by default. So to be able to store unix
144 permissions when creating zips, call SetSystemMadeBy(wxZIP_SYSTEM_UNIX).
147 const void SetMode(int mode
);
152 The originating file-system. The default constructor sets this to
153 wxZIP_SYSTEM_MSDOS. Set it to wxZIP_SYSTEM_UNIX in order to be
154 able to store unix permissions using @ref mode() SetMode.
156 int GetSystemMadeBy();
157 const void SetSystemMadeBy(int system
);
161 The compressed size of this entry in bytes.
163 off_t
GetCompressedSize() const;
166 CRC32 for this entry's data.
168 wxUint32
GetCrc() const;
171 Returns a combination of the bits flags in the enumeration @c wxZipFlags.
173 int GetFlags() const;
177 A static member that translates a filename into the internal format used
178 within the archive. If the third parameter is provided, the bool pointed
179 to is set to indicate whether the name looks like a directory name
180 (i.e. has a trailing path separator).
182 @see @ref overview_wxarcbyname "Looking up an archive entry by name"
184 wxString
GetInternalName();
185 const wxString
GetInternalName(const wxString
& name
,
186 wxPathFormat format
= wxPATH_NATIVE
,
187 bool* pIsDir
= NULL
);
191 Returns @true if @ref systemmadeby() GetSystemMadeBy
192 is a flavour of unix.
194 bool IsMadeByUnix() const;
198 Indicates that this entry's data is text in an 8-bit encoding.
201 const void SetIsText(bool isText
= true);
206 Sets the notifier() for this entry.
207 Whenever the wxZipInputStream updates
208 this entry, it will then invoke the associated
209 notifier's wxZipNotifier::OnEntryUpdated
211 Setting a notifier is not usually necessary. It is used to handle
212 certain cases when modifying an zip in a pipeline (i.e. between
213 non-seekable streams).
215 @see @ref overview_wxarcnoseek "Archives on non-seekable streams", wxZipNotifier
217 void SetNotifier(wxZipNotifier
& notifier
);
218 void UnsetNotifier();
224 wxZipEntry
& operator operator=(const wxZipEntry
& entry
);
230 @class wxZipInputStream
233 Input stream for reading zip files.
235 wxZipInputStream::GetNextEntry returns an
236 wxZipEntry object containing the meta-data
237 for the next entry in the zip (and gives away ownership). Reading from
238 the wxZipInputStream then returns the entry's data. Eof() becomes @true
239 after an attempt has been made to read past the end of the entry's data.
240 When there are no more entries, GetNextEntry() returns @NULL and sets Eof().
242 Note that in general zip entries are not seekable, and
243 wxZipInputStream::SeekI() always returns wxInvalidOffset.
248 @see @ref overview_wxarc "Archive formats such as zip", wxZipEntry,
251 class wxZipInputStream
: public wxArchiveInputStream
256 Compatibility constructor (requires WXWIN_COMPATIBILITY_2_6).
257 When this constructor is used, an emulation of seeking is
258 switched on for compatibility with previous versions. Note however,
259 that it is deprecated.
261 wxZipInputStream(wxInputStream
& stream
,
262 wxMBConv
& conv
= wxConvLocal
);
263 wxZipInputStream(wxInputStream
* stream
,
264 wxMBConv
& conv
= wxConvLocal
);
265 wxZipInputStream(const wxString
& archive
,
266 const wxString
& file
);
270 Closes the current entry. On a non-seekable stream reads to the end of
271 the current entry first.
276 Returns the zip comment.
277 This is stored at the end of the zip, therefore when reading a zip
278 from a non-seekable stream, it returns the empty string until the
279 end of the zip has been reached, i.e. when GetNextEntry() returns
282 wxString
GetComment();
285 Closes the current entry if one is open, then reads the meta-data for
286 the next entry and returns it in a wxZipEntry
287 object, giving away ownership. The stream is then open and can be read.
289 wxZipEntry
* GetNextEntry();
292 For a zip on a seekable stream returns the total number of entries in
293 the zip. For zips on non-seekable streams returns the number of entries
294 returned so far by GetNextEntry().
296 int GetTotalEntries();
299 Closes the current entry if one is open, then opens the entry specified
300 by the @a entry object.
301 @a entry should be from the same zip file, and the zip should
302 be on a seekable stream.
304 bool OpenEntry(wxZipEntry
& entry
);
310 @class wxZipClassFactory
313 Class factory for the zip archive format. See the base class
319 @see @ref overview_wxarc "Archive formats such as zip", @ref
320 overview_wxarcgeneric "Generic archive programming", wxZipEntry, wxZipInputStream, wxZipOutputStream
322 class wxZipClassFactory
: public wxArchiveClassFactory
331 @class wxZipOutputStream
334 Output stream for writing zip files.
336 wxZipOutputStream::PutNextEntry is used to create
337 a new entry in the output zip, then the entry's data is written to the
338 wxZipOutputStream. Another call to PutNextEntry() closes the current
339 entry and begins the next.
344 @see @ref overview_wxarc "Archive formats such as zip", wxZipEntry,
347 class wxZipOutputStream
: public wxArchiveOutputStream
352 Constructor. @c level is the compression level to use.
353 It can be a value between 0 and 9 or -1 to use the default value
354 which currently is equivalent to 6.
355 If the parent stream is passed as a pointer then the new filter stream
356 takes ownership of it. If it is passed by reference then it does not.
357 In a Unicode build the third parameter @c conv is used to translate
358 the filename and comment fields to an 8-bit encoding. It has no effect on the
361 wxZipOutputStream(wxOutputStream
& stream
, int level
= -1,
362 wxMBConv
& conv
= wxConvLocal
);
363 wxZipOutputStream(wxOutputStream
* stream
, int level
= -1,
364 wxMBConv
& conv
= wxConvLocal
);
368 The destructor calls Close() to finish
369 writing the zip if it has not been called already.
371 ~wxZipOutputStream();
374 Finishes writing the zip, returning @true if successful.
375 Called by the destructor if not called explicitly.
380 Close the current entry. It is called implicitly whenever another new
381 entry is created with CopyEntry()
382 or PutNextEntry(), or
383 when the zip is closed.
388 Transfers the zip comment from the wxZipInputStream
389 to this output stream.
391 bool CopyArchiveMetaData(wxZipInputStream
& inputStream
);
394 Takes ownership of @c entry and uses it to create a new entry
395 in the zip. @c entry is then opened in @c inputStream and its contents
396 copied to this stream.
397 CopyEntry() is much more efficient than transferring the data using
398 Read() and Write() since it will copy them without decompressing and
400 For zips on seekable streams, @c entry must be from the same zip file
401 as @c stream. For non-seekable streams, @c entry must also be the
402 last thing read from @c inputStream.
404 bool CopyEntry(wxZipEntry
* entry
, wxZipInputStream
& inputStream
);
408 Set the compression level that will be used the next time an entry is
409 created. It can be a value between 0 and 9 or -1 to use the default value
410 which currently is equivalent to 6.
413 const void SetLevel(int level
);
418 Create a new directory entry
419 (see wxArchiveEntry::IsDir)
420 with the given name and timestamp.
422 also be used to create directory entries, by supplying a name with
423 a trailing path separator.
425 bool PutNextDirEntry(const wxString
& name
);
429 , @b off_t@e size = wxInvalidOffset)
430 Create a new entry with the given name, timestamp and size.
432 bool PutNextEntry(wxZipEntry
* entry
);
433 bool PutNextEntry(const wxString
& name
);
437 Sets a comment for the zip as a whole. It is written at the end of the
440 void SetComment(const wxString
& comment
);