DeflateCompressor.h
Go to the documentation of this file.
1 
2 // This source file is part of the ZipArchive Library Open Source distribution
3 // and is Copyrighted 2000 - 2022 by Artpol Software - Tadeusz Dracz
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // For the licensing details refer to the License.txt file.
11 //
12 // Web Site: https://www.artpol-software.com
14 
21 #if !defined(ZIPARCHIVE_DEFLATECOMPRESSOR_DOT_H)
22 #define ZIPARCHIVE_DEFLATECOMPRESSOR_DOT_H
23 
24 #if _MSC_VER > 1000
25 #pragma once
26 #endif
27 
28 #include "ZipExport.h"
29 #include "BaseLibCompressor.h"
30 #include "ZipException.h"
31 #include "zlib/zlib.h"
32 
33 namespace ZipArchiveLib
34 {
35 
39 class ZIP_API CDeflateCompressor : public CBaseLibCompressor
40 {
41 public:
51  {
52  COptions()
53  {
54  m_bCheckLastBlock = true;
55  }
56 
57  int GetType() const
58  {
59  return typeDeflate;
60  }
61 
62  CZipCompressor::COptions* Clone() const
63  {
64  return new COptions(*this);
65  }
66 
73 
74  };
75 
83 
84  bool CanProcess(WORD uMethod) {return uMethod == methodStore || uMethod == methodDeflate;}
85 
86  void InitCompression(int iLevel, CZipFileHeader* pFile, CZipCryptograph* pCryptograph);
87  void InitDecompression(CZipFileHeader* pFile, CZipCryptograph* pCryptograph);
88 
89  DWORD Decompress(void *pBuffer, DWORD uSize);
90  void Compress(const void *pBuffer, DWORD uSize);
91 
92  void FinishCompression(bool bAfterException);
93  void FinishDecompression(bool bAfterException);
94 
95 
96  const CZipCompressor::COptions* GetOptions() const
97  {
98  return &m_options;
99  }
100 
102  {
103  }
104 protected:
105  void UpdateOptions(const CZipCompressor::COptions* pOptions)
106  {
107  m_options = *(COptions*)pOptions;
108  }
109 
110  int ConvertInternalError(int iErr) const
111  {
112  switch (iErr)
113  {
114  case Z_NEED_DICT:
116  case Z_STREAM_END:
118  case Z_ERRNO:
119  return CZipException::errNo;
120  case Z_STREAM_ERROR:
122  case Z_DATA_ERROR:
124  case Z_MEM_ERROR:
126  case Z_BUF_ERROR:
128  case Z_VERSION_ERROR:
130  default:
132  }
133  }
134 
135  bool IsCodeErrorOK(int iErr) const
136  {
137  return iErr == Z_OK || iErr == Z_NEED_DICT;
138  }
139 
140 private:
141  COptions m_options;
142  zarch_z_stream m_stream;
143 };
144 
145 } // namespace
146 
147 #endif
148 

The ZipArchive Library Copyright © 2000 - 2022 Artpol Software - Tadeusz Dracz. Generated at Sat Dec 17 2022 19:57:03.