diff options
| author | Tomas Bzatek <tbzatek@redhat.com> | 2023-12-17 21:23:58 +0100 |
|---|---|---|
| committer | Tomas Bzatek <tbzatek@redhat.com> | 2023-12-17 21:23:58 +0100 |
| commit | 02d6107c97b48888362e7c6a70dcac323c89d741 (patch) | |
| tree | 5069a77adaf73f7249ac79b6c49a47168a647ef8 /zip/ZipArchive/ZipCompressor.h | |
| parent | 4e17c2527b106f1b493a3ac77c89858d14f834e2 (diff) | |
| download | tuxcmd-modules-02d6107c97b48888362e7c6a70dcac323c89d741.tar.xz | |
ZipArchive: Update to the 4.6.9 release
Diffstat (limited to 'zip/ZipArchive/ZipCompressor.h')
| -rw-r--r-- | zip/ZipArchive/ZipCompressor.h | 94 |
1 files changed, 66 insertions, 28 deletions
diff --git a/zip/ZipArchive/ZipCompressor.h b/zip/ZipArchive/ZipCompressor.h index be2855d..0aa5822 100644 --- a/zip/ZipArchive/ZipCompressor.h +++ b/zip/ZipArchive/ZipCompressor.h @@ -1,6 +1,6 @@ ////////////////////////////////////////////////////////////////////////////////
-// This source file is part of the ZipArchive library source distribution and
-// is Copyrighted 2000 - 2007 by Artpol Software - Tadeusz Dracz
+// This source file is part of the ZipArchive Library Open Source distribution
+// and is Copyrighted 2000 - 2022 by Artpol Software - Tadeusz Dracz
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
@@ -9,7 +9,7 @@ //
// For the licensing details refer to the License.txt file.
//
-// Web Site: http://www.artpol-software.com
+// Web Site: https://www.artpol-software.com
////////////////////////////////////////////////////////////////////////////////
/**
@@ -24,7 +24,8 @@ #if _MSC_VER > 1000
#pragma once
#pragma warning( push )
- #pragma warning (disable : 4100) // unreferenced formal parameter
+ #pragma warning (disable: 4100) // unreferenced formal parameter
+ #pragma warning (disable: 4275) // non dll-interface class 'CObject' used as base for dll-interface class 'CMap<KEY,ARG_KEY,VALUE,ARG_VALUE>'
#endif
#include "ZipExport.h"
@@ -42,7 +43,7 @@ class ZIP_API CZipCompressor protected:
CZipStorage* m_pStorage; ///< The current storage object.
CZipAutoBuffer m_pBuffer; ///< A buffer that receives compressed data or provides data for decompression.
- CZipCryptograph* m_pCryptograph; ///< Current cryptograph.
+ CZipCryptograph* m_pCryptograph; ///< The current cryptograph.
CZipFileHeader* m_pFile; ///< The file header being compressed or decompressed.
@@ -59,6 +60,7 @@ protected: m_uUncomprLeft = 0;
m_uComprLeft = 0;
m_uCrc32 = 0;
+ m_pFile = NULL;
}
public:
@@ -68,7 +70,8 @@ public: enum CompressorType
{
typeDeflate = 1, ///< Deflate compression (default in zip archives).
- typeBzip2 ///< Bzip2 compression.
+ typeBzip2, ///< Bzip2 compression.
+ typePPMd ///< PPMd compression
};
/**
@@ -76,10 +79,10 @@ public: */
enum CompressionLevel
{
- levelDefault = -1, ///< The default compression level (equals 6 for deflate).
+ levelDefault = -1, ///< The default compression level (equals \c 6 for deflate).
levelStore = 0, ///< No compression used. Data is stored.
levelFastest = 1, ///< The fastest compression. The compression ratio is the lowest (apart from #levelStore).
- levelBest = 9 ///< The highest compression ratio. It's usually the slowest.
+ levelBest = 9 ///< The highest compression ratio. It's usually the slowest one.
};
/**
@@ -90,12 +93,13 @@ public: methodStore = 0, ///< A file is stored, not compressed.
methodDeflate = 8, ///< The deflate compression method.
/**
- A file is compressed using the bzip2 algorithm.
+ The bzip2 compression method.
\see
<a href="kb">0610231446|bzip2</a>
*/
methodBzip2 = 12,
+
/**
This value means that WinZip AES encryption is used.
The original compression method is stored in a WinZip extra field.
@@ -136,7 +140,7 @@ public: }
/**
- Gets the type of the compressor to which the current options apply.
+ Returns the type of the compressor to which the current options apply.
\return
The type of the compressor. It can be one of the #CompressorType values.
@@ -153,7 +157,7 @@ public: /**
The size of the buffer used in compression and decompression operations.
- By default it is set to to #cDefaultBufferSize. For the optimal performance of the
+ By default it is set to #cDefaultBufferSize. For the optimal performance of the
deflate algorithm it should be set at least to 128kB.
\see
@@ -185,7 +189,7 @@ public: Returns the value indicating whether the given compression method is supported by the ZipArchive Library.
\param uCompressionMethod
- The compression method. Can be one of the #CompressionMethod values.
+ The compression method. It can be one of the #CompressionMethod values.
\return
\c true, if the compression method is supported, \c false otherwise.
@@ -201,10 +205,10 @@ public: DWORD m_uCrc32; ///< The CRC32 file checksum.
/**
- Returns the value indicating, if the current #CZipCompressor object supports the given compression method.
+ Returns the value indicating whether the current #CZipCompressor object supports the given compression method.
\param uMethod
- The compression method. Can be one of the #CompressionMethod values.
+ The compression method. It can be one of the #CompressionMethod values.
\return
\c true, if the compression method is supported; \c false otherwise.
@@ -223,7 +227,7 @@ public: The file being compressed.
\param pCryptograph
- The current CZipCryptograph. Can be \c NULL, if no encryption is used.
+ The current CZipCryptograph. It can be \c NULL, if no encryption is used.
\see
Compress
@@ -245,7 +249,7 @@ public: The file being extracted.
\param pCryptograph
- The current CZipCryptograph. Can be \c NULL, if no decryption is used.
+ The current CZipCryptograph. It can be \c NULL, if no decryption is used.
\see
Decompress
@@ -258,7 +262,7 @@ public: m_pFile = pFile;
m_pCryptograph = pCryptograph;
- m_uComprLeft = m_pFile->GetDataSize(false, true);
+ m_uComprLeft = m_pFile->GetDataSize(true);
m_uUncomprLeft = m_pFile->m_uUncomprSize;
m_uCrc32 = 0;
}
@@ -292,7 +296,7 @@ public: The number of bytes decompressed and written to \a pBuffer.
\note
- This method should be called repeatedly until it returns 0.
+ This method should be called repeatedly until it returns \c 0.
\see
InitDecompression
@@ -368,7 +372,7 @@ public: A factory method that creates an appropriate compressor for the given compression method.
\param uMethod
- The compression method to create a compressor for. Can be one of #CompressionMethod values.
+ The compression method to create a compressor for. It can be one of the #CompressionMethod values.
\param pStorage
The current storage object.
@@ -411,18 +415,54 @@ protected: /**
Flushes data in the buffer into the storage, encrypting the data if needed.
- \note
- Throws exceptions.
*/
void FlushWriteBuffer()
{
- if (m_pCryptograph)
- m_pCryptograph->Encode(m_pBuffer, (DWORD)m_uComprLeft);
- m_pStorage->Write(m_pBuffer, (DWORD)m_uComprLeft, false);
+ WriteBuffer(m_pBuffer, (DWORD)m_uComprLeft);
m_uComprLeft = 0;
}
/**
+ Writes the buffer into the storage, encrypting the data if needed.
+
+ \param pBuffer
+ The buffer with data to write.
+
+ \param uSize
+ The size of the buffer.
+ */
+ void WriteBuffer(char* pBuffer, DWORD uSize)
+ {
+ if (uSize == 0)
+ return;
+ if (m_pCryptograph)
+ m_pCryptograph->Encode(pBuffer, uSize);
+ m_pStorage->Write(pBuffer, uSize, false);
+ }
+
+ /**
+ Fills the read buffer.
+
+ \return
+ The number of bytes read.
+ */
+ DWORD FillBuffer()
+ {
+ DWORD uToRead = m_pBuffer.GetSize();
+ if (m_uComprLeft < uToRead)
+ uToRead = (DWORD)m_uComprLeft;
+
+ if (uToRead > 0)
+ {
+ m_pStorage->Read(m_pBuffer, uToRead, false);
+ if (m_pCryptograph)
+ m_pCryptograph->Decode(m_pBuffer, uToRead);
+ m_uComprLeft -= uToRead;
+ }
+ return uToRead;
+ }
+
+ /**
Initializes the internal buffer.
\see
@@ -442,7 +482,7 @@ protected: }
/**
- Converts internal error code of the compressor to the ZipArchive Library error code.
+ Converts an internal error code of the compressor to the ZipArchive Library error code.
\param iErr
An internal error code.
@@ -464,9 +504,7 @@ protected: \param bInternal
\c true, if \a iErr is an internal error code and needs a conversion to the ZipArchive Library error code; \c false otherwise.
- \note
- Throws exceptions.
-
+
\see
ConvertInternalError
*/
|
