Gorilla.Utils.Zip
Unit Gorilla.Utils.Zip.pasClasses
- EZipException = class ( Exception )
- TGorillaZipFile = class ( TObject )
Records
- record TZipEndOfCentralHeader
- record TZipHeader
Enumerations
- enum TZipCompression = ( zcStored, zcShrunk, zcReduce1, zcReduce2, zcReduce3, zcReduce4, zcImplode, zcTokenize, zcDeflate, zcDeflate64, zcPKImplode, zcBZIP2, zcLZMA, zcTERSE, zcLZ77, zcWavePack, zcPPMdI1 ) ;
- enum TZipMode = ( zmClosed, zmRead, zmReadWrite, zmWrite ) ;
Constants
- const SIGNATURE_ZIPENDOFHEADER : Cardinal = ;
- const SIGNATURE_CENTRALHEADER : Cardinal = ;
- const SIGNATURE_LOCALHEADER : Cardinal = ;
- const LOCALHEADERSIZE : Integer = $1A;
- const CENTRALHEADERSIZE : Integer = $2A;
- const MADEBY_MSDOS : Integer = $0;
- const MADEBY_UNIX : Integer = $3;
Mics. types
- type PZipHeader = pointer to TZipHeader;
Functions / Procedures
- public function TZipCompressionToString
(
Compression :
TZipCompression
)
: string
;
Converts ZIP compression method value to string
TZipCompression
Zip Compression Method Enumeration
TZipHeader
Fields
- public MadeByVersion :
Word
- public RequiredVersion :
Word
- public Flag :
Word
- public CompressionMethod :
Word
- public ModifiedDateTime :
Cardinal
- public CRC32 :
Cardinal
- public CompressedSize :
Cardinal
- public UncompressedSize :
Cardinal
- public FileNameLength :
Word
- public ExtraFieldLength :
Word
- public FileCommentLength :
Word
- public DiskNumberStart :
Word
- public InternalAttributes :
Word
- public ExternalAttributes :
Cardinal
- public LocalHeaderOffset :
Cardinal
- public FileName :
TBytes
- public ExtraField :
TBytes
- public FileComment :
TBytes
TGorillaZipFile
Class for creating and reading .ZIP files.
Ancestors
Members
Fields
- private FCompressionHandler :
TGorillaZipFile.TCompressionDict
- private FOnCreateDecompressStream :
TOnCreateCustomStream
- private FCreateDecompressStreamCallBack :
TCreateCustomStreamCallBack
- private FMode :
TZipMode
- private FStream :
TStream
- private FFileStream :
TFileStream
- private FStartFileData :
Int64
- private FEndFileData :
Int64
- private FFiles :
TList<Gorilla.Utils.Zip.TZipHeader>
- private FComment :
TBytes
- private FUTF8Support :
Boolean
- private FOnProgress :
TZipProgressEvent
- private FCurrentFile :
string
- private FCurrentHeader :
TZipHeader
Methods
- public constructor Create
(
)
;
Create a TGorillaZipFile
- public destructor Destroy ( ) ;
- private function TBytesToString ( B : TBytes ) : string ;
- private function StringToTBytes ( S : string ) : TBytes ;
- private function GetFileComment ( Index : Integer ) : string ;
- private function GetFileCount ( ) : Integer ;
- private function GetFileInfo ( Index : Integer ) : TZipHeader ;
- private function GetFileInfos ( ) : TArray<Gorilla.Utils.Zip.TZipHeader> ;
- private function GetFileName ( Index : Integer ) : string ;
- private function GetFileNames ( ) : TArray<System.string> ;
- private function GetComment ( ) : string ;
- private procedure ReadCentralHeader ( ) ;
- private procedure SetFileComment ( Index : Integer; Value : string ) ;
- private procedure SetComment ( Value : string ) ;
- private procedure SetUTF8Support ( const Value : Boolean ) ;
- private function LocateEndOfCentralHeader ( var Header : TZipEndOfCentralHeader ) : Boolean ;
- private procedure DoZLibProgress ( Sender : TObject ) ;
- protected procedure CheckFileName ( const ArchiveFileName : string ) ; virtual;
- class private procedure Create@ ( ) ; class constructor noself;
- class private procedure Destroy@ ( ) ; class destructor noself;
- public procedure RegisterCompressionHandler ( Compression : TZipCompression; CompressStream : TStreamConstructor; DecompressStream : TStreamConstructor ) ; class;
- public function IsValid
(
const
ZipFileName :
string
)
: Boolean
;
static;
Parameters
- const ZipFileName : string - Path to Zip File
- public procedure ExtractZipFile
(
const
ZipFileName :
string; const
Path :
string; ZipProgress :
TZipProgressEvent
=
nil
)
;
static;
Extract a ZipFile
Parameters
- const ZipFileName : string - File name of the ZIP filePath to extract to diskOn progress callback.
- const Path : string - File name of the ZIP filePath to extract to diskOn progress callback.
- ZipProgress : TZipProgressEvent = nil - File name of the ZIP filePath to extract to diskOn progress callback.
- public procedure ZipDirectoryContents
(
const
ZipFileName :
string; const
Path :
string; Compression :
TZipCompression
=
zcDeflate
; ZipProgress :
TZipProgressEvent
=
nil
)
;
static;
Zip the contents of a directory
Parameters
- const ZipFileName : string - File name of the ZIP filePath of directory to zipCompression mode.On progress callback.
- const Path : string - File name of the ZIP filePath of directory to zipCompression mode.On progress callback.
- Compression : TZipCompression = zcDeflate - File name of the ZIP filePath of directory to zipCompression mode.On progress callback.
- ZipProgress : TZipProgressEvent = nil - File name of the ZIP filePath of directory to zipCompression mode.On progress callback.
- public function GetUTF8PathFromExtraField
(
const
AHeader :
TZipHeader; out
AFileName :
string
)
: Boolean
;
class;
Checks if header extra field contains unicode path, if true AFilename contains the unicode path
- public procedure Open
(
const
ZipFileName :
string; OpenMode :
TZipMode
)
;
overload;
Opens a ZIP file for reading or writing.
Parameters
- const
ZipFileName :
string
-
Path to ZipFile File Mode to open file.
zmWrite
Creates a new ZIP file for writing.zmReadWrite
Opens the file for reading and allows adding additional new files.zmRead
Opens the file for reading. - OpenMode :
TZipMode
-
Path to ZipFile File Mode to open file.
zmWrite
Creates a new ZIP file for writing.zmReadWrite
Opens the file for reading and allows adding additional new files.zmRead
Opens the file for reading.
- const
ZipFileName :
string
-
Path to ZipFile File Mode to open file.
- public procedure Open ( ZipFileStream : TStream; OpenMode : TZipMode ) ; overload;
- public procedure Close ( ) ;
- public procedure Extract
(
const
FileName :
string; const
Path :
string
=
; CreateSubdirs :
Boolean
=
True
)
;
overload;
Extract a single file
Parameters
- const FileName : string - File name in the archivePath to extract to diskThe output should create sub directories specified in the ZIP file
- const Path : string = - File name in the archivePath to extract to diskThe output should create sub directories specified in the ZIP file
- CreateSubdirs : Boolean = True - File name in the archivePath to extract to diskThe output should create sub directories specified in the ZIP file
- public procedure Extract ( Index : Integer; const Path : string = ; CreateSubdirs : Boolean = True ) ; overload;
- public procedure Extract ( const FileName : string; const AStream : TStream ) ; overload;
- public procedure Extract ( Index : Integer; const AStream : TStream ) ; overload;
- public procedure ExtractAll ( const Path : string = ) ;
- public procedure Read
(
const
FileName :
string; out
Bytes :
TBytes
)
;
overload;
Read a file from arcive to an array of Bytes
Parameters
- const FileName : string - ZIP file FileNameOutput bytes
- out Bytes : TBytes - ZIP file FileNameOutput bytes
- public procedure Read ( Index : Integer; out Bytes : TBytes ) ; overload;
- public procedure Read
(
const
FileName :
string; out
Stream :
TStream; out
LocalHeader :
TZipHeader
)
;
overload;
Get a stream to read a file from disk
Parameters
- const FileName : string - ZIP file FileNameOutput StreamLocal File header
- out Stream : TStream - ZIP file FileNameOutput StreamLocal File header
- out LocalHeader : TZipHeader - ZIP file FileNameOutput StreamLocal File header
- public procedure Read ( Index : Integer; out Stream : TStream; out LocalHeader : TZipHeader ) ; overload;
- public procedure Add
(
const
FileName :
string; const
ArchiveFileName :
string
=
; Compression :
TZipCompression
=
zcDeflate
)
;
overload;
Add a file to the ZIP file
Parameters
- const FileName : string - FileName to be addedPath + Name of file in the arcive. If Ommitted, ExtractFileName(FileName) will be used.Compression mode.
- const ArchiveFileName : string = - FileName to be addedPath + Name of file in the arcive. If Ommitted, ExtractFileName(FileName) will be used.Compression mode.
- Compression : TZipCompression = zcDeflate - FileName to be addedPath + Name of file in the arcive. If Ommitted, ExtractFileName(FileName) will be used.Compression mode.
- public procedure Add
(
Data :
TBytes; const
ArchiveFileName :
string; Compression :
TZipCompression
=
zcDeflate
)
;
overload;
Add a memory file to the ZIP file
Parameters
- Data : TBytes - Bytes to be addedPath + Name of file in the arcive.Compression mode.
- const ArchiveFileName : string - Bytes to be addedPath + Name of file in the arcive.Compression mode.
- Compression : TZipCompression = zcDeflate - Bytes to be addedPath + Name of file in the arcive.Compression mode.
- public procedure Add
(
Data :
TStream; const
ArchiveFileName :
string; Compression :
TZipCompression
=
zcDeflate
; AExternalAttributes :
TFileAttributes
=
[]
)
;
overload;
Add a memory file to the ZIP file
Parameters
- Data : TStream - Stream of file to be addedPath + Name of file in the arcive.Compression mode.External attributes for this file.
- const ArchiveFileName : string - Stream of file to be addedPath + Name of file in the arcive.Compression mode.External attributes for this file.
- Compression : TZipCompression = zcDeflate - Stream of file to be addedPath + Name of file in the arcive.Compression mode.External attributes for this file.
- AExternalAttributes : TFileAttributes = [] - Stream of file to be addedPath + Name of file in the arcive.Compression mode.External attributes for this file.
- public procedure Add
(
Data :
TStream; LocalHeader :
TZipHeader; CentralHeader :
PZipHeader
=
nil
)
;
overload;
Add a memory file to the ZIP file. Allows programmer to specify the Local and Central Header data for more flexibility on what gets written. Minimal vailidation is done on the Header parameters; speficying bad options could result in a corrupted zip file.
Parameters
- Data : TStream - Stream of file to be addedThe local header dataA Pointer to an optional central header. If no central Header is provided, the Local Header information is used.
- LocalHeader : TZipHeader - Stream of file to be addedThe local header dataA Pointer to an optional central header. If no central Header is provided, the Local Header information is used.
- CentralHeader : PZipHeader = nil - Stream of file to be addedThe local header dataA Pointer to an optional central header. If no central Header is provided, the Local Header information is used.
- public function IndexOf
(
const
FileName :
string
)
: Integer
;
Translate from FileName to index in ZIP Central Header
Parameters
- const FileName : string - Path + Name of file in the arcive.
Properties
- public CreateDecompressStreamCallBack : TCreateCustomStreamCallBack
Callback called before a file inside a zip file is decompressed, allows access to the raw stream for decrypt purposes
read FCreateDecompressStreamCallBack
write FCreateDecompressStreamCallBack - public Mode : TZipModeread FMode
- public FileCount : Integerread GetFileCount
- public FileNames : TArray<System.string>read GetFileNames
- public FileInfos : TArray<Gorilla.Utils.Zip.TZipHeader>read GetFileInfos
- public FileName[Index] : stringread GetFileName
- public FileInfo[Index] : TZipHeaderread GetFileInfo
- public FileComment[Index] : string
- public Comment : string
- public UTF8Support : Boolean