(StreamRegion): added leave_open argument to constructor.

This commit is contained in:
morkt 2015-06-14 10:19:16 +04:00
parent ab70e8b9f8
commit 0955c15181

View File

@ -196,13 +196,15 @@ namespace GameRes.Formats
private Stream m_stream; private Stream m_stream;
private long m_begin; private long m_begin;
private long m_end; private long m_end;
private bool m_should_dispose;
public StreamRegion (Stream main, long offset, long length) public StreamRegion (Stream main, long offset, long length, bool leave_open = false)
{ {
m_stream = main; m_stream = main;
m_begin = offset; m_begin = offset;
m_end = Math.Min (offset + length, m_stream.Length); m_end = Math.Min (offset + length, m_stream.Length);
m_stream.Position = m_begin; m_stream.Position = m_begin;
m_should_dispose = !leave_open;
} }
public StreamRegion (Stream main, long offset) : this (main, offset, main.Length-offset) public StreamRegion (Stream main, long offset) : this (main, offset, main.Length-offset)
@ -276,6 +278,7 @@ namespace GameRes.Formats
{ {
if (!m_disposed) if (!m_disposed)
{ {
if (m_should_dispose)
m_stream.Dispose(); m_stream.Dispose();
m_disposed = true; m_disposed = true;
base.Dispose (disposing); base.Dispose (disposing);