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; }
public virtual TagCompound ReadDocument(Stream stream, ReadTagOptions options) { TagCompound tag; if (stream.IsGzipCompressed()) { using (Stream decompressionStream = new GZipStream(stream, CompressionMode.Decompress)) { _stream = decompressionStream; tag = (TagCompound)this.ReadTag(options); } } else if (stream.IsDeflateCompressed()) { using (Stream decompressionStream = new DeflateStream(stream, CompressionMode.Decompress)) { _stream = decompressionStream; tag = (TagCompound)this.ReadTag(options); } } else if (stream.PeekNextByte() == (int)TagType.Compound) { _stream = stream; tag = (TagCompound)this.ReadTag(options); } else { throw new InvalidDataException("Source stream does not contain a NBT document."); } return tag; }