System.Zip2
Unit System.Zip2.pasClasses
- EZipException = class ( Exception )
- TZipFile = class ( TObject )
Records
- record TZipEndOfCentralHeader
- record TZipHeader
- record TZipExtraField
- record TZipExtraField_ZIP64
- record TZipExtraField_NTFS
- record TZipExtraFields
- record TZip64_EndOfCentralDirectory
- record TZip64_EndOfCentralDirectoryLocator
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 SIGNATURE_ZIP64_ENDOFCENTRALDIRECTORY : Cardinal = ;
- const SIGNATURE_ZIP64_ENDOFCENTRALDIRECTORYLOCATOR : Cardinal = ;
- const LOCALHEADERSIZE : Integer = $1A;
- const CENTRALHEADERSIZE : Integer = $2A;
- const MADEBY_MSDOS : Integer = $0;
- const MADEBY_UNIX : Integer = $3;
- const ZIP_Version20 : Integer = $14;
- const EXTRAFIELD_ID_ZIP64 : Word = ;
- const EXTRAFIELD_ID_NTFS : Word = ;
- const ZIP64 : Integer = $FFFFFFFF;
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
Methods
- public function IsZIP64 ( ) : Boolean ;
- public function GetZIP64_CompressedSize ( ) : UInt64 ;
- public procedure SetZIP64_CompressedSize ( const Value : UInt64 ) ;
- public function GetZIP64_UncompressedSize ( ) : UInt64 ;
- public procedure SetZIP64_UncompressedSize ( const Value : UInt64 ) ;
- public procedure SetExtraField_NTFS ( const aFileName : string ) ;
Properties
TZipExtraField
Fields
Methods
TZipExtraField_ZIP64
Fields
Methods
- public function operator Implicit ( const aBytes : TBytes ) : TZipExtraField_ZIP64 ; class noself operator overload;
- public function operator Implicit ( const A : TZipExtraField_ZIP64 ) : TZipExtraField ; class noself operator overload;
- public function operator Implicit ( const A : TZipExtraField_ZIP64 ) : TBytes ; class noself operator overload;
- public function operator Implicit ( const A : TZipExtraField ) : TZipExtraField_ZIP64 ; class noself operator overload;
TZipExtraField_NTFS
Fields
- public Reserved :
Cardinal
- public Tag1 :
Word
- public Size1 :
Word
- public MTime :
UInt64
- public ATime :
UInt64
- public CTime :
UInt64
Methods
- public constructor Create ( const aFileName : string ) ;
- public function operator Implicit ( const aBytes : TBytes ) : TZipExtraField_NTFS ; class noself operator overload;
- public function operator Implicit ( const A : TZipExtraField_NTFS ) : TBytes ; class noself operator overload;
- public function operator Implicit ( const A : TZipExtraField_NTFS ) : TZipExtraField ; class noself operator overload;
- public function operator Implicit ( const A : TZipExtraField ) : TZipExtraField_NTFS ; class noself operator overload;
TZipExtraFields
Fields
Methods
- public function Get ( const aHeaderID : Word; out aItem : TZipExtraField; out Index : NativeInt ) : Boolean ;
- public function New ( ) : NativeInt ; overload;
- public procedure Add ( const A : TZipExtraField ) ;
- public function operator Implicit ( const aBytes : TBytes ) : TZipExtraFields ; class noself operator overload;
- public function operator Implicit ( const A : TZipExtraFields ) : TBytes ; class noself operator overload;
- public function operator Implicit ( const A : TZipExtraFields ) : TZipExtraField_ZIP64 ; class noself operator overload;
TZip64_EndOfCentralDirectory
Fields
- public Signature :
Cardinal
- public RecordSize :
UInt64
- public VersionMadeBy :
Word
- public VersionNeededToExtract :
Word
- public DiskNumber :
Cardinal
- public StartDiskNumber :
Cardinal
- public EntriesOnDisk :
UInt64
- public TotalEntries :
UInt64
- public DirectorySize :
UInt64
- public DirectoryOffset :
UInt64
Methods
TZipFile
Class for creating and reading .ZIP files.
Ancestors
Members
Fields
- private FCompressionHandler :
TZipFile.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<System.Zip2.TZipHeader>
- private FComment :
TBytes
- private FUTF8Support :
Boolean
- private FOnProgress :
TZipProgressEvent
- private FCurrentFile :
string
- private FCurrentHeader :
TZipHeader
Methods
- public constructor Create
(
)
;
Create a TZipFile
- 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<System.Zip2.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 ) ;
- private function ZIP64_LocateEndOfCentralHeader ( var Header : TZip64_EndOfCentralDirectory ) : Boolean ;
- 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 procedure UnregisterCompressionHandler ( Compression : TZipCompression ) ; 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 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<System.Zip2.TZipHeader>read GetFileInfos
- public FileName[Index] : stringread GetFileName
- public FileInfo[Index] : TZipHeaderread GetFileInfo
- public FileComment[Index] : string
- public Comment : string
- public UTF8Support : Boolean