xbmc
ZipFile.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "File.h"
12 #include "IFile.h"
13 #include "ZipManager.h"
14 
15 #include <zlib.h>
16 
17 namespace XFILE
18 {
19  class CZipFile : public IFile
20  {
21  public:
22  CZipFile();
23  ~CZipFile() override;
24 
25  int64_t GetPosition() override;
26  int64_t GetLength() override;
27  bool Open(const CURL& url) override;
28  bool Exists(const CURL& url) override;
29  int Stat(struct __stat64* buffer) override;
30  int Stat(const CURL& url, struct __stat64* buffer) override;
31  ssize_t Read(void* lpBuf, size_t uiBufSize) override;
32  //virtual bool ReadString(char *szLine, int iLineLength);
33  int64_t Seek(int64_t iFilePosition, int iWhence = SEEK_SET) override;
34  void Close() override;
35 
36  //NOTE: gzip doesn't work. use DecompressGzip() instead
37  int UnpackFromMemory(std::string& strDest, const std::string& strInput, bool isGZ=false);
38 
40  static bool DecompressGzip(const std::string& in, std::string& out);
41 
42  private:
43  bool InitDecompress();
44  bool FillBuffer();
45  void DestroyBuffer(void* lpBuffer, int iBufSize);
46  CFile mFile;
47  SZipEntry mZipItem;
48  int64_t m_iFilePos = 0; // position in _uncompressed_ data read
49  int64_t m_iZipFilePos = 0; // position in _compressed_ data
50  int m_iAvailBuffer = 0;
51  z_stream m_ZStream;
52  char m_szBuffer[65535]; // 64k buffer for compressed data
53  char* m_szStringBuffer;
54  char* m_szStartOfStringBuffer; // never allocated!
55  size_t m_iDataInStringBuffer;
56  int m_iRead;
57  bool m_bFlush = false;
58  bool m_bCached;
59  };
60 }
61 
Definition: Scraper.h:41
Definition: URL.h:20
Definition: File.h:37
Definition: IFile.h:42
ssize_t Read(void *lpBuf, size_t uiBufSize) override
Attempt to read bufSize bytes from currently opened file into buffer bufPtr.
Definition: ZipFile.cpp:279
static bool DecompressGzip(const std::string &in, std::string &out)
Definition: ZipFile.cpp:484
Definition: ZipFile.h:19
int Stat(struct __stat64 *buffer) override
Fills struct __stat64 with information about currently open file For st_mode function will set correc...
Definition: ZipFile.cpp:236
Definition: ZipManager.h:31
Definition: zlib.h:82