개요

보관 및 압축 도구는 세 가지 주요 클래스로 나눌 수 있습니다.
- 일반적으로 압축을 사용하는 여러 파일이 포함된 보관 파일 – ZIP, 7Z, XAR;
- 압축하지 않고 여러 파일 저장 – TAR, CPIO;
- 압축 -항목이 없는 전용 형식 – GZ, LZ, BZIP2, XZ, ZStandard, Z.
두 번째 클래스의 아카이브는 종종 압축 전용 형식과 결합됩니다. 하나는 보관용이고 다른 하나는 압축용이라는 고유한 작업을 통해 Unix 계열 시스템에서 널리 사용됩니다. 다음은 모든 아카이브 종류에 대한 설명과 샘플입니다.

여러 파일을 포함하는 압축 아카이브

압축할 모든 파일에 대해 CreateEntry 메소드를 사용합니다. 이 샘플에서는 압축 설정을 제공하지 않으므로 선택한 형식의 기본값이 됩니다.

여러 파일을 압축하는 방법

기본값은 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을 사용하면 아카이브 전용 형식과 압축 전용 형식을 단일 방법으로 결합할 수 있습니다. 다음은 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");
        } 
    }

.NET API 기능에 대해 지원되는 기타 Aspose.ZIP

Aspose.ZIP C# 라이브러리를 사용하여 zip 파일 문서를 변환, 병합, 편집하고 아카이브에서 데이터를 추출하는 등의 작업을 수행하세요!

  

Support and Learning Resources

  
  

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