ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream.Read C# (CSharp) Method

Read() public method

Reads decompressed data into the provided buffer byte array
/// Inflater needs a dictionary ///
public Read ( byte buffer, int offset, int count ) : int
buffer byte /// The array to read and decompress data into ///
offset int /// The offset indicating where the data should be placed ///
count int /// The number of bytes to decompress ///
return int
        public override int Read(byte[] buffer, int offset, int count)
        {
            if (inf.IsNeedingDictionary) {
                throw new SharpZipBaseException("Need a dictionary");
            }

            int remainingBytes = count;
            while (true) {
                int bytesRead = inf.Inflate(buffer, offset, remainingBytes);
                offset += bytesRead;
                remainingBytes -= bytesRead;

                if (remainingBytes == 0 || inf.IsFinished) {
                    break;
                }

                if (inf.IsNeedingInput) {
                    Fill();
                } else if (bytesRead == 0) {
                    throw new ZipException("Dont know what to do");
                }
            }
            return count - remainingBytes;
        }

Usage Example

Exemplo n.º 1
0
        /// <summary>
        /// Decompresses an array of bytes.
        /// </summary>
        /// <param name="_pBytes">An array of bytes to be decompressed.</param>
        /// <returns>Decompressed bytes</returns>
        public static byte[] DeCompress(byte[] _pBytes)
        {
            InflaterInputStream inputStream = new InflaterInputStream(new MemoryStream(_pBytes));

            MemoryStream ms = new MemoryStream();
            Int32 mSize;

            byte[] mWriteData = new byte[4096];

            while (true)
            {
                mSize = inputStream.Read(mWriteData, 0, mWriteData.Length);
                if (mSize > 0)
                {
                    ms.Write(mWriteData, 0, mSize);
                }
                else
                {
                    break;
                }
            }

            inputStream.Close();
            return ms.ToArray();
        }
All Usage Examples Of ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream::Read