zipSubStream.h

Engine/source/core/util/zip/zipSubStream.h

More...

Classes:

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _ZIPSUBSTREAM_H_
 25#define _ZIPSUBSTREAM_H_
 26
 27//Includes
 28#ifndef _FILTERSTREAM_H_
 29#include "core/filterStream.h"
 30#endif
 31
 32struct z_stream_s;
 33
 34class ZipSubRStream : public FilterStream, public IStreamByteCount
 35{
 36   typedef FilterStream Parent;
 37   static const U32 csm_streamCaps;
 38   static const U32 csm_inputBufferSize;
 39
 40   Stream* m_pStream;
 41   U32     m_uncompressedSize;
 42   U32     m_currentPosition;
 43   bool     m_EOS;
 44   z_stream_s*  m_pZipStream;
 45   U8*          m_pInputBuffer;
 46   U32          m_originalSlavePosition;
 47   U32 m_lastBytesRead;
 48
 49   U32 fillBuffer(const U32 in_attemptSize);
 50public:
 51   virtual U32 getLastBytesRead() { return m_lastBytesRead; }
 52   virtual U32 getLastBytesWritten() { return 0; }
 53   
 54
 55  public:
 56   ZipSubRStream();
 57   virtual ~ZipSubRStream();
 58
 59   // Overrides of NFilterStream
 60  public:
 61   bool    attachStream(Stream* io_pSlaveStream);
 62   void    detachStream();
 63   Stream* getStream();
 64
 65   void setUncompressedSize(const U32);
 66
 67   // Mandatory overrides.  By default, these are simply passed to
 68   //  whatever is returned from getStream();
 69  protected:
 70   bool _read(const U32 in_numBytes,  void* out_pBuffer);
 71  public:
 72   bool hasCapability(const Capability) const;
 73
 74   U32  getPosition() const;
 75   bool setPosition(const U32 in_newPosition);
 76
 77   U32  getStreamSize();
 78};
 79
 80class ZipSubWStream : public FilterStream, public IStreamByteCount
 81{
 82   typedef FilterStream Parent;
 83   static const U32 csm_streamCaps;
 84   static const U32 csm_bufferSize;
 85
 86   Stream*      m_pStream;
 87   z_stream_s*  m_pZipStream;
 88   U32          m_currPosition;  // Indicates number of _uncompressed_ bytes written
 89   U8*          m_pOutputBuffer;
 90   U8*          m_pInputBuffer;
 91   U32 m_lastBytesRead;
 92   U32 m_lastBytesWritten;
 93
 94public:
 95   virtual U32 getLastBytesRead() { return m_lastBytesRead; }
 96   virtual U32 getLastBytesWritten() { return m_lastBytesWritten; }
 97
 98  public:
 99   ZipSubWStream();
100   virtual ~ZipSubWStream();
101
102   // Overrides of NFilterStream
103  public:
104   bool    attachStream(Stream* io_pSlaveStream);
105   void    detachStream();
106   Stream* getStream();
107
108   // Mandatory overrides.  By default, these are simply passed to
109   //  whatever is returned from getStream();
110  protected:
111   bool _read(const U32 in_numBytes,  void* out_pBuffer);
112   bool _write(const U32 in_numBytes, const void* in_pBuffer);
113  public:
114   bool hasCapability(const Capability) const;
115
116   U32  getPosition() const;
117   bool setPosition(const U32 in_newPosition);
118
119   U32  getStreamSize();
120};
121
122#endif //_ZIPSUBSTREAM_H_
123