zstream.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: zstream.h
  3. // Purpose: interface of wxZlibOutputStream
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /// Compression level
  8. enum wxZlibCompressionLevels {
  9. wxZ_DEFAULT_COMPRESSION = -1,
  10. wxZ_NO_COMPRESSION = 0,
  11. wxZ_BEST_SPEED = 1,
  12. wxZ_BEST_COMPRESSION = 9
  13. };
  14. /// Flags
  15. enum wxZLibFlags {
  16. wxZLIB_NO_HEADER = 0, //!< raw deflate stream, no header or checksum
  17. wxZLIB_ZLIB = 1, //!< zlib header and checksum
  18. wxZLIB_GZIP = 2, //!< gzip header and checksum, requires zlib 1.2.1+
  19. wxZLIB_AUTO = 3 //!< autodetect header zlib or gzip
  20. };
  21. /**
  22. @class wxZlibOutputStream
  23. This stream compresses all data written to it.
  24. The compressed output can be in zlib or gzip format.
  25. Note that writing the gzip format requires zlib version 1.2.1 or greater
  26. (the builtin version does support gzip format).
  27. The stream is not seekable, wxOutputStream::SeekO() returns
  28. ::wxInvalidOffset.
  29. @library{wxbase}
  30. @category{archive,streams}
  31. @see wxOutputStream, wxZlibInputStream
  32. */
  33. class wxZlibOutputStream : public wxFilterOutputStream
  34. {
  35. public:
  36. //@{
  37. /**
  38. Creates a new write-only compressed stream.
  39. @a level means level of compression. It is number between 0 and 9
  40. (including these values) where 0 means no compression and 9 best but
  41. slowest compression. -1 is default value (currently equivalent to 6).
  42. If the parent stream is passed as a pointer then the new filter stream
  43. takes ownership of it. If it is passed by reference then it does not.
  44. The @a flags wxZLIB_ZLIB and wxZLIB_GZIP specify whether the output data
  45. will be in zlib or gzip format. wxZLIB_ZLIB is the default.
  46. If @a flags is wxZLIB_NO_HEADER, then a raw deflate stream is output
  47. without either zlib or gzip headers. This is a lower level mode, which
  48. is not usually used directly. It can be used to embed a raw deflate
  49. stream in a higher level protocol.
  50. The values of the ::wxZlibCompressionLevels and ::wxZLibFlags
  51. enumerations can be used.
  52. */
  53. wxZlibOutputStream(wxOutputStream& stream, int level = -1,
  54. int flags = wxZLIB_ZLIB);
  55. wxZlibOutputStream(wxOutputStream* stream, int level = -1,
  56. int flags = wxZLIB_ZLIB);
  57. //@}
  58. /**
  59. Returns @true if zlib library in use can handle gzip compressed data.
  60. */
  61. static bool CanHandleGZip();
  62. //@{
  63. /**
  64. Sets the dictionary to the specified chunk of data. This can improve
  65. compression rate but note that the dictionary has to be the same when
  66. you deflate the data as when you inflate the data, otherwise you
  67. will inflate corrupted data.
  68. Returns @true if the dictionary was successfully set.
  69. */
  70. bool SetDictionary(const char *data, const size_t datalen);
  71. bool SetDictionary(const wxMemoryBuffer &buf);
  72. //@}
  73. };
  74. /**
  75. @class wxZlibInputStream
  76. This filter stream decompresses a stream that is in zlib or gzip format.
  77. Note that reading the gzip format requires zlib version 1.2.1 or greater,
  78. (the builtin version does support gzip format).
  79. The stream is not seekable, wxInputStream::SeekI returns ::wxInvalidOffset.
  80. Also wxStreamBase::GetSize() is not supported, it always returns 0.
  81. @library{wxbase}
  82. @category{archive,streams}
  83. @see wxInputStream, wxZlibOutputStream.
  84. */
  85. class wxZlibInputStream : public wxFilterInputStream
  86. {
  87. public:
  88. //@{
  89. /**
  90. If the parent stream is passed as a pointer then the new filter stream
  91. takes ownership of it. If it is passed by reference then it does not.
  92. The @a flags wxZLIB_ZLIB and wxZLIB_GZIP specify whether the input data
  93. is in zlib or gzip format. If wxZLIB_AUTO is used, then zlib will
  94. autodetect the stream type, this is the default.
  95. If @a flags is wxZLIB_NO_HEADER, then the data is assumed to be a raw
  96. deflate stream without either zlib or gzip headers. This is a lower level
  97. mode, which is not usually used directly. It can be used to read a raw
  98. deflate stream embedded in a higher level protocol.
  99. The values of the ::wxZLibFlags enumeration can be used.
  100. */
  101. wxZlibInputStream(wxInputStream& stream, int flags = wxZLIB_AUTO);
  102. wxZlibInputStream(wxInputStream* stream, int flags = wxZLIB_AUTO);
  103. //@}
  104. /**
  105. Returns @true if zlib library in use can handle gzip compressed data.
  106. */
  107. static bool CanHandleGZip();
  108. //@{
  109. /**
  110. Sets the dictionary to the specified chunk of data. This can improve
  111. compression rate but note that the dictionary has to be the same when
  112. you deflate the data as when you inflate the data, otherwise you
  113. will inflate corrupted data.
  114. Returns @true if the dictionary was successfully set.
  115. */
  116. bool SetDictionary(const char *data, const size_t datalen);
  117. bool SetDictionary(const wxMemoryBuffer &buf);
  118. //@}
  119. };