2016-06-29 5 views
-1

압축 된 base64 인코딩 된 문자열의 압축을 풀려고하고 있지만 그렇게하는 방법을 모릅니다. 그것은 gzip이 아니며 파일에 쓰지 않고 압축을 풀려고합니다.C#에서 메모리 스트림의 데이터 압축을 해제하는 방법

+0

관련 : http://stackoverflow.com/questions/17212964/net-zlib-inflate-with-net-4-5 –

+1

1 단계 : 이해 –

+0

데이터 압축 방법에 관한 아래의 base64 인코딩을 입력하세요 여기의 데이터 또는 적어도 처음 100 자. –

답변

0

시도한 제안이 Unzip a memorystream (Contains the zip file) and get the files에서 시도되었으며 마지막으로 방법으로 사용하기 위해 만들어진 일부 변경 사항과 함께 작동하는 것으로 나타났습니다.

public static string DecompressData(string val) 
    { 
     byte[] bytes = Convert.FromBase64String(val).ToArray(); 
     Stream data = new MemoryStream(bytes); 
     Stream unzippedEntryStream; 
     MemoryStream ms = new MemoryStream(); 
     ZipArchive archive = new ZipArchive(data); 
     foreach (ZipArchiveEntry entry in archive.Entries) 
     { 
      unzippedEntryStream = entry.Open(); 
      unzippedEntryStream.CopyTo(ms); 
     } 

     string result = Encoding.UTF8.GetString(ms.ToArray()); 
     return result; 
    }