00001 00002 // This source file is part of the ZipArchive library source distribution and 00003 // is Copyrighted 2000 - 2009 by Artpol Software - Tadeusz Dracz 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License 00007 // as published by the Free Software Foundation; either version 2 00008 // of the License, or (at your option) any later version. 00009 // 00010 // For the licensing details refer to the License.txt file. 00011 // 00012 // Web Site: http://www.artpol-software.com 00014 00021 #if !defined(ZIPARCHIVE_DEFLATECOMPRESSOR_DOT_H) 00022 #define ZIPARCHIVE_DEFLATECOMPRESSOR_DOT_H 00023 00024 #if _MSC_VER > 1000 00025 #pragma once 00026 #endif 00027 00028 #include "ZipExport.h" 00029 #include "BaseLibCompressor.h" 00030 #include "ZipException.h" 00031 #include "zlib/zlib.h" 00032 00033 namespace ZipArchiveLib 00034 { 00035 00039 class ZIP_API CDeflateCompressor : public CBaseLibCompressor 00040 { 00041 public: 00050 struct ZIP_API COptions : CBaseLibCompressor::COptions 00051 { 00052 COptions() 00053 { 00054 m_bCheckLastBlock = true; 00055 } 00056 00057 int GetType() const 00058 { 00059 return typeDeflate; 00060 } 00061 00062 CZipCompressor::COptions* Clone() const 00063 { 00064 return new COptions(*this); 00065 } 00066 00072 bool m_bCheckLastBlock; 00073 00074 }; 00075 00082 CDeflateCompressor(CZipStorage* pStorage); 00083 00084 bool CanProcess(WORD uMethod) {return uMethod == methodStore || uMethod == methodDeflate;} 00085 00086 void InitCompression(int iLevel, CZipFileHeader* pFile, CZipCryptograph* pCryptograph); 00087 void InitDecompression(CZipFileHeader* pFile, CZipCryptograph* pCryptograph); 00088 00089 DWORD Decompress(void *pBuffer, DWORD uSize); 00090 void Compress(const void *pBuffer, DWORD uSize); 00091 00092 void FinishCompression(bool bAfterException); 00093 void FinishDecompression(bool bAfterException); 00094 00095 00096 const CZipCompressor::COptions* GetOptions() const 00097 { 00098 return &m_options; 00099 } 00100 00101 ~CDeflateCompressor() 00102 { 00103 } 00104 protected: 00105 void UpdateOptions(const CZipCompressor::COptions* pOptions) 00106 { 00107 m_options = *(COptions*)pOptions; 00108 } 00109 00110 int ConvertInternalError(int iErr) const 00111 { 00112 switch (iErr) 00113 { 00114 case Z_NEED_DICT: 00115 return CZipException::needDict; 00116 case Z_STREAM_END: 00117 return CZipException::streamEnd; 00118 case Z_ERRNO: 00119 return CZipException::errNo; 00120 case Z_STREAM_ERROR: 00121 return CZipException::streamError; 00122 case Z_DATA_ERROR: 00123 return CZipException::dataError; 00124 case Z_MEM_ERROR: 00125 return CZipException::memError; 00126 case Z_BUF_ERROR: 00127 return CZipException::bufError; 00128 case Z_VERSION_ERROR: 00129 return CZipException::versionError; 00130 default: 00131 return CZipException::genericError; 00132 } 00133 } 00134 00135 bool IsCodeErrorOK(int iErr) const 00136 { 00137 return iErr == Z_OK || iErr == Z_NEED_DICT; 00138 } 00139 00140 private: 00141 COptions m_options; 00142 zarch_z_stream m_stream; 00143 }; 00144 00145 } // namespace 00146 00147 #endif 00148