Add wxLZMAClassFactory for run-time LZMA stream creation

This should allow handling .xz files in wxFileSystem, for example.
This commit is contained in:
Vadim Zeitlin
2018-03-30 22:11:07 +02:00
parent 7c34ca65a0
commit 1cdb384d7b
2 changed files with 58 additions and 0 deletions

View File

@@ -117,6 +117,31 @@ private:
bool DoFlush(bool finish);
};
// ----------------------------------------------------------------------------
// Support for creating LZMA streams from extension/MIME type
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_BASE wxLZMAClassFactory: public wxFilterClassFactory
{
public:
wxLZMAClassFactory();
wxFilterInputStream *NewStream(wxInputStream& stream) const wxOVERRIDE
{ return new wxLZMAInputStream(stream); }
wxFilterOutputStream *NewStream(wxOutputStream& stream) const wxOVERRIDE
{ return new wxLZMAOutputStream(stream, -1); }
wxFilterInputStream *NewStream(wxInputStream *stream) const wxOVERRIDE
{ return new wxLZMAInputStream(stream); }
wxFilterOutputStream *NewStream(wxOutputStream *stream) const wxOVERRIDE
{ return new wxLZMAOutputStream(stream, -1); }
const wxChar * const *GetProtocols(wxStreamProtocolType type
= wxSTREAM_PROTOCOL) const wxOVERRIDE;
private:
wxDECLARE_DYNAMIC_CLASS(wxLZMAClassFactory);
};
WXDLLIMPEXP_BASE wxVersionInfo wxGetLibLZMAVersionInfo();
#endif // wxUSE_LIBLZMA && wxUSE_STREAMS

View File

@@ -369,4 +369,37 @@ bool wxLZMAOutputStream::Close()
return wxFilterOutputStream::Close() && IsOk();
}
// ----------------------------------------------------------------------------
// wxLZMAClassFactory: allow creating streams from extension/MIME type
// ----------------------------------------------------------------------------
wxIMPLEMENT_DYNAMIC_CLASS(wxLZMAClassFactory, wxFilterClassFactory);
static wxLZMAClassFactory g_wxLZMAClassFactory;
wxLZMAClassFactory::wxLZMAClassFactory()
{
if ( this == &g_wxLZMAClassFactory )
PushFront();
}
const wxChar * const *
wxLZMAClassFactory::GetProtocols(wxStreamProtocolType type) const
{
static const wxChar *mime[] = { wxT("application/xz"), NULL };
static const wxChar *encs[] = { wxT("xz"), NULL };
static const wxChar *exts[] = { wxT(".xz"), NULL };
const wxChar* const* ret = NULL;
switch ( type )
{
case wxSTREAM_PROTOCOL: ret = encs; break;
case wxSTREAM_MIMETYPE: ret = mime; break;
case wxSTREAM_ENCODING: ret = encs; break;
case wxSTREAM_FILEEXT: ret = exts; break;
}
return ret;
}
#endif // wxUSE_LIBLZMA && wxUSE_STREAMS