Delphi 解压缩 ZipForge

ZipForge

http://www.componentace.com/zip_component_zip_delphi_zipforge.htm

downLoad

http://www.componentace.com/download/download.php?editionid=12

Example

http://www.componentace.com/zip-delphi.htm

c++builder、Delphi 压缩文件

ZipForge is a fast and powerful VCL Zip component, written in Delphi.
It lets you easily create ZIP archives, extract files from zip files to hard drive or memory, add files to a zip archive from disk or memory, replace, move and delete files in zip archives. Also it creates and reads self-extracting (SFX) zip archives, AES encrypted and multi-volume zip files.

ZipForge main features:

    • Opens and creates archives encrypted with strong AES encryption algorithm
    • Zip64 supports - lets you create ZIP files over 4 GB
    • Unicode file names support
    • Includes transaction system which allows you to rollback changes if archive update failed
    • Adds compressed data directly from streams and extracts archived files to streams without creating temp files
    • Lets you store full path with drive for each file
    • Allows to search for files inside archive by mask
    • Progress indication
    • Full Delphi source code is available 
zf: TZipForge;
zf := TZipForge.Create(nil);
zf.OpenArchive(aInStream, False);
zf.ExtractToStream(FileName, StreamOut);

setup Path

D:Program Files (x86)ComponentAceipForge

压缩文件

void __fastcall TForm4::Button1Click( TObject * Sender )
{
    TMemoryStream * ms = new TMemoryStream( );
    Memo1->Text="Hello Word!";
    Memo1->Lines->SaveToStream( ms );
    ZipForge1->FileName = "a.zip";//压缩包的名称
    ZipForge1->OpenArchive( );
   ZipForge1->AddFromStream( "a.txt", ms, true );//压缩包里的文件
    //ZipForge1->AddFromString("b.txt","text2",)
    ZipForge1->CloseArchive( );
    delete ms;

}

解压缩

void __fastcall TForm4::Button2Click( TObject * Sender )
{
    TMemoryStream * ms = new TMemoryStream( );
    ZipForge1->FileName = "a.zip";//压缩包名称
    ZipForge1->OpenArchive( );
    ZipForge1->ExtractToStream( "a.txt", ms );//压缩包里的文件
    ms->Position = 0;
    Memo1->Lines->LoadFromStream( ms );

    // To String
//    String StrOut;
//    ZipForge1->ExtractToString( "a.txt", StrOut );
    ZipForge1->CloseArchive( );
    delete ms;
}

解压缩到字符串

void __fastcall TForm4::Button2Click( TObject * Sender )
{

    ZipForge1->FileName = "a.zip";
    ZipForge1->OpenArchive( );
    // To String
    String StrOut;
    ZipForge1->ExtractToString( "a.txt", StrOut );
    Memo1->Text = StrOut;
    ZipForge1->CloseArchive( );
}

查找压缩包文件列表,找到文件名称,然后

ZipForge1->ExtractToStream(文件名,stream);

Use FindFirst and FindNext methods of TZipForgefor searching files within the archive file. 

获得压缩包中的文件列表

    TZFArchiveItem afItem;
    bool aFound = ZipForge1->FindFirst( "*.*", afItem, faAnyFile, "" );
    while ( aFound )
    {
        this->mmoFileList->Lines->Add( afItem.FileName );
        aFound = ZipForge1->FindNext( afItem );
    }

压缩包文件详情

        this->mmoFileList->Lines->Add( afItem.FileName );
        this->mmoFileList->Lines->Add( ">>>>" );
        this->mmoFileList->Lines->Add( afItem.StoredPath );
        this->mmoFileList->Lines->Add( afItem.CompressedSize );//压缩后文件大小
        this->mmoFileList->Lines->Add( afItem.UncompressedSize );//压缩前文件大小
        this->mmoFileList->Lines->Add( afItem.CompressionRate );
        this->mmoFileList->Lines->Add((int) afItem.Encrypted );
        this->mmoFileList->Lines->Add( afItem.LastModFileDate );
        this->mmoFileList->Lines->Add( afItem.LastModFileTime );
        this->mmoFileList->Lines->Add( afItem.CRC );
        this->mmoFileList->Lines->Add( afItem.ExternalFileAttributes );
        this->mmoFileList->Lines->Add( afItem.Comment );

 从流中解压

    TMemoryStream * ms;
    ms = new TMemoryStream( );
    ms->LoadFromFile( "a.zip" );
    ZipForge1->OpenArchive( ms, false );

.Net c#

ICSharpCode.SharpZipLib.dll

ZipOutputStream

http://icsharpcode.github.io/SharpZipLib/

原文地址:https://www.cnblogs.com/cb168/p/4949565.html