Exemplo n.º 1
0
    public virtual bool IsNbtDocument(Stream stream)
    {
      bool result;
      long position;

      position = stream.Position;

      try
      {
        if (stream.IsGzipCompressed())
        {
          using (Stream decompressionStream = new GZipStream(stream, CompressionMode.Decompress, true))
          {
            result = decompressionStream.PeekNextByte() == (int)TagType.Compound;
          }
        }
        else if (stream.IsDeflateCompressed())
        {
          using (Stream decompressionStream = new DeflateStream(stream, CompressionMode.Decompress, true))
          {
            result = decompressionStream.PeekNextByte() == (int)TagType.Compound;
          }
        }
        else if (stream.PeekNextByte() == (int)TagType.Compound)
        {
          result = true;
        }
        else
        {
          result = false;
        }
      }
      catch
      {
        result = false;
      }

      stream.Position = position;

      return result;
    }