+ This operation in general is possible only for seekable streams
+ (see wxStreamBase::IsSeekable()); non-seekable streams support only
+ seeking positive amounts in mode @c wxFromCurrent (this is implemented
+ by reading data and simply discarding it).
+
+ @param pos
+ Offset to seek to.
+ @param mode
+ One of wxFromStart, wxFromEnd, wxFromCurrent.
+
+ @return The new stream position or ::wxInvalidOffset on error.
+ */
+ virtual wxFileOffset SeekI(wxFileOffset pos, wxSeekMode mode = wxFromStart);
+
+ /**
+ Returns the current stream position or ::wxInvalidOffset if it's not
+ available (e.g. socket streams do not have a size nor a current stream
+ position).
+ */
+ virtual wxFileOffset TellI() const;
+
+ /**
+ This function is only useful in read mode.
+ It is the manager of the "Write-Back" buffer. This buffer acts like a
+ temporary buffer where data which has to be read during the next read IO
+ call are put. This is useful when you get a big block of data which you
+ didn't want to read: you can replace them at the top of the input queue
+ by this way.
+
+ Be very careful about this call in connection with calling SeekI() on
+ the same stream. Any call to SeekI() will invalidate any previous call
+ to this method (otherwise you could SeekI() to one position, "unread" a
+ few bytes there, SeekI() to another position and data would be either
+ lost or corrupted).
+
+ @return Returns the amount of bytes saved in the Write-Back buffer.
+ */
+ size_t Ungetch(const void* buffer, size_t size);
+
+ /**
+ This function acts like the previous one except that it takes only one
+ character: it is sometimes shorter to use than the generic function.
+ */
+ bool Ungetch(char c);
+
+protected:
+
+ /**
+ Internal function. It is called when the stream wants to read data of the
+ specified size @a bufsize and wants it to be placed inside @a buffer.
+
+ It should return the size that was actually read or zero if EOF has been
+ reached or an error occurred (in this last case the internal @c m_lasterror
+ variable should be set accordingly as well).
+ */
+ size_t OnSysRead(void* buffer, size_t bufsize) = 0;
+};
+
+
+
+
+/**
+ @class wxCountingOutputStream
+
+ wxCountingOutputStream is a specialized output stream which does not write any
+ data anywhere, instead it counts how many bytes would get written if this were a
+ normal stream. This can sometimes be useful or required if some data gets
+ serialized to a stream or compressed by using stream compression and thus the
+ final size of the stream cannot be known other than pretending to write the stream.
+ One case where the resulting size would have to be known is if the data has
+ to be written to a piece of memory and the memory has to be allocated before
+ writing to it (which is probably always the case when writing to a memory stream).
+
+ @library{wxbase}
+ @category{streams}
+*/
+class wxCountingOutputStream : public wxOutputStream
+{
+public:
+ /**
+ Creates a wxCountingOutputStream object.
+ */
+ wxCountingOutputStream();
+
+ /**
+ Destructor.
+ */
+ virtual ~wxCountingOutputStream();
+
+ /**
+ Returns the current length of the stream.
+
+ This is the amount of data written to the stream so far, in bytes.
+ */
+ virtual wxFileOffset GetLength() const;
+};
+
+
+/**
+ @class wxBufferedInputStream
+
+ This stream acts as a cache. It caches the bytes read from the specified
+ input stream (see wxFilterInputStream).
+ It uses wxStreamBuffer and sets the default in-buffer size to 1024 bytes.
+ This class may not be used without some other stream to read the data
+ from (such as a file stream or a memory stream).
+
+ @library{wxbase}
+ @category{streams}
+
+ @see wxStreamBuffer, wxInputStream, wxBufferedOutputStream
+*/
+class wxBufferedInputStream : public wxFilterInputStream
+{
+public:
+ /**
+ Constructor using the provided buffer or default.
+
+ @param stream
+ The associated low-level stream.
+ @param buffer
+ The buffer to use if non-@NULL. Notice that the ownership of this
+ buffer is taken by the stream, i.e. it will delete it. If this
+ parameter is @NULL a default 1KB buffer is used.
+ */
+ wxBufferedInputStream(wxInputStream& stream,
+ wxStreamBuffer *buffer = NULL);
+
+ /**
+ Constructor allowing to specify the size of the buffer.
+
+ This is just a more convenient alternative to creating a wxStreamBuffer
+ of the given size and using the other overloaded constructor of this
+ class.
+
+ @param stream
+ The associated low-level stream.
+ @param bufsize
+ The size of the buffer, in bytes.
+
+ @since 2.9.0
+ */
+ wxBufferedInputStream(wxInputStream& stream, size_t bufsize);
+
+ /**
+ Destructor.
+ */
+ virtual ~wxBufferedInputStream();
+};
+
+
+
+
+/**
+ Enumeration values used by wxFilterClassFactory.
+*/
+enum wxStreamProtocolType
+{
+ wxSTREAM_PROTOCOL, //!< wxFileSystem protocol (should be only one).
+ wxSTREAM_MIMETYPE, //!< MIME types the stream handles.
+ wxSTREAM_ENCODING, //!< The HTTP Content-Encodings the stream handles.
+ wxSTREAM_FILEEXT //!< File extensions the stream handles.
+};
+
+/**
+ @class wxFilterClassFactory
+
+ Allows the creation of filter streams to handle compression formats such
+ as gzip and bzip2.
+
+ For example, given a filename you can search for a factory that will
+ handle it and create a stream to decompress it:
+
+ @code
+ factory = wxFilterClassFactory::Find(filename, wxSTREAM_FILEEXT);
+ if (factory)
+ stream = factory->NewStream(new wxFFileInputStream(filename));
+ @endcode
+
+ wxFilterClassFactory::Find can also search for a factory by MIME type,
+ HTTP encoding or by wxFileSystem protocol.
+ The available factories can be enumerated using wxFilterClassFactory::GetFirst()
+ and wxFilterClassFactory::GetNext().
+
+ @library{wxbase}
+ @category{streams}
+
+ @see wxFilterInputStream, wxFilterOutputStream, wxArchiveClassFactory,
+ @ref overview_archive
+*/
+class wxFilterClassFactory : public wxObject
+{
+public:
+ /**
+ Returns @true if this factory can handle the given protocol, MIME type, HTTP
+ encoding or file extension.
+
+ When using @c wxSTREAM_FILEEXT for the second parameter, the first parameter
+ can be a complete filename rather than just an extension.
+ */
+ bool CanHandle(const wxString& protocol,
+ wxStreamProtocolType type = wxSTREAM_PROTOCOL) const;
+
+ /**
+ A static member that finds a factory that can handle a given protocol, MIME
+ type, HTTP encoding or file extension. Returns a pointer to the class
+ factory if found, or @NULL otherwise.
+ It does not give away ownership of the factory.
+
+ When using @c wxSTREAM_FILEEXT for the second parameter, the first parameter
+ can be a complete filename rather than just an extension.
+ */
+ static const wxFilterClassFactory* Find(const wxString& protocol,
+ wxStreamProtocolType type = wxSTREAM_PROTOCOL);
+
+ //@{
+ /**
+ GetFirst and GetNext can be used to enumerate the available factories.
+ For example, to list them:
+
+ @code
+ wxString list;
+ const wxFilterClassFactory *factory = wxFilterClassFactory::GetFirst();
+
+ while (factory) {
+ list << factory->GetProtocol() << wxT("\n");
+ factory = factory->GetNext();
+ }
+ @endcode
+
+ GetFirst()/GetNext() return a pointer to a factory or @NULL if no more
+ are available. They do not give away ownership of the factory.
+ */
+ static const wxFilterClassFactory* GetFirst();
+ const wxFilterClassFactory* GetNext() const;
+ //@}
+
+ /**
+ Returns the wxFileSystem protocol supported by this factory.
+ Equivalent to @code wxString(*GetProtocols()) @endcode.
+ */
+ wxString GetProtocol() const;
+
+ /**
+ Returns the protocols, MIME types, HTTP encodings or file extensions
+ supported by this factory, as an array of null terminated strings.
+ It does not give away ownership of the array or strings.
+
+ For example, to list the file extensions a factory supports:
+
+ @code
+ wxString list;
+ const wxChar *const *p;
+
+ for (p = factory->GetProtocols(wxSTREAM_FILEEXT); *p; p++)
+ list << *p << wxT("\n");
+ @endcode
+ */
+ virtual const wxChar * const* GetProtocols(wxStreamProtocolType type = wxSTREAM_PROTOCOL) const = 0;
+
+ //@{
+ /**
+ Create a new input or output stream to decompress or compress a given stream.
+
+ 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.
+ */
+ virtual wxFilterInputStream* NewStream(wxInputStream& stream) const = 0;
+ virtual wxFilterOutputStream* NewStream(wxOutputStream& stream) const = 0;
+ virtual wxFilterInputStream* NewStream(wxInputStream* stream) const = 0;
+ virtual wxFilterOutputStream* NewStream(wxOutputStream* stream) const = 0;
+ //@}
+
+ /**
+ Remove the file extension of @a location if it is one of the file
+ extensions handled by this factory.
+ */
+ wxString PopExtension(const wxString& location) const;
+
+ /**
+ Adds this class factory to the list returned by GetFirst()/GetNext().
+
+ It is not necessary to do this to use the filter streams. It is usually
+ used when implementing streams, typically the implementation will
+ add a static instance of its factory class.