1 つまたは複数のファイルを保存するアーカイブを作成します

.NET アーカイブ ツールでファイル管理を簡素化

概要

複数のファイルを ZIP 圧縮する方法

デフォルトは Deflate アルゴリズムです

Zip compression with Deflate algoritm

    using (Archive archive = new Archive())
    {
        archive.CreateEntry("first.bin",  "data1.bin");
        archive.CreateEntry("second.bin",  "data2.bin");
        // Add as many entries as you need 
        archive.Save("archive.zip");	
    }

複数のファイルの 7-ZIP アーカイブを作成する方法

7-zip のデフォルトは LZMA アルゴリズムです

7-Zip with LZMA algorithm

    using (SevenZipArchive archive = new SevenZipArchive())
    {
        archive.CreateEntry("first.bin",  "data1.bin");
        archive.CreateEntry("second.bin",  "data2.bin");	
        // Add as many entries as you need 	
        archive.Save("archive.7z");	
    }

複数のファイルを含む XAR アーカイブ

デフォルトは ZLib アルゴリズムです

XAR with ZLib algorithm

    using (XarArchive archive = new XarArchive())
    {
        archive.CreateEntry("first.bin",  "data1.bin");
        archive.CreateEntry("second.bin",  "data2.bin");
        // Add as many entries as you need 	
        archive.Save("archive.xar");	
    }

複数のファイルを圧縮せずに保存する

TAR および CPIO フォーマットのアプローチは似ており、既知の CreateEntry メソッドにあります。

圧縮なしの TAR アーカイブ

TAR storing files without compression

    using (TarArchive archive = new TarArchive())
    {
        archive.CreateEntry("first.bin",  "data1.bin");
        archive.CreateEntry("second.bin",  "data2.bin");
        // Add as many entries as you need 
        archive.Save("archive.tar");
    }

圧縮なしの CPIO アーカイブ

CPIO storing files without compression

    using (TarArchive archive = new TarArchive())
    {
        archive.CreateEntry("first.bin",  "data1.bin");
        archive.CreateEntry("second.bin",  "data2.bin");
        // Add as many entries as you need 
        archive.Save("archive.cpio");
    }

エントリのない圧縮のみの形式

GZIP、LZ、BZIP2、XZ、Z などのアーカイブはエントリをサポートしておらず、単一のソースのみを圧縮できます。このような圧縮を使用したサンプルを参照してください。

GZ アーカイブ エントリのない圧縮のみの形式

GZIP with compress only single source

using (FileStream source = File.Open("alice29.txt", FileMode.Open, FileAccess.Read))
{
    using (GzipArchive archive = new GzipArchive())
    {
        archive.SetSource(source);
        archive.Save("archive.gz");
    }
}

LZ アーカイブ エントリのない圧縮専用フォーマット

LZIP with compress only single source

using (FileStream source = File.Open("alice29.txt", FileMode.Open, FileAccess.Read))
{
    using (GzipArchive archive = new GzipArchive())
    {
        archive.SetSource(source);
        archive.Save("archive.gz");
    }
}

Aspose.ZIP を使用すると、アーカイブ専用形式と圧縮専用形式を 1 つの方法で組み合わせることができます。 TAR.GZ を組み合わせたこの機能の例を次に示します。これを実現するには、SaveGzipped メソッドを使用します。

TAR.GZの組み合わせ

LZIP、XZ、ZStandard、Z 圧縮形式にも同様の方法があります。

TAR.GZ with SaveGzipped method

    using (TarArchive archive = new TarArchive())
    {
        archive.CreateEntry("first.bin",  "data1.bin");
        archive.CreateEntry("second.bin",  "data2.bin");
        archive.SaveGzipped("archive.tar.gz");
    }

TAR.BZ2

ただし、BZIP2 形式には別のアプローチを使用する必要があります。

BZIP2 with SaveGzipped method

    using (TarArchive tar = new TarArchive())
    {
        tar.CreateEntry("first.bin",  "data1.bin");
        tar.CreateEntry("second.bin",  "data2.bin");	
        using (Bzip2Archive archive = new Bzip2Archive())
        {
            archive.SetSource(tar);
            archive.Save("archive.tar.bz2");
        } 
    }

サポートされているその他の Aspose.ZIP for .NET API 機能

Aspose.ZIP C# ライブラリを使用して、zip ファイル ドキュメントの変換、結合、編集、アーカイブからのデータの抽出などを行います。

  

Support and Learning Resources

  
  

Aspose.Zip offers individual archive processing APIs for other popular development environments, listed below: