PureZIP library
Overview
The purpose of PureZIP is to handle ZIP files (PB4.6x version).Functions
PureZIP_PackMemory(*SourceMemoryID, SourceLength.l, *DestinationMemoryID, *DestinationLength)Pack the content of the *SourceMemory area into the *DestinationMemory.PureZIP_UnpackMemory(*SourceMemoryID, SourceLength.l, *DestinationMemoryID, *DestinationLength)
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.
Unpack the content of the *SourceMemory area into the *DestinationMemory.PureZIP_Archive_Create(ArchiveFileName.s, AppendMethod.l)
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.
Create a ZIP archive.PureZIP_Archive_Read(ArchiveFileName.s)
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().
Open a ZIP archive for reading.PureZIP_Archive_ReadInMemory(*MemoryBank, MemoryBankSize.l)
Returned value
Returns archive handle if success, #NULL if failed.
Note : to delete a file in an archive, you may use PureZIP_DeleteFile().
Open a ZIP archive in memory for reading.PureZIP_Archive_Close([GlobalComment.s])
Returned value
Returns archive handle if success, #NULL if failed.
Close current archive.PureZIP_Archive_GlobalInfo(*GlobalInfo.unz_global_info)
If the archive is in write mode, you can add a global comment.
Get global info for current archive.PureZIP_Archive_GlobalComment()
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.
Get the archive global comment (if any).PureZIP_Archive_CheckCRC()
Check current file integrity (using stored checksum).PureZIP_Archive_FileInfo(*FileInfo.PureZIP_FileInfo)
Returned value
#True : passed
#False : current file is corrupt !
Get file information from current file in current archive.PureZIP_Archive_Locate(FileName.s)
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
Locate file in archive.PureZIP_Archive_FindFirst()
Returned value
Returns #UNZ_OK if found, it becomes the current file.
Find first file in archive.PureZIP_Archive_FindNext()
Returned value
Returns #UNZ_OK if success.
Find next file in archive.PureZIP_Archive_Compress(FileName.s, StorePath.l [, UserParam.l])
Returned value
Returns #UNZ_OK if success, or #UNZ_END_OF_LIST_OF_FILE if no more files.
Add file to current archive.PureZIP_Archive_CompressMem(FileName.s, *MemoryBank, MemoryBankSize.l)
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.
Add memory bank to current archive.PureZIP_Archive_Extract(OutputPath.s, ExtractPath.l [, UserParam.l])
Returned value
Returns #Z_OK if success, else is error code.
Extract current file to disk.PureZIP_Archive_ExtractMem(*MemoryBank, MemoryBankSize.l)
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.
Extract current file to memory.PureZIP_AddFile(ArchiveFileName.s, FileName.s, StorePath.l [, UserParam.l])
Returned value
Returns number of bytes written (error if < 0).
Add file to archive.PureZIP_AddFiles(ArchiveFileName.s, FileMask.s, StorePath.l, Recursive.l [, UserParam.l])
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.
Add files to archive.PureZIP_AddMemory(ArchiveFileName.s, FileName.s, *MemoryBank, MemoryBankSize.l)
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.
Add memory bank to archive.PureZIP_ExtractFile(ArchiveFileName.s, FileNumberInArchive.l, OutputPath.s, ExtractPath.l [, UserParam.l])
Returned value
Returns #TRUE if success, else if failed.
Extract file from archive to disk.PureZIP_ExtractFiles(ArchiveFileName.s, FileMask.s, OutputPath.s, ExtractPath.l [, UserParam.l])
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.
Extract files from archive.PureZIP_ExtractMemory(ArchiveFileName.s, FileNumberInArchive.l, *MemoryBank, MemoryBankSize.l)
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.
Extract file from archive to memory.PureZIP_FindFile(ArchiveFileName.s, FileName.s [, IncludingPath.l])
Parameters
FileNumberInArchive : file position in archive (can be found with PureZIP_FindFile()).
Returned value
Returns number of bytes written (error if < 0).
Find file in archive.PureZIP_GetFileCount(ArchiveFileName.s)
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.
Count files in archive.PureZIP_GetFileInfo(ArchiveFileName.s, FileNumberInArchive.l, *FileInfo.PureZIP_FileInfo)
Returned value
Returns number of files, <0 if failed.
Get archive information.PureZIP_DeleteFile(ArchiveFileName.s, FileToDelete.s)
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
Delete a file in archive.PureZIP_RenameFile(ArchiveFileName.s, OldFileName.s, NewFileName.s)
Parameters
ArchiveFilename : Archive full path
FileToDelete : Archived file to delete
Returned value
Returns #TRUE if succeeded, #NULL if failed.
Rename a file in archive.PureZIP_SetArchivePassword(Password.s)
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.
Set current archive password for both compress and extract functions.PureZIP_SetCompressionAlgorithm(Algorithm.l)
Default is no password.
To cancel current password, set Password = "" (no password).
Set current compression algorithm.PureZIP_SetCompressionLevel(CompressionLevel.l)
Algorithms
#Z_NO_COMPRESSION : no compression (store)
#Z_DEFLATED : deflate algorithm [Default]
Set current compression level for DEFLATE algorithm.PureZIP_SetCompressionCallback(*ProcedureAddress)
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.
Set PureZIP (de)compression callback address for the functions :PureZIP_SetProgressionCallback(*ProcedureAddress)
- 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
Set PureZIP progression callback address for the functions :PureZIP_GetVersion()
- 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
Get PureZIP version string.