(ProxyStream): new base class for stream post-processing.

This commit is contained in:
morkt 2016-03-14 04:21:55 +04:00
parent 2abe3c706a
commit 5704a61823

View File

@ -27,6 +27,80 @@ using System;
using System.IO;
namespace GameRes.Formats
{
/// <summary>
/// Base class for various filter streams.
/// </summary>
public class ProxyStream : Stream
{
Stream m_stream;
bool m_should_dispose;
public ProxyStream (Stream input, bool leave_open = false)
{
m_stream = input;
m_should_dispose = !leave_open;
}
public Stream BaseStream { get { return m_stream; } }
public override bool CanRead { get { return m_stream.CanRead; } }
public override bool CanSeek { get { return m_stream.CanSeek; } }
public override bool CanWrite { get { return m_stream.CanWrite; } }
public override long Length { get { return m_stream.Length; } }
public override long Position
{
get { return m_stream.Position; }
set { m_stream.Position = value; }
}
public override int Read (byte[] buffer, int offset, int count)
{
return m_stream.Read (buffer, offset, count);
}
public override int ReadByte ()
{
return m_stream.ReadByte();
}
public override void Flush()
{
m_stream.Flush();
}
public override long Seek (long offset, SeekOrigin origin)
{
return m_stream.Seek (offset, origin);
}
public override void SetLength (long length)
{
m_stream.SetLength (length);
}
public override void Write (byte[] buffer, int offset, int count)
{
m_stream.Write (buffer, offset, count);
}
public override void WriteByte (byte value)
{
m_stream.WriteByte (value);
}
bool _proxy_disposed = false;
protected override void Dispose (bool disposing)
{
if (!_proxy_disposed)
{
if (m_should_dispose && disposing)
m_stream.Dispose();
_proxy_disposed = true;
base.Dispose (disposing);
}
}
}
public class PrefixStream : Stream
{
byte[] m_header;