System.StreamExtensions.CheckGZipHeader C# (CSharp) Méthode

CheckGZipHeader() public static méthode

public static CheckGZipHeader ( this stream ) : bool
stream this
Résultat bool
        public static bool CheckGZipHeader(this Stream stream)
        {
            Debug.Assert(stream.CanRead, "Cannot check the header of the stream - the stream is not readable");
            Debug.Assert(stream.CanSeek, "Cannot check the header of the stream - the stream is not seekable");

            long currentPosition = stream.Position;

            byte[] magicBytes = new byte[2];
            stream.Seek(0, SeekOrigin.Begin);
            stream.Read(magicBytes, 0, 2);
            if (magicBytes[0] == 0x1f && magicBytes[1] == 0x8b)
            {
                stream.Seek(currentPosition, SeekOrigin.Begin);
                return true;
            }
            else
            {
                stream.Seek(currentPosition, SeekOrigin.Begin);
                return false;
            }
        }