title: zlib from C++ to C#(How to convert byte[] to stream and stream to byte[])
body: <p>My task is to decompress a packet(received) using zlib and then use an algoritm to make a picture from the data</p>
  
  <p>The good news is that I have the code in C++,but the task is to do it in C#</p>
  
  <p>C++</p>
  
  <pre><code>        //Read the first values of the packet received
  
          DWORD image[200 * 64] = {0}; //used for algoritm(width always = 200 and height always == 64)
          int imgIndex = 0; //used for algoritm
          unsigned char rawbytes_[131072] = {0}; //read below
          unsigned char * rawbytes = rawbytes_; //destrination parameter for decompression(ptr)
          compressed = r.Read&lt;WORD&gt;(); //the length of the compressed bytes(picture)
          uncompressed = r.Read&lt;WORD&gt;(); //the length that should be after decompression
          width = r.Read&lt;WORD&gt;(); //the width of the picture
          height = r.Read&lt;WORD&gt;(); //the height of the picture
  
          LPBYTE ptr = r.GetCurrentStream(); //the bytes(file that must be decompressed)
  
          outLen = uncompressed; //copy the len into another variable
  
          //Decompress
  
          if(uncompress((Bytef*)rawbytes, &amp;outLen, ptr, compressed) != Z_OK)
          {
              printf("Could not uncompress the image code.\n");
              Disconnect();
              return;
          }
  
          //Algoritm to make up the picture
          // Loop through the data
          for(int c = 0; c &lt; (int)height; ++c)
          {
              for(int r = 0; r &lt; (int)width; ++r)
              {
                  imgIndex = (height - 1 - c) * width + r;
                  image[imgIndex] = 0xFF000000;
                  if(-((1 &lt;&lt; (0xFF &amp; (r &amp; 0x80000007))) &amp; rawbytes[((c * width + r) &gt;&gt; 3)])) 
                      image[imgIndex] = 0xFFFFFFFF;
              }
          }
  </code></pre>
  
  <p>I'm trying to do this with zlib.NET ,but all demos have that code to decompress(C#)</p>
  
  <pre><code>    private void decompressFile(string inFile, string outFile)
      {
          System.IO.FileStream outFileStream = new System.IO.FileStream(outFile, System.IO.FileMode.Create);
          zlib.ZOutputStream outZStream = new zlib.ZOutputStream(outFileStream);
          System.IO.FileStream inFileStream = new System.IO.FileStream(inFile, System.IO.FileMode.Open);          
          try
          {
              CopyStream(inFileStream, outZStream);
          }
          finally
          {
              outZStream.Close();
              outFileStream.Close();
              inFileStream.Close();
          }
      }
  
      public static void CopyStream(System.IO.Stream input, System.IO.Stream output)
      {
          byte[] buffer = new byte[2000];
          int len;
          while ((len = input.Read(buffer, 0, 2000)) &gt; 0)
          {
              output.Write(buffer, 0, len);
          }
          output.Flush();
      }
  </code></pre>
  
  <p>My problem:I don't want to save the file after decompression,because I have to use the algoritm shown in the C++ code.</p>
  
  <p>How to convert the byte[] array into a stream similiar to the one in the C# zlib code to decompress the data and then how to convert the stream back into byte array?</p>
  
  <p>Also,How to change the zlib.NET code to NOT save files?</p>