Пример #1
0
 /// <summary>
 /// Read data from the stream.
 /// </summary>
 /// <remarks>
 ///
 /// <para>
 ///   If you wish to use the <c>DeflateStream</c> to compress data while
 ///   reading, you can create a <c>DeflateStream</c> with
 ///   <c>CompressionMode.Compress</c>, providing an uncompressed data stream.
 ///   Then call Read() on that <c>DeflateStream</c>, and the data read will be
 ///   compressed as you read.  If you wish to use the <c>DeflateStream</c> to
 ///   decompress data while reading, you can create a <c>DeflateStream</c> with
 ///   <c>CompressionMode.Decompress</c>, providing a readable compressed data
 ///   stream.  Then call Read() on that <c>DeflateStream</c>, and the data read
 ///   will be decompressed as you read.
 /// </para>
 ///
 /// <para>
 ///   A <c>DeflateStream</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 actually read</returns>
 public override int Read(byte[] buffer, int offset, int count)
 {
     if (_disposed)
     {
         throw new ObjectDisposedException("DeflateStream");
     }
     return(_baseStream.Read(buffer, offset, count));
 }
Пример #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);
        }