PureZIP_L library

Overview

The purpose of PureZIP is to handle ZIP files.


It uses the static ZLIB 1.2.3. library.


PureZIP_L is a part of the PureZIP package.


Libraries :
PureZIP_O : original ZLIB 1.2.3. static library
PureZIP_W : ZLIB functions
PureZIP_L : ZIP functions

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.

Returns archive handle if success,  #NULL if failed.

AppendMethod

. #APPEND_STATUS_CREATE : create a new archive.
. #APPEND_STATUS_CREATEAFTER : if the file exists and AppendMethod = #APPEND_STATUS_CREATEAFTER,
the zip will be created at the end of the file (usefull if the file contains a self extractor code).
. #APPEND_STATUS_ADDINZIP : if the file exists and AppendMethod = #APPEND_STATUS_ADDINZIP, we will add
files in existing zip (be sure you don't add file that doesn't exist).

Returned value

If the zipfile cannot be opened, the returned value is #NULL.
Else, the returned value is a zipFile handle, usable with the PureZIP_Archive zip functions of this package.
Note : there is no function to delete a file in a zipfile.
If you want delete a file in a zipfile, you must create another.
PureZIP_Archive_Read(ArchiveFileName.s)

Open a ZIP archive for reading.

Returned value

If the zipfile cannot be opened (the file don't exist or is not valid), the returned value is #NULL.
Else, the returned value is a zipFile handle, usable with the PureZIP_Archive unzip functions of this package.
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_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 Dos format [do not use !]
  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.
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)

Add file to current archive.

Parameters

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

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)

Extract current file to disk.

Parameters

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

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)

Add file to archive.

Parameters

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

Returned value

Returns #TRUE if success, else if failed.
PureZIP_AddFiles(ArchiveFileName.s, FileMask.s, StorePath.l, Recursive.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)

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)

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.

Returned value

Returns #TRUE if success, #FALSE if failed.
PureZIP_ExtractFiles(ArchiveFileName.s, FileMask.s, OutputPath.s, ExtractPath.l)

Extract files from archive.

Parameters

FileMask supports wildcards.

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

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 Dos format [do not use !]
  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.
PureZIP_SetArchivePassword(Password.s)

Set current archive password for both compress and extract functions.

To cancel current password, set Password = "".
PureZIP_SetCompressionAlgorithm(Algorithm.l)

Set current compression algorithm.

Algorithms
#Z_NO_COMPRESSION : no compression (store)
#Z_DEFLATED : deflate algorithm
PureZIP_SetCompressionCallback(*ProcedureAddress)

Set PureZIP (de)compression callback address for the functions :
- PureZIP_Archive_Compress()
- PureZIP_Archive_Extract()
- PureZIP_ExtractFile()
- PureZIP_AddFile()
- PureZIP_ExtractFiles()
- PureZIP_AddFiles()
The callback is called in realtime during compression or decompression.
Usefull to indicate the progress when a big file is packed / unpacked.

Procedure MyCallback(FileName.s, Progression.f)
	; 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() returns #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.
Usefull to indicate the progress when many files are packed / unpacked.

Procedure MyCallback(FileName.s, Progression.f)
	; FileName : current processed file (if applicable)
	; Progression : progression percentage)
EndProcedure
PureZIP_GetVersion()

Get PureZIP version string.