반응형
250x250
Notice
Recent Posts
Recent Comments
Link
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
Archives
Today
Total
관리 메뉴

폴크(FOLC)

C# 테크닉 - UnZip 파일 복원 ( SharpZipLib ) 본문

C#, WF, WPF(.NET)/C#, WF, WPF(.NET) 테크닉

C# 테크닉 - UnZip 파일 복원 ( SharpZipLib )

folcjin 2021. 12. 6. 21:07
728x90
반응형

# Local 폴더를 Zip 파일을 복원
   > SharpZipLib 라이브러리 이용

# Nuget 에서 SharpZipLib 설치

 

# 소스 코드
using System.IO;
using ICSharpCode.SharpZipLib.Zip;

public void UnZipFileWithDecompress(string src_path, string dst_path)
{
    DirectoryInfo dst_dir_info = new DirectoryInfo(dst_path);
    if (dst_dir_info.Exists == false)
    {
        dst_dir_info.Create();
    }

    FileStream src_file_stream = new FileStream(src_path, FileMode.Open);
    ZipInputStream zip_strm = new ZipInputStream(src_file_stream);

    byte[] databufferArray = new byte[1024];

    while (true)
    {
        ZipEntry zipEntry = zip_strm.GetNextEntry();
        if (zipEntry == null)
        {
            break;
        }

        if (0 < zipEntry.Name.LastIndexOf('\\'))
        {
            string sub_dir = zipEntry.Name.Substring(0, zipEntry.Name.LastIndexOf('\\'));

            if (Directory.Exists(Path.Combine(dst_dir_info.FullName, sub_dir)) == false)
            {
                dst_dir_info.CreateSubdirectory(sub_dir);
            }
        }

        FileInfo dst_file_info = new FileInfo(Path.Combine(dst_dir_info.FullName, zipEntry.Name));
        using (FileStream dst_file_stream = dst_file_info.Create())
        {
            while (true)
            {
                int datacount = zip_strm.Read(databufferArray, 0, databufferArray.Length);
                if (datacount == 0)
                {
                    break;
                }

                dst_file_stream.Write(databufferArray, 0, datacount);
            }
        }
    }

    zip_strm.Close();
}

728x90
반응형
사업자 정보 표시
사업자 등록번호 : -- | TEL : --