예제 #1
0
        /// <summary>
        /// Reads a compressed byte array from this stream.
        /// </summary>
        /// <param name="stream">The stream to read from.</param>
        /// <param name="validityCheck">Set this parameter <c>true</c> if there is a check code before the array to detect data corruption; otherwise, set this <c>false</c>.</param>
        /// <returns>
        /// The byte array read from the stream.
        /// </returns>
        /// <exception cref="System.IO.InvalidDataException">Raises if data in the stream is corrupted.</exception>
        public static byte[] ReadCompressedByteArray(this Stream stream, bool validityCheck = false)
        {
            var data = stream.ReadByteArray();

            if (data.IsNullOrEmpty())
            {
                return(null);
            }
            using (var ms = new MemoryStream(data))
                using (var cms = new GZipStream(ms, CompressionMode.Decompress))
                    return(cms.ReadByteArray(validityCheck));
        }