Merge pull request #4857 from t-nelson/Gotham_13.2_backports
[vuplus_xbmc] / xbmc / filesystem / ZipFile.h
1 #ifndef FILE_ZIP_H_
2 #define FILE_ZIP_H_
3 /*
4  *      Copyright (C) 2005-2013 Team XBMC
5  *      http://xbmc.org
6  *
7  *  This Program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2, or (at your option)
10  *  any later version.
11  *
12  *  This Program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with XBMC; see the file COPYING.  If not, see
19  *  <http://www.gnu.org/licenses/>.
20  *
21  */
22
23 #include "IFile.h"
24 #include <zlib.h>
25 #include "utils/log.h"
26 #include "File.h"
27 #include "ZipManager.h"
28
29 namespace XFILE
30 {
31   class CZipFile : public IFile
32   {
33   public:
34     CZipFile();
35     virtual ~CZipFile();
36
37     virtual int64_t GetPosition();
38     virtual int64_t GetLength();
39     virtual bool Open(const CURL& url);
40     virtual bool Exists(const CURL& url);
41     virtual int Stat(struct __stat64* buffer);
42     virtual int Stat(const CURL& url, struct __stat64* buffer);
43     virtual unsigned int Read(void* lpBuf, int64_t uiBufSize);
44     //virtual bool ReadString(char *szLine, int iLineLength);
45     virtual int64_t Seek(int64_t iFilePosition, int iWhence = SEEK_SET);
46     virtual void Close();
47
48     int UnpackFromMemory(std::string& strDest, const std::string& strInput, bool isGZ=false);
49   private:
50     bool InitDecompress();
51     bool FillBuffer();
52     void DestroyBuffer(void* lpBuffer, int iBufSize);
53     CFile mFile;
54     SZipEntry mZipItem;
55     int64_t m_iFilePos; // position in _uncompressed_ data read
56     int64_t m_iZipFilePos; // position in _compressed_ data
57     int m_iAvailBuffer;
58     z_stream m_ZStream;
59     char m_szBuffer[65535];     // 64k buffer for compressed data
60     char* m_szStringBuffer;
61     char* m_szStartOfStringBuffer; // never allocated!
62     int m_iDataInStringBuffer;
63     int m_iRead;
64     bool m_bFlush;
65     bool m_bCached;
66   };
67 }
68
69 #endif