Decompress Stream - CSharp System.IO.Compression

CSharp examples for System.IO.Compression:Zip

Description

Decompress Stream

Demo Code


using System.Diagnostics;
using System.IO.Compression;
using System.IO;/*from   w w w .  j av  a 2 s .c om*/
using System.Text;
using System.Collections.Generic;
using System;

public class Main{
   public static Stream DecompressStream(Stream instream) {
         MemoryStream outstream = new MemoryStream();
         DeflateStream comp = new DeflateStream(instream, CompressionMode.Decompress, true);

         int numBytes;
         byte[] buffer = new byte[4096];
         while ((numBytes = comp.Read(buffer, 0, 4096)) != 0) {
            outstream.Write(buffer, 0, numBytes);
         }

         outstream.Position = 0;
         return outstream;
      }
}

Related Tutorials