zipSubStream.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #ifndef _ZIPSUBSTREAM_H_
  23. #define _ZIPSUBSTREAM_H_
  24. //Includes
  25. #ifndef _FILTERSTREAM_H_
  26. #include "io/filterStream.h"
  27. #endif
  28. struct z_stream_s;
  29. class ZipSubRStream : public FilterStream
  30. {
  31. typedef FilterStream Parent;
  32. static const U32 csm_streamCaps;
  33. static const U32 csm_inputBufferSize;
  34. Stream* m_pStream;
  35. U32 m_uncompressedSize;
  36. U32 m_currentPosition;
  37. bool m_EOS;
  38. z_stream_s* m_pZipStream;
  39. U8* m_pInputBuffer;
  40. U32 m_originalSlavePosition;
  41. U32 fillBuffer(const U32 in_attemptSize);
  42. public:
  43. ZipSubRStream();
  44. virtual ~ZipSubRStream();
  45. // Overrides of NFilterStream
  46. public:
  47. bool attachStream(Stream* io_pSlaveStream);
  48. void detachStream();
  49. Stream* getStream();
  50. void setUncompressedSize(const U32);
  51. // Mandatory overrides. By default, these are simply passed to
  52. // whatever is returned from getStream();
  53. protected:
  54. bool _read(const U32 in_numBytes, void* out_pBuffer);
  55. public:
  56. bool hasCapability(const Capability) const;
  57. U32 getPosition() const;
  58. bool setPosition(const U32 in_newPosition);
  59. U32 getStreamSize();
  60. };
  61. class ZipSubWStream : public FilterStream
  62. {
  63. typedef FilterStream Parent;
  64. static const U32 csm_streamCaps;
  65. static const U32 csm_bufferSize;
  66. Stream* m_pStream;
  67. z_stream_s* m_pZipStream;
  68. U32 m_currPosition; // Indicates number of _uncompressed_ bytes written
  69. U8* m_pOutputBuffer;
  70. U8* m_pInputBuffer;
  71. public:
  72. ZipSubWStream();
  73. virtual ~ZipSubWStream();
  74. // Overrides of NFilterStream
  75. public:
  76. bool attachStream(Stream* io_pSlaveStream);
  77. void detachStream();
  78. Stream* getStream();
  79. // Mandatory overrides. By default, these are simply passed to
  80. // whatever is returned from getStream();
  81. protected:
  82. bool _read(const U32 in_numBytes, void* out_pBuffer);
  83. bool _write(const U32 in_numBytes, const void* in_pBuffer);
  84. public:
  85. bool hasCapability(const Capability) const;
  86. U32 getPosition() const;
  87. bool setPosition(const U32 in_newPosition);
  88. U32 getStreamSize();
  89. };
  90. #endif //_ZIPSUBSTREAM_H_