compressor.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "io/zip/centralDir.h"
  23. #ifndef _COMPRESSOR_H_
  24. #define _COMPRESSOR_H_
  25. // Forward refs
  26. class Stream;
  27. namespace Zip
  28. {
  29. /// @addtogroup zipint_group
  30. /// @ingroup zip_group
  31. // @{
  32. // [tom, 10/26/2006] Standard Zip compression methods
  33. enum CompressionMethod
  34. {
  35. Stored = 0,
  36. Shrunk = 1,
  37. ReducedL1 = 2,
  38. ReducedL2 = 3,
  39. ReducedL3 = 4,
  40. ReducedL4 = 5,
  41. Imploded = 6,
  42. ReservedTokenized = 7,
  43. Deflated = 8,
  44. EnhDefalted = 9,
  45. DateCompression = 10,
  46. ReservedPKWARE = 11,
  47. BZip2 = 12,
  48. PPMd = 98,
  49. AESEncrypted = 99, // WinZip's AES Encrypted zips use compression method 99
  50. // to indicate AES encryption. The actual compression
  51. // method is specified in the AES extra field.
  52. };
  53. class Compressor
  54. {
  55. Compressor *mNext;
  56. protected:
  57. const char *mName; //!< The name of the compression method
  58. S32 mMethod; //!< The compression method as in the Zip header
  59. public:
  60. Compressor(S32 method, const char *name);
  61. inline const char * getName() { return mName; }
  62. inline S32 getMethod() { return mMethod; }
  63. virtual Stream *createReadStream(const CentralDir *cdir, Stream *zipStream) = 0;
  64. virtual Stream *createWriteStream(const CentralDir *cdir, Stream *zipStream) = 0;
  65. // Run time lookup methods
  66. static Compressor *findCompressor(const char *name);
  67. static Compressor *findCompressor(S32 method);
  68. };
  69. #define ImplementCompressor(name, method) \
  70. class Compressor##name : public Compressor \
  71. { \
  72. public: \
  73. Compressor##name(S32 m, const char *n) : Compressor(m, n) {} \
  74. virtual Stream *createReadStream(const CentralDir *cdir, Stream *zipStream); \
  75. virtual Stream *createWriteStream(const CentralDir *cdir, Stream *zipStream); \
  76. }; \
  77. Compressor##name gCompressor##name##instance(method, #name);
  78. #define CompressorCreateReadStream(name) \
  79. Stream * Compressor##name::createReadStream(const CentralDir *cdir, Stream *zipStream)
  80. #define CompressorCreateWriteStream(name) \
  81. Stream * Compressor##name::createWriteStream(const CentralDir *cdir, Stream *zipStream)
  82. // @}
  83. } // end namespace Zip
  84. #endif // _COMPRESSOR_H_