Files
sharpcompress/src/SharpCompress/Common/Volume.cs
Matt Kotsenas 6c25322465 Follow best-practices for Dispose in Volume and ForwardOnlyStream
Update `Volume` and `ForwardOnlyStream` to follow the project's
general pattern and best-practices for `Dispose`
2018-07-11 16:21:19 -07:00

51 lines
1.3 KiB
C#

using System;
using System.IO;
using SharpCompress.IO;
using SharpCompress.Readers;
namespace SharpCompress.Common
{
public abstract class Volume : IVolume
{
private readonly Stream _actualStream;
internal Volume(Stream stream, ReaderOptions readerOptions)
{
ReaderOptions = readerOptions;
if (readerOptions.LeaveStreamOpen)
{
stream = new NonDisposingStream(stream);
}
_actualStream = stream;
}
internal Stream Stream => _actualStream;
protected ReaderOptions ReaderOptions { get; }
/// <summary>
/// RarArchive is the first volume of a multi-part archive.
/// Only Rar 3.0 format and higher
/// </summary>
public virtual bool IsFirstVolume => true;
/// <summary>
/// RarArchive is part of a multi-part archive.
/// </summary>
public virtual bool IsMultiVolume => true;
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
_actualStream.Dispose();
}
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
}