Yunqa • The Delphi Inspiration

Delphi Components and Applications

User Tools

Site Tools


products:zipwriter:index

DIZipWriter

DIZipWriter is a Delphi component to create PKZip-compatible ZIP archives. Archive output is based on TStream and writes directlyfiles (TFileStream), memory (TMemoryStream), or database BLOBs (TBlobStream).

Overview

DIZipWriter's core functionality is in its main class, TDIZipWriter. It has methods to create new ZIP archives and add ZIP file entries from different data types:

  • Files • Streams • Strings • Memory Buffers

After a ZIP file entry is added, applications can write data to it. Writing can take place in one go or in multiple chunks. There can be any number of chunks of any size, starting from an empty chunk of size zero.

TDIZipWriter writes chunk data directly to the ZIP archive with no need for temporary memory buffers or disk storage. Other than the target ZIP archive, TDIZipWriter does not create any additional files. It can also create ZIP archives enirely in memory, useful for web servers to send ZIP files quickly.

Comments are supported for each ZIP file entry, plus a global comment for the ZIP archive itself. File names of the ZIP entries are automatically encoded to support Unicode. Long file names are supported, too, just as absolute and relative path names.

Compression Algorithms

TDIZipWriter has a pluggable compressor interface. These compressors are ready to use, custom ones can be added:

TYuStoreCompressor This is not a real compressor as it stores data without compression. Fastest, largest files.
TYuDeflateCompressor Deflate dates back to 1993 and forms the basis of ZIP compression up to today. It offers fast, reasonable compression and is supported by all ZIP software.
TYuBZip2Compressor Bzip2 was first published in 1995 and achieves better compression than deflate at the cost of compression time. It is well established and supported by most ZIP software.
TYuLzmaCompressor LZMA was introduced in 1998 and with improves compression over deflate and bzip2 in most cases. Extreme compression levels can be slow, but decompression is always fast, regardless of the compression level. Support by newer ZIP software.
TYuXzCompressor The XZ compression format is based on LZMA and adds secure data integrity check.
TYuZstdCompressor Zstandard is a recent compression algorithm from 2016. It combines high compression ratios with short compression times. Decompression is super fast. Supported by selected ZIP software like 7-Zip zstd.

Direct Streaming

Direct streaming is a unique feature to DIZipWriter. It allows objects to stream their data directly to a ZIP archive using their own SaveToStream() procedure. This is very efficient because its avoids all temporary storage of, say, image or BLOB data. This is fast to code and efficient to run.

{ Save a TBitMap image to a ZIP archive. }
 
{ Create and initialize an example bitmap image. }
Img := TBitMap.Create;
 
{ Add a new entry to the ZIP archive. }
DIZipWriter.AddEntry('MyImage');
 
{ Write the bitmap to the archive's entry stream. }
Img.SaveToStream(DIZipWriter.CurrentEntryStream);
 
{ The same works to save a database BLOB. }
MyBlob.SaveToStream(DIZipWriter.CurrentEntryStream);

Encryption: Standard PKZIP and strong AES

DIZipWriter can encryt data using strong AES encryption up to 256 bits. It follows the AE-1 and AE-2 Encryption Specification first introduced by WinZip 9. Many ZIP software allows to extract AES encrypted ZIP archives, for example the free 7-Zip zstd.

DIZipWriter also supported the standard PKZIP encryption is also supported, but considered weak and no longer recommended.

products/zipwriter/index.txt · Last modified: 2021/04/26 17:12 (external edit)