C# 테크닉 - UnZip 파일 복원 ( SharpZipLib )
# 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();
}