Microsoft MVP성태의 닷넷 이야기
.NET Framework: 135. C# - Deflate, GZip, Zip [링크 복사], [링크+제목 복사],
조회: 33291
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 1개 있습니다.)
(시리즈 글이 2개 있습니다.)
.NET Framework: 135. C# - Deflate, GZip, Zip
; https://www.sysnet.pe.kr/2/0/723

.NET Framework: 136. 자바와 닷넷의 압축 호환
; https://www.sysnet.pe.kr/2/0/724





C# - Deflate, GZip, Zip


보통 압축 알고리즘을 다루다 보면 쉽게 볼 수 있는 단어들이 있는데요. 각각의 차이점에 대해서 다음의 글에 간략하게 설명되어 있습니다.

Re: Difference between gzip, zip, deflate
; http://newsgroups.derkeiler.com/Archive/Comp/comp.compression/2007-07/msg00011.html

정리해 보면 대략 다음과 같은 정도로만 알아둬도 될 것 같습니다.

  • Deflate = 원시 압축 데이터
  • GZip = Header + Deflate 데이터 + Footer
  • Zip = 다양한 압축 포맷, 다중 파일 지원

그렇다면, 닷넷으로는 이를 어떻게 구현할까요?

우선, Deflate는 DeflateStream으로 .NET 2.0에서부터 지원되고 있습니다. 그런 의미에서 DeflateStream은 Header/Footer에 대한 부가적인 데이터를 포함하지 않고 LZ77/허프만 코딩이 적용되어 산출된 원시 압축 데이터만을 다루기 때문에 즉석으로 사용할 수 있는 용도로 적합합니다. 아쉬운 점이 있다면 다양한 압축률 지정이 안 된다는 것입니다. 게다가 내부적으로 Huffman_only 방식으로만 사용할지에 대한 옵션 및 그에 대한 구현 방법도 명시적으로 공개되어 있지 않습니다.

구체적인 사용 예제는 MSDN 도움말에 잘 공개되어 있습니다. (도움말에도 나오지만, 4GB 이상의 파일에는 적용할 수 없습니다.)

.NET Framework Class Library - DeflateStream Class
; https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.deflatestream

특이한 것은, 보통 일반적인 Deflate 라이브러리 같은 데에서 보면 압축은 Deflate, 압축 해제는 Inflate라는 접두어를 써서 표현하고는 하는데 .NET의 경우에는 2가지 모두 단일하게 DeflateStream의 생성자에서 CompressionMode를 지정하는 것으로 해결하고 있습니다.

다음으로 GZip은, 여러분들이 많이 써온 GZipStream과 비교됩니다. 위에 설명한 대로 Deflate 압축 데이터와 함께 앞/뒤에 부가적인 메타 정보를 포함합니다. 재미있는 것은 GZipStream이 말 그대로 "Stream" 차원에서 사용될 수 있도록 구현되었기 때문에 "하나의 파일"을 압축해서 보관하는 일반적인 ZIP 실행 파일에서 다뤄지는 헤더를 모두 포함하지는 않습니다. 이에 관해서는 다음의 토픽에서 자세히 설명하고 있는데요.

. NET Matters - NamedGZipStream, Covariance and Contravariance
; https://learn.microsoft.com/en-us/archive/msdn-magazine/2005/october/net-matters-namedgzipstream-covariance-and-contravariance

The GZipStream class implements the GZIP file format as defined in RFC 1952. The GZIP file format makes use of the DEFLATE compression algorithm, detailed in RFC 1951, and simply defines a header and footer that are used to encapsulate the compressed data, providing some metadata for it.

The problem you're running into is that the GZIP header format declares the name of the compressed file as optional.



따라서, 만약 파일 이름까지 포함하는 헤더를 지원하는 압축 데이터를 원한다면 위의 토픽에서 제공되는 NamedGZipStream을 사용하거나, 아니면 그에 준하는 기능을 지원하는 여타 공개된 라이브러리를 사용하셔야 합니다.

마지막으로, Zip에 대응되는 닷넷 기본 클래스는 존재하지 않습니다. 물론 고맙게도 다른 분들이 만들어 놓은 공개 라이브러리들이 있습니다.

DotNetZip - Zip file manipulation in .NET languages
; http://www.codeplex.com/DotNetZip

SharpZipLib
; http://www.icsharpcode.net/OpenSource/SharpZipLib/

그럼... 좀 정리가 된 것 같죠! ^^



[이 토픽에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 11/25/2024]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 76  77  78  79  80  81  82  83  [84]  85  86  87  88  89  90  ...
NoWriterDateCnt.TitleFile(s)
11836정성태3/5/201923304오류 유형: 525. Visual Studio 2019 Preview 4/RC - C# 8.0 Missing compiler required member 'System.Range..ctor' [1]
11835정성태3/5/201921791.NET Framework: 810. C# 8.0의 Index/Range 연산자를 .NET Framework에서 사용하는 방법 및 비동기 스트림의 컴파일 방법 [3]파일 다운로드1
11834정성태3/4/201920618개발 환경 구성: 432. Visual Studio 없이 최신 C# (8.0) 컴파일러를 사용하는 방법
11833정성태3/4/201921140개발 환경 구성: 431. Visual Studio 2019 - CMake를 이용한 공유/실행(so/out) 리눅스 프로젝트 설정파일 다운로드1
11832정성태3/4/201917059오류 유형: 524. Visual Studio CMake - rsync: connection unexpectedly closed
11831정성태3/4/201916893오류 유형: 523. Visual Studio 2019 - 새 창으로 뜬 윈도우를 닫을 때 비정상 종료
11830정성태2/26/201916595오류 유형: 522. 이벤트 로그 - Error opening event log file State. Log will not be processed. Return code from OpenEventLog is 87.
11829정성태2/26/201918303개발 환경 구성: 430. 마이크로소프트의 CoreCLR 프로파일러 예제 빌드 방법 - 리눅스 환경 [1]
11828정성태2/26/201926182개발 환경 구성: 429. Component Services 관리자의 RuntimeBroker 설정이 2개 있는 경우 [8]
11827정성태2/26/201919116오류 유형: 521. Visual Studio - Could not start the 'rsync' command on the remote host, please install it using your system package manager.
11826정성태2/26/201919292오류 유형: 520. 우분투에 .NET Core SDK 설치 시 패키지 의존성 오류
11825정성태2/25/201924532개발 환경 구성: 428. Visual Studio 2019 - CMake를 이용한 리눅스 빌드 환경 설정 [1]
11824정성태2/25/201919013오류 유형: 519. The SNMP Service encountered an error while accessing the registry key SYSTEM\CurrentControlSet\Services\SNMP\Parameters\TrapConfiguration. [1]
11823정성태2/21/201920638오류 유형: 518. IIS 관리 콘솔이 뜨지 않는 문제
11822정성태2/20/201918952오류 유형: 517. docker에 설치한 MongoDB 서버로 연결이 안 되는 경우
11821정성태2/20/201919716오류 유형: 516. Visual Studio 2019 - This extension uses deprecated APIs and is at risk of not functioning in a future VS update. [1]
11820정성태2/20/201922790오류 유형: 515. 윈도우 10 1809 업데이트 후 "User Profiles Service" 1534 경고 발생
11819정성태2/20/201922057Windows: 158. 컴퓨터와 사용자의 SID(security identifier) 확인 방법
11818정성태2/20/201920132VS.NET IDE: 131. Visual Studio 2019 Preview의 닷넷 프로젝트 빌드가 20초 이상 걸리는 경우 [2]
11817정성태2/17/201916507오류 유형: 514. WinDbg Preview 실행 오류 - Error : DbgX.dll : WindowsDebugger.WindowsDebuggerException: Could not load dbgeng.dll
11816정성태2/17/201919951Windows: 157. 윈도우 스토어 앱(Microsoft Store App)을 명령행에서 직접 실행하는 방법
11815정성태2/14/201918163오류 유형: 513. Visual Studio 2019 - VSIX 설치 시 "The extension cannot be installed to this product due to prerequisites that cannot be resolved." 오류 발생
11814정성태2/12/201917048오류 유형: 512. VM(가상 머신)의 NT 서비스들이 자동 시작되지 않는 문제
11813정성태2/12/201918338.NET Framework: 809. C# - ("Save File Dialog" 등의) 대화 창에 확장 속성을 보이는 방법
11812정성태2/11/201915655오류 유형: 511. Windows Server 2003 VM 부팅 후 로그인 시점에 0xC0000005 BSOD 발생
11811정성태2/11/201920889오류 유형: 510. 서버 운영체제에 NVIDIA GeForce Experience 실행 시 wlanapi.dll 누락 문제
... 76  77  78  79  80  81  82  83  [84]  85  86  87  88  89  90  ...