Ionic.Zlib.GZipStream.Read C# (CSharp) Method

Read() public method

Read and decompress data from the source stream.
With a GZipStream, decompression is done through reading.
public Read ( byte buffer, int offset, int count ) : int
buffer byte The buffer into which the decompressed data should be placed.
offset int the offset within that data array to put the first byte read.
count int the number of bytes to read.
return int
        public override int Read(byte[] buffer, int offset, int count)
        {
            if (_disposed) throw new ObjectDisposedException("GZipStream");
            int n = _baseStream.Read(buffer, offset, count);

            // Console.WriteLine("GZipStream::Read(buffer, off({0}), c({1}) = {2}", offset, count, n);
            // Console.WriteLine( Util.FormatByteArray(buffer, offset, n) );

            if (!_firstReadDone)
            {
                _firstReadDone = true;
                FileName = _baseStream._GzipFileName;
                Comment = _baseStream._GzipComment;
            }
            return n;
        }

Usage Example

Beispiel #1
0
 public static byte[] Decompress(byte[] data)
 {
     try
     {
         MemoryStream ms       = new MemoryStream(data);
         GZipStream   zip      = new GZipStream(ms, CompressionMode.Decompress, true);
         MemoryStream msreader = new MemoryStream();
         byte[]       buffer   = new byte[0x1000];
         while (true)
         {
             int reader = zip.Read(buffer, 0, buffer.Length);
             if (reader <= 0)
             {
                 break;
             }
             msreader.Write(buffer, 0, reader);
         }
         zip.Close();
         ms.Close();
         msreader.Position = 0;
         buffer            = msreader.ToArray();
         msreader.Close();
         return(buffer);
     }
     catch (IOException e)
     {
         throw new IOException(e.Message);
     }
 }
All Usage Examples Of Ionic.Zlib.GZipStream::Read