ZipFile Class Reference Library » Zip File

#include <lib_zipfile.h>

详细描述

Allows to read/write ZIP files.

私有成员函数

  ZipFile ()
  ~ZipFile ()

Alloc/Free

static ZipFile Alloc ()
static void  Free ( ZipFile *&p)

Static

static Bool   CreateLocalFileName (const Filename &fn, String &str)
static Bool   CreateFilename (const String &str, Filename &fn)
static Bool   GetFileCRC (const Filename &fn, UInt32 &ulCRC)
static UInt32   CalcCRC32 (const void *pBuffer, Int32 lBufferLen, UInt32 ulOldCRC=0)

Open/Extract/Close

Bool   Open (const Filename &fn, const Bool bRead, const Int32 lAppend=0)
Bool   OpenEncrypted (const Filename &fn, const Bool bRead, const char *pchKey, Int32 lKeyLength, Int32 lBlockLength, UInt32 lAESFlags, const Int32 lAppend=0)
Bool   SetSpanning ( UInt32 ulSpan, Bool bOverwrite)
Bool   ExtractToDirectory (const Filename &fnZip, const Filename &fnDir, Int32 lFlags=0x00000001, ExtractDirectoryCallback fn=nullptr, void *pData=nullptr, const char *pChPassword=nullptr)
Bool   关闭 ()
Bool   关闭 (const char *pchGlobalComment)
Bool   关闭 (const String &strGlobalComment)

Write

Bool   CreateFileInZip (const String &strName, ZipWriteInfo *pInfo, void *pExtraFieldLocal, UInt32 lExtraSizeLocal, void *pExtraFieldGlobal, UInt32 lExtraSizeGlobal, String *pstrComment, ZipMethod method, INT lLevel, const char *pchPassword=nullptr, UInt32 ulCryptingCRC=0)
Bool   WriteInFileInZip (const void *pBuffer, const UInt32 lLen, const Int32 lExpectedSize=-1)
Bool   CopyInFileInZip (const Filename &fn, const String &str, const char *pchPassword=nullptr)
Bool   CopyInFileInZip (const Filename &fn, const String &str, UInt32 ulInternalAttributes, UInt32 ulExternalAttributes, const char *pchPassword=nullptr)
Bool   CloseFileInZip ()
Bool   CreateDirectoryInZip (const String &strName, ZipFileTime *pTime)

读取

Bool   GetGlobalInfo ( ZipFileGlobalInfo &i)
Bool   GetGlobalComment ( String &str)
Bool   GoToFirstFile ()
Bool   GoToNextFile ()
Bool   LocateFile (const String &strName)
Bool   GetCurrentFileInfo ( ZipFileInfo &i)
Bool   GetCurrentFileInfo ( String *pstrName, String *pstrComment=nullptr, void *pExtraField=nullptr, UInt32 lExtraFieldSize=0)
Bool   ExtractCurrentFile (const Filename &fnDir, BaseThread *pThread, Int32 lFlags=0x00000001, const char *pchPassword=nullptr, Filename *pfnDest=nullptr)
Bool   ExtractCurrentFile (const Filename &fnDir, Int32 lFlags=0x00000001, const char *pchPassword=nullptr, Filename *pfnDest=nullptr)
Bool   OpenCurrentFile (const char *pChPassword=nullptr)
Bool   CloseCurrentFile ()
Int32   ReadCurrentFile (void *pBuffer, UInt32 lBufferSize)
Int32   GetCurrentFileReadPosition ()
Bool   EndOfCurrentFile ()

Compression Level

Bool   SetCompressionLevel ( Int32 lLevel)
Int32   GetCompressionLevel () const

构造函数 & 析构函数文档编制

◆  ZipFile()

ZipFile () private

◆  ~ZipFile()

~ ZipFile () private

成员函数文档编制

◆  Alloc()

static ZipFile * Alloc ( )
static

Allocates a ZIP file. Destroy the allocated ZIP file with Free() 。使用 AutoAlloc to automate the allocation and destruction based on scope.

返回
The allocated ZIP file, or nullptr if the allocation failed.

◆  Free()

static void Free ( ZipFile *&  p )
static

Destructs ZIP file allocated with Alloc() 。使用 AutoAlloc to automate the allocation and destruction based on scope.

参数
[in,out] p The ZIP file to destruct. If the pointer is nullptr nothing happens. The pointer is assigned nullptr afterwards.

◆  CreateLocalFileName()

static Bool CreateLocalFileName ( const Filename fn ,
String str  
)
static

Creates a local file name.

参数
[in] fn The filename to create from.
[out] str Assigned the local file name to create.
返回
true if successful, otherwise false .

◆  CreateFilename()

static Bool CreateFilename ( const String str ,
Filename fn  
)
static

Creates a file name.

参数
[in] str The file string to create from.
[in] fn Assigned the filename to create.
返回
true if successful, otherwise false .

◆  GetFileCRC()

static Bool GetFileCRC ( const Filename fn ,
UInt32 ulCRC  
)
static

Gets a ZIP file CRC.

参数
[in] fn The filename to get the CRC for.
[out] ulCRC The calculated CRC.
返回
true if successful, otherwise false .

◆  CalcCRC32()

static UInt32 CalcCRC32 ( const void *  pBuffer ,
Int32   lBufferLen ,
UInt32   ulOldCRC = 0  
)
static

Calculates the CRC from a buffer.

参数
[in] pBuffer The buffer to calculate the CRC from.
[in] lBufferLen The buffer length.
[in] ulOldCRC The optional initial CRC value.
返回
The calculated CRC.

◆  Open()

Bool Open ( const Filename fn ,
const Bool   bRead ,
const Int32   lAppend = 0  
)

Opens a ZIP file.

参数
[in] fn The file to open.
[in] bRead true to open for reading, otherwise false .
[in] lAppend The append flags to append the ZIP file to an existing file: ZIP_APPEND
返回
true if successful, otherwise false .

◆  OpenEncrypted()

Bool OpenEncrypted ( const Filename fn ,
const Bool   bRead ,
const char *  pchKey ,
Int32   lKeyLength ,
Int32   lBlockLength ,
UInt32   lAESFlags ,
const Int32   lAppend = 0  
)

Opens an AES encrypted ZIP file, see AESFile .

参数
[in] fn The encrypted file to open.
[in] bRead true to open for reading, otherwise false .
[in] pchKey The decryption key.
[in] lKeyLength The key length. Must be 128 , 192 or 256 (bits).
[in] lBlockLength The block size. Must be 128 , 192 or 256 (bits).
[in] lAESFlags Reserved for later use. Must be set to 0 .
[in] lAppend The append flags to append the ZIP file to an existing file: ZIP_APPEND
返回
true if successful, otherwise false .

◆  SetSpanning()

Bool SetSpanning ( UInt32   ulSpan ,
Bool   bOverwrite  
)

Sets the maximum size of the ZIP file. A new file is created with the same name and a consecutive number if it exceeds this size.

注意
Call immediately after opening a ZIP file for writing.
参数
[in] ulSpan The maximum size of the file.
[in] bOverwrite true the next file is overwritten.
返回
true if successful, otherwise false .

◆  ExtractToDirectory()

Bool ExtractToDirectory ( const Filename fnZip ,
const Filename fnDir ,
Int32   lFlags = 0x00000001 ,
ExtractDirectoryCallback   fn = nullptr ,
void *  pData = nullptr ,
const char *  pChPassword = nullptr  
)

Extracts the ZIP file to the specified directory.

参数
[in] fnZip The ZIP filename.
[in] fnDir The directory to extract to.
[in] lFlags The extract flags: ZIP_EXTRACT
[in] fn The extract callback.
[in] pData The private data for the extract callback.
[in] pChPassword An optional password.
返回
true if successful, otherwise false .

◆  Close() [1/3]

Bool 关闭 ( )

Closes the ZIP file.

返回
true if successful, otherwise false .

◆  Close() [2/3]

Bool 关闭 ( const char *  pchGlobalComment )

Closes the ZIP file and writes a comment.

注意
Comments are only written if the file is saved.
参数
[in] pchGlobalComment The global comment string.
返回
true if successful, otherwise false .

◆  Close() [3/3]

Bool 关闭 ( const String strGlobalComment )

Closes the ZIP file and writes a comment.

注意
Comments are only written if the file is saved.
参数
[in] strGlobalComment The global comment string.
返回
true if successful, otherwise false .

◆  CreateFileInZip()

Bool CreateFileInZip ( const String strName ,
ZipWriteInfo pInfo ,
void *  pExtraFieldLocal ,
UInt32   lExtraSizeLocal ,
void *  pExtraFieldGlobal ,
UInt32   lExtraSizeGlobal ,
String pstrComment ,
ZipMethod   method ,
INT   lLevel ,
const char *  pchPassword = nullptr ,
UInt32   ulCryptingCRC = 0  
)

Creates a file in the ZIP file.

注意
Directories must be separated by a slash.
参数
[in] strName The file name.
[in] pInfo The write information.
[in] pExtraFieldLocal The extra local field.
[in] lExtraSizeLocal The extra local size.
[in] pExtraFieldGlobal The extra global field.
[in] lExtraSizeGlobal The extra global size.
[in] pstrComment The comment string.
[in] method The ZIP method: ZipMethod
[in] lLevel The ZIP compression level, between 0 and 9 .
[in] pchPassword An optional password.
[in] ulCryptingCRC An optional encryption CRC.
返回
true if successful, otherwise false .

◆  WriteInFileInZip()

Bool WriteInFileInZip ( const void *  pBuffer ,
const UInt32   lLen ,
const Int32   lExpectedSize = -1  
)

Writes a buffer in the ZIP file.

参数
[in] pBuffer The buffer to write.
[in] lLen The buffer length.
[in] lExpectedSize An optional expected size.
返回
true if successful, otherwise false .

◆  CopyInFileInZip() [1/2]

Bool CopyInFileInZip ( const Filename fn ,
const String str ,
const char *  pchPassword = nullptr  
)

Copies a file in the ZIP file.

参数
[in] fn The file to copy.
[in] str The destination file name.
[in] pchPassword An optional password.
返回
true if successful, otherwise false .

◆  CopyInFileInZip() [2/2]

Bool CopyInFileInZip ( const Filename fn ,
const String str ,
UInt32   ulInternalAttributes ,
UInt32   ulExternalAttributes ,
const char *  pchPassword = nullptr  
)

Copies a file in the ZIP file.

参数
[in] fn The file to copy.
[in] str The destination file name.
[in] ulInternalAttributes The internal file attributes.
[in] ulExternalAttributes The external file attributes.
[in] pchPassword An optional password.
返回
true if successful, otherwise false .

◆  CloseFileInZip()

Bool CloseFileInZip ( )

Closes a file in the ZIP file.

返回
true if successful, otherwise false .

◆  CreateDirectoryInZip()

Bool CreateDirectoryInZip ( const String strName ,
ZipFileTime pTime  
)

Creates a directory in the ZIP file. A slash is added if necessary.

参数
[in] strName The directory name.
[in] pTime The directory time.
返回
true if successful, otherwise false .

◆  GetGlobalInfo()

Bool GetGlobalInfo ( ZipFileGlobalInfo i )

Retrieves the global information.

参数
[out] i Filled with the global information.
返回
true if successful, otherwise false .

◆  GetGlobalComment()

Bool GetGlobalComment ( String str )

Retrieves the global comment.

参数
[out] str Filled with the global comment.
返回
true if successful, otherwise false .

◆  GoToFirstFile()

Bool GoToFirstFile ( )

Goes to the first file.

返回
true if successful, otherwise false .

◆  GoToNextFile()

Bool GoToNextFile ( )

Goes to the next file.

返回
true if successful, otherwise false .

◆  LocateFile()

Bool LocateFile ( const String strName )

Locates a file.

参数
[in] strName The file name to locate.
返回
true if successful, otherwise false .

◆  GetCurrentFileInfo() [1/2]

Bool GetCurrentFileInfo ( ZipFileInfo i )

Retrieves the information for the current file.

参数
[out] i Filled with the current file information.
返回
true if successful, otherwise false .

◆  GetCurrentFileInfo() [2/2]

Bool GetCurrentFileInfo ( String pstrName ,
String pstrComment = nullptr ,
void *  pExtraField = nullptr ,
UInt32   lExtraFieldSize = 0  
)

Retrieves the information for the current file.

参数
[out] pstrName Filled with the current file name.
[out] pstrComment Filled with the current file comment.
[out] pExtraField Filled with the current file extra field.
[out] lExtraFieldSize Filled with the current file extra field size.
返回
true if successful, otherwise false .

◆  ExtractCurrentFile() [1/2]

Bool ExtractCurrentFile ( const Filename fnDir ,
BaseThread pThread ,
Int32   lFlags = 0x00000001 ,
const char *  pchPassword = nullptr ,
Filename pfnDest = nullptr  
)

Extracts the contents of the current archive to the directory fnDir .

参数
[in] fnDir The directory to extract the files to.
[in] pThread The thread for extracting in an own thread.
[in] lFlags The extract flags: ZIP_EXTRACT
[in] pchPassword An optional password.
[out] pfnDest An optional filename pointer filled with the destination.
返回
true if successful, otherwise false .

◆  ExtractCurrentFile() [2/2]

Bool ExtractCurrentFile ( const Filename fnDir ,
Int32   lFlags = 0x00000001 ,
const char *  pchPassword = nullptr ,
Filename pfnDest = nullptr  
)

Extracts the contents of the current archive to the directory fnDir .

参数
[in] fnDir The directory to extract the files to.
[in] lFlags The extract flags: ZIP_EXTRACT
[in] pchPassword An optional password.
[out] pfnDest An optional filename pointer filled with the destination.
返回
true if successful, otherwise false .

◆  OpenCurrentFile()

Bool OpenCurrentFile ( const char *  pChPassword = nullptr )

Opens the current file with password protection.

参数
[in] pChPassword An optional password.
返回
true if successful, otherwise false .

◆  CloseCurrentFile()

Bool CloseCurrentFile ( )

Closes the current file.

返回
true if successful, otherwise false .

◆  ReadCurrentFile()

Int32 ReadCurrentFile ( void *  pBuffer ,
UInt32   lBufferSize  
)

Reads a buffer from the current file.

参数
[in,out] pBuffer The buffer to read to.
[in,out] lBufferSize The buffer size.
返回
The number of bytes read, or < 0 if there was an error.

◆  GetCurrentFileReadPosition()

Int32 GetCurrentFileReadPosition ( )

Gets the read position in the current file.

返回
The current read position.

◆  EndOfCurrentFile()

Bool EndOfCurrentFile ( )

Checks for the end of the current file.

返回
true if end of current file, otherwise false .

◆  SetCompressionLevel()

Bool SetCompressionLevel ( Int32   lLevel )

Sets the compression level of the ZIP file.

注意
Must be called before opening and initializing the file.
参数
[in] lLevel The compression level, ranges from 0 (min) to 9 (max).
返回
true if successful, otherwise false .

◆  GetCompressionLevel()

Int32 GetCompressionLevel ( ) const

Gets the compression level of the ZIP file.

返回
The compression level, ranges from 0 (min) to 9 (max).