Пример #1
0
        /// <summary>
        /// Decompresses the data at the current read position in the source stream to the specified targetstream.
        /// </summary>
        /// <param name="sourceStream">The stream containing the data to be compressed.</param>
        /// <param name="targetStream">The stream that will receive the decompressed data.</param>
        /// <param name="count">The number of bytes to decompress.</param>
        /// <param name="closeStream">Close the source stream after decompression.</param>
        public static void Decompress(Stream sourceStream, Stream targetStream, long count, bool closeStream)
        {
            if (sourceStream == null)
            {
                throw new ArgumentNullException(nameof(sourceStream));
            }

            if (targetStream == null)
            {
                throw new ArgumentNullException(nameof(targetStream));
            }

            var decompressStream = new InflaterInputStream(sourceStream)
            {
                IsStreamOwner = false,
            };

            if (count > 0)
            {
                decompressStream.CopyBlocksTo(targetStream, count);
            }
            else
            {
                decompressStream.CopyBlocksTo(targetStream);
            }

            if (closeStream)
            {
#if !NETSTANDARD13
                sourceStream.Close();
#endif
            }
        }