PureZIP library

Overview

The purpose of PureZIP is to handle ZIP files (PB4.6x version).


It uses the static ZLIB 1.2.3. library.

Notes :
1. If you upgrade from PureZIP 1.xx, please note that PureZIP V2 requires an additional parameter for the compression and progression callbacks.
2. You can't mix 'Archive' functions with 'Standalone' functions !

Additional notes :
1. Unicode : the ZIP standard doesn't support unicode files names. In a (PKZIP 2.04g) ZIP archive, the filenames are stored as OEM (MS-DOS, remember ?). The unicode version of PureZIP translates unicode to OEM and vice-versa. It works, but it is not 'true' unicode support...
Some newer archivers (like Pkzip 4.5+ / Winzip 11.2+) store unicode names using the UTF-8 standard. This method isn't compatible with older ZIP packers. Others store Unicode names in an extra field (like the Info-Zip method). But there is no real standard. If you need real unicode support, better use RAR or 7-ZIP.
2. Archive size : PureZIP (ZLIB) should support archive sizes up to 4GB. However ZIP is not recommended for big archives, because some compressors achieve much better compression ratio (RAR, 7-ZIP, ...), and ZIP doesn't have recovery capabilities like RAR for example.

Functions

PureZIP_PackMemory(*SourceMemoryID, SourceLength.l, *DestinationMemoryID, *DestinationLength)
Pack the content of the *SourceMemory area into the *DestinationMemory.

Parameters

DestinationLength = SourceLength + (SourceLength * 0.01) + 12

SourceLength is the byte length of the source buffer.

Upon entry, *DestinationLength points to the total size of the destination buffer.
Upon exit, *DestinationLength points to the actual size of the compressed buffer.

Returned value

#Z_OK if success ;
#Z_MEM_ERROR if there was not enough memory ;
#Z_BUF_ERROR if there was not enough room in the *DestinationMemory buffer.
PureZIP_UnpackMemory(*SourceMemoryID, SourceLength.l, *DestinationMemoryID, *DestinationLength)
Unpack the content of the *SourceMemory area into the *DestinationMemory.

Parameters

SourceLength is the byte length of the source buffer.

Upon entry, *DestinationLength points to the total size of the destination buffer,
which must be large enough to hold the entire uncompressed data.
(The size of the uncompressed data must have been saved previously by
the compressor and transmitted to the decompressor by some mechanism
outside the scope of this compression library.)

Upon exit, *DestinationLength points to the actual size of the compressed buffer.

Returned value

#Z_OK if success ;
#Z_MEM_ERROR if there was not enough memory ;
#Z_BUF_ERROR if there was not enough room in the *DestinationMemory buffer.
PureZIP_Archive_Create(ArchiveFileName.s, AppendMethod.l)
Create a ZIP archive.

AppendMethod

. #APPEND_STATUS_CREATE : create a new archive.
. #APPEND_STATUS_ADDINZIP : add files to an existing archive.
. #APPEND_STATUS_CREATEAFTER : the archive will be created at the end of the file,
useful if the file contains a self extractor code.

Returned value

Returns archive handle if success, #NULL if failed.

Note : to delete a file in an archive, you may use PureZIP_DeleteFile().
PureZIP_Archive_Read(ArchiveFileName.s)
Open a ZIP archive for reading.

Returned value

Returns archive handle if success, #NULL if failed.

Note : to delete a file in an archive, you may use PureZIP_DeleteFile().
PureZIP_Archive_ReadInMemory(*MemoryBank, MemoryBankSize.l)
Open a ZIP archive in memory for reading.

Returned value

Returns archive handle if success, #NULL if failed.
PureZIP_Archive_Close([GlobalComment.s])
Close current archive.

If the archive is in write mode, you can add a global comment.
PureZIP_Archive_GlobalInfo(*GlobalInfo.unz_global_info)
Get global info for current archive.

Parameter

Structure unz_global_info
number_entry.l ; total number of entries in the zipfile
size_comment.l ; size of the global comment of the zipfile
EndStructure

Returned value

Returns #UNZ_OK if success.
PureZIP_Archive_GlobalComment()
Get the archive global comment (if any).
PureZIP_Archive_CheckCRC()
Check current file integrity (using stored checksum).

Returned value
#True : passed
#False : current file is corrupt !
PureZIP_Archive_FileInfo(*FileInfo.PureZIP_FileInfo)
Get file information from current file in current archive.

Parameter

Structure PureZIP_FileInfo
Version.l ; version made by
VersionNeeded.l ; version needed to extract
flag.l ; general purpose bit flag [if bit 0 is set the file is encrypted]
CompressionMethod.l ; compression method [0 - 10]
dosDate.l ; last mod file date in MS-DOS format
Crc32.l ; crc-32
CompressedSize.l ; compressed size
unCompressedSize.l ; uncompressed size
SizeFilename.l ; filename length
SizeFileExtra.l ; extra field length
SizeFileComment.l ; file comment length
DiskNumStart.l ; disk number start
internal_fa.l ; internal file attributes
external_fa.l ; external file attributes (packed file attributes)
tmu_date.tm_date ; file date (see tm_date structure) [use this to get filedate!]
FileName.s ; filename
EndStructure

Structure tm_date
tm_sec.l ; seconds after the minute - [0,59]
tm_min.l ; minutes after the hour - [0,59]
tm_hour.l ; hours since midnight - [0,23]
tm_mday.l ; day of the month - [1,31]
tm_mon.l ; months since January - [0,11]
tm_year.l ; years - [1980..2044]
EndStructure

; Flags :
;
; Bit 0: If set, indicates that the file is encrypted.
;
; (For Method 6 - Imploding)
; Bit 1: If the compression method used was type 6,
; Imploding, then this bit, if set, indicates
; an 8K sliding dictionary was used. If clear,
; then a 4K sliding dictionary was used.
; Bit 2: If the compression method used was type 6,
; Imploding, then this bit, if set, indicates
; an 3 Shannon-Fano trees were used to encode the
; sliding dictionary output. If clear, then 2
; Shannon-Fano trees were used.
;
; (For Method 8 - Deflating)
; Bit 2 Bit 1
; 0 0 Normal (-en) compression option was used.
; 0 1 Maximum (-ex) compression option was used.
; 1 0 Fast (-ef) compression option was used.
; 1 1 Super Fast (-es) compression option was used.
;
; Note: Bits 1 and 2 are undefined if the compression
; method is any other.
;
; Bit 3: If this bit is set, the fields crc-32, compressed size
; and uncompressed size are set to zero in the local
; header. The correct values are put in the data descriptor
; immediately following the compressed data. (Note: PKZIP
; version 2.04g for DOS only recognizes this bit for method 8
; compression, newer versions of PKZIP recognize this bit
; for any compression method.)
;
; Compression Method :
;
; 0 - The file is stored (no compression)
; 1 - The file is Shrunk
; 2 - The file is Reduced with compression factor 1
; 3 - The file is Reduced with compression factor 2
; 4 - The file is Reduced with compression factor 3
; 5 - The file is Reduced with compression factor 4
; 6 - The file is Imploded
; 7 - Reserved for Tokenizing compression algorithm
; 8 - The file is Deflated
; 9 - Reserved for enhanced Deflating
; 10 - PKWARE Date Compression Library Imploding

Returned value

Returns #UNZ_OK if success.

Note

ZLIB can handle files up to 4 Gbytes, but PB longs are signed [0 - 2 Gbytes]...
So if you expect PureZIP_FileInfo\CompressedSize > 2 Gbytes or PureZIP_FileInfo\unCompressedSize > 2 Gbytes,
use quads and convert signed to unsigned !
Example : Size.q = FileInfo\unCompressedSize & $FFFFFFFF
PureZIP_Archive_Locate(FileName.s)
Locate file in archive.

Returned value

Returns #UNZ_OK if found, it becomes the current file.
PureZIP_Archive_FindFirst()
Find first file in archive.

Returned value

Returns #UNZ_OK if success.
PureZIP_Archive_FindNext()
Find next file in archive.

Returned value

Returns #UNZ_OK if success, or #UNZ_END_OF_LIST_OF_FILE if no more files.
PureZIP_Archive_Compress(FileName.s, StorePath.l [, UserParam.l])
Add file to current archive.

Parameters

StorePath values :
#TRUE : the complete filename (including path) is stored ;
#FALSE : only filename is stored.

UserParam : a user value transmitted to the callback (if defined).

Returned value

Returns #Z_OK if success, else is error code.

Note : PureZIP_Archive_Compress() will return -1 as a warning if you try to compress
an empty file (length = 0 -> no compressed data), yet the file will be present in the archive.
PureZIP_Archive_CompressMem(FileName.s, *MemoryBank, MemoryBankSize.l)
Add memory bank to current archive.

Returned value

Returns #Z_OK if success, else is error code.
PureZIP_Archive_Extract(OutputPath.s, ExtractPath.l [, UserParam.l])
Extract current file to disk.

Parameters

ExtractPath values :
#TRUE : the complete filename (including path) is extracted ;
#FALSE : only filename is extracted.

UserParam : a user value transmitted to the callback (if defined).

Returned value

Returns #UNZ_OK if success, else is error.
PureZIP_Archive_ExtractMem(*MemoryBank, MemoryBankSize.l)
Extract current file to memory.

Returned value

Returns number of bytes written (error if < 0).
PureZIP_AddFile(ArchiveFileName.s, FileName.s, StorePath.l [, UserParam.l])
Add file to archive.

Parameters

StorePath values :
#PureZIP_DontStorePath = 0 ; do not store file path
#PureZIP_StorePathAbsolute = 1 ; store path

UserParam : a user value transmitted to the callback (if defined).

Returned value

Returns #TRUE if success, else if failed.
PureZIP_AddFiles(ArchiveFileName.s, FileMask.s, StorePath.l, Recursive.l [, UserParam.l])
Add files to archive.

Parameters

FileMask supports wildcards.

StorePath values :
#PureZIP_DontStorePath = 0 ; do not store file path
#PureZIP_StorePathAbsolute = 1 ; store path
#PureZIP_StorePathRelative = 2 ; store path relative to base directory

Recursive values :
#PureZIP_NotRecursive = 0 ; no recursive search
#PureZIP_Recursive = 1 ; recursive file search
#PureZIP_RecursiveZeroDirs = 2 ; recursive file search and add empty directories
(use only if necessary)

UserParam : a user value transmitted to the callback (if defined).

Returned value

Returns number of added files, #NULL if failed.
PureZIP_AddMemory(ArchiveFileName.s, FileName.s, *MemoryBank, MemoryBankSize.l)
Add memory bank to archive.

Returned value

Returns #TRUE if success, else if failed.
PureZIP_ExtractFile(ArchiveFileName.s, FileNumberInArchive.l, OutputPath.s, ExtractPath.l [, UserParam.l])
Extract file from archive to disk.

Parameters

FileNumberInArchive : file position in archive (can be found with PureZIP_FindFile()).

ExtractPath values :
#TRUE : the complete filename (including path) is extracted ;
#FALSE : only filename is extracted.

UserParam : a user value transmitted to the callback (if defined).

Returned value

Returns #TRUE if success, #FALSE if failed.
PureZIP_ExtractFiles(ArchiveFileName.s, FileMask.s, OutputPath.s, ExtractPath.l [, UserParam.l])
Extract files from archive.

Parameters

FileMask supports wildcards.

ExtractPath values :
#TRUE : the complete filename (including path) is extracted ;
#FALSE : only filename is extracted.

UserParam : a user value transmitted to the callback (if defined).

Returned value

Returns number of extracted files, #NULL if failed.
PureZIP_ExtractMemory(ArchiveFileName.s, FileNumberInArchive.l, *MemoryBank, MemoryBankSize.l)
Extract file from archive to memory.

Parameters

FileNumberInArchive : file position in archive (can be found with PureZIP_FindFile()).

Returned value

Returns number of bytes written (error if < 0).
PureZIP_FindFile(ArchiveFileName.s, FileName.s [, IncludingPath.l])
Find file in archive.

Parameters

If IncludingPath = #FALSE (default), search only for filename.
If IncludingPath = #TRUE, search for path + filename.

Returned value

Returns file number in archive, -1 if not found.
PureZIP_GetFileCount(ArchiveFileName.s)
Count files in archive.

Returned value

Returns number of files, <0 if failed.
PureZIP_GetFileInfo(ArchiveFileName.s, FileNumberInArchive.l, *FileInfo.PureZIP_FileInfo)
Get archive information.

Parameter

Structure PureZIP_FileInfo
Version.l ; version made by
VersionNeeded.l ; version needed to extract
flag.l ; general purpose bit flag [if bit 0 is set the file is encrypted]
CompressionMethod.l ; compression method [0 - 10]
dosDate.l ; last mod file date in MS-DOS format
Crc32.l ; crc-32
CompressedSize.l ; compressed size
unCompressedSize.l ; uncompressed size
SizeFilename.l ; filename length
SizeFileExtra.l ; extra field length
SizeFileComment.l ; file comment length
DiskNumStart.l ; disk number start
internal_fa.l ; internal file attributes
external_fa.l ; external file attributes (packed file attributes)
tmu_date.tm_date ; file date (see tm_date structure) [use this to get filedate!]
FileName.s ; filename
EndStructure

Structure tm_date
tm_sec.l ; seconds after the minute - [0,59]
tm_min.l ; minutes after the hour - [0,59]
tm_hour.l ; hours since midnight - [0,23]
tm_mday.l ; day of the month - [1,31]
tm_mon.l ; months since January - [0,11]
tm_year.l ; years - [1980..2044]
EndStructure

; Flags :
;
; Bit 0: If set, indicates that the file is encrypted.
;
; (For Method 6 - Imploding)
; Bit 1: If the compression method used was type 6,
; Imploding, then this bit, if set, indicates
; an 8K sliding dictionary was used. If clear,
; then a 4K sliding dictionary was used.
; Bit 2: If the compression method used was type 6,
; Imploding, then this bit, if set, indicates
; an 3 Shannon-Fano trees were used to encode the
; sliding dictionary output. If clear, then 2
; Shannon-Fano trees were used.
;
; (For Method 8 - Deflating)
; Bit 2 Bit 1
; 0 0 Normal (-en) compression option was used.
; 0 1 Maximum (-ex) compression option was used.
; 1 0 Fast (-ef) compression option was used.
; 1 1 Super Fast (-es) compression option was used.
;
; Note: Bits 1 and 2 are undefined if the compression
; method is any other.
;
; Bit 3: If this bit is set, the fields crc-32, compressed size
; and uncompressed size are set to zero in the local
; header. The correct values are put in the data descriptor
; immediately following the compressed data. (Note: PKZIP
; version 2.04g for DOS only recognizes this bit for method 8
; compression, newer versions of PKZIP recognize this bit
; for any compression method.)
;
; Compression Method :
;
; 0 - The file is stored (no compression)
; 1 - The file is Shrunk
; 2 - The file is Reduced with compression factor 1
; 3 - The file is Reduced with compression factor 2
; 4 - The file is Reduced with compression factor 3
; 5 - The file is Reduced with compression factor 4
; 6 - The file is Imploded
; 7 - Reserved for Tokenizing compression algorithm
; 8 - The file is Deflated
; 9 - Reserved for enhanced Deflating
; 10 - PKWARE Date Compression Library Imploding

Returned value

Returns #TRUE if success, #FALSE if failed.

Note

ZLIB can handle files up to 4 Gbytes, but PB longs are signed [0 - 2 Gbytes]...
So if you expect PureZIP_FileInfo\CompressedSize > 2 Gbytes or PureZIP_FileInfo\unCompressedSize > 2 Gbytes,
use quads and convert signed to unsigned !
Example : Size.q = FileInfo\unCompressedSize & $FFFFFFFF
PureZIP_DeleteFile(ArchiveFileName.s, FileToDelete.s)
Delete a file in archive.

Parameters

ArchiveFilename : Archive full path
FileToDelete : Archived file to delete

Returned value

Returns #TRUE if succeeded, #NULL if failed.
PureZIP_RenameFile(ArchiveFileName.s, OldFileName.s, NewFileName.s)
Rename a file in archive.

Rename the old filename to the new filename

Parameters

ArchiveFilename : Archive full path
OldFileName : Archived file old name
NewFileName : Archived file new name

Returned value

Returns #TRUE if succeeded, #NULL if failed.
PureZIP_SetArchivePassword(Password.s)
Set current archive password for both compress and extract functions.

Default is no password.

To cancel current password, set Password = "" (no password).
PureZIP_SetCompressionAlgorithm(Algorithm.l)
Set current compression algorithm.

Algorithms

#Z_NO_COMPRESSION : no compression (store)
#Z_DEFLATED : deflate algorithm [Default]
PureZIP_SetCompressionLevel(CompressionLevel.l)
Set current compression level for DEFLATE algorithm.

CompressionLevel

Valid values : 1 to 9.
#Z_BEST_SPEED [=1] : best compression speed
#Z_BEST_COMPRESSION [=9] : best compression ratio [Default]

However, the deflate algorithm with #Z_BEST_COMPRESSION is so fast
that there is no point using any other compression level.
PureZIP_SetCompressionCallback(*ProcedureAddress)
Set PureZIP (de)compression callback address for the functions :

- PureZIP_Archive_CheckCRC()
- PureZIP_Archive_Compress()
- PureZIP_Archive_Extract()
- PureZIP_ExtractFile()
- PureZIP_AddFile()
- PureZIP_ExtractFiles()
- PureZIP_AddFiles()

The callback is called in realtime during compression, decompression or CRC check.
Useful to indicate the progress when a big file is packed / unpacked.

Procedure MyCallback(FileName.s, Progression.f, UserParam.l)
; FileName : current processed file (if applicable)
; Progression : progression percentage)
ProcedureReturn #False
; ProcedureReturn #True to stop the compression
EndProcedure


Returned value [only for PureZIP_Archive_Compress() and PureZIP_Archive_Extract()]

#FALSE : compression / extraction continues

#TRUE : compression / extraction stops !
PureZIP_Archive_Compress() and PureZIP_Archive_Extract() return #PureZIP_CallbackStop error
PureZIP_SetProgressionCallback(*ProcedureAddress)
Set PureZIP progression callback address for the functions :

- PureZIP_ExtractFiles()
- PureZIP_AddFiles()

The callback is called each time a new file is processed.
Useful to indicate the progress when many files are packed / unpacked.

Procedure MyCallback(FileName.s, Progression.f, UserParam.l)
; FileName : current processed file (if applicable)
; Progression : progression percentage)
EndProcedure
PureZIP_GetVersion()
Get PureZIP version string.