Beispiel #1
0
 /// <summary>
 /// Read data from the stream.
 /// </summary>
 ///
 /// <remarks>
 ///
 /// <para>
 ///   If you wish to use the <c>ZlibStream</c> to compress data while reading,
 ///   you can create a <c>ZlibStream</c> with <c>CompressionMode.Compress</c>,
 ///   providing an uncompressed data stream.  Then call <c>Read()</c> on that
 ///   <c>ZlibStream</c>, and the data read will be compressed.  If you wish to
 ///   use the <c>ZlibStream</c> to decompress data while reading, you can create
 ///   a <c>ZlibStream</c> with <c>CompressionMode.Decompress</c>, providing a
 ///   readable compressed data stream.  Then call <c>Read()</c> on that
 ///   <c>ZlibStream</c>, and the data will be decompressed as it is read.
 /// </para>
 ///
 /// <para>
 ///   A <c>ZlibStream</c> can be used for <c>Read()</c> or <c>Write()</c>, but
 ///   not both.
 /// </para>
 ///
 /// </remarks>
 ///
 /// <param name="buffer">
 /// The buffer into which the read data should be placed.</param>
 ///
 /// <param name="offset">
 /// the offset within that data array to put the first byte read.</param>
 ///
 /// <param name="count">the number of bytes to read.</param>
 ///
 /// <returns>the number of bytes read</returns>
 public override int Read(byte[] buffer, int offset, int count)
 {
     if (_disposed)
     {
         throw new ObjectDisposedException("ZlibStream");
     }
     return(_baseStream.Read(buffer, offset, count));
 }
Beispiel #2
0
        /// <summary>
        ///   Read and decompress data from the source stream.
        /// </summary>
        ///
        /// <remarks>
        ///   With a <c>GZipStream</c>, decompression is done through reading.
        /// </remarks>
        ///
        /// <example>
        /// <code>
        /// byte[] working = new byte[WORKING_BUFFER_SIZE];
        /// using (System.IO.Stream input = System.IO.File.OpenRead(_CompressedFile))
        /// {
        ///     using (Stream decompressor= new Ionic.Zlib.GZipStream(input, CompressionMode.Decompress, true))
        ///     {
        ///         using (var output = System.IO.File.Create(_DecompressedFile))
        ///         {
        ///             int n;
        ///             while ((n= decompressor.Read(working, 0, working.Length)) !=0)
        ///             {
        ///                 output.Write(working, 0, n);
        ///             }
        ///         }
        ///     }
        /// }
        /// </code>
        /// </example>
        /// <param name="buffer">The buffer into which the decompressed data should be placed.</param>
        /// <param name="offset">the offset within that data array to put the first byte read.</param>
        /// <param name="count">the number of bytes to read.</param>
        /// <returns>the number of bytes actually read</returns>
        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);
        }