REFACTOR: Final cleanup of DiscImageChef.Filters.

This commit is contained in:
2017-12-24 02:43:49 +00:00
parent 4115698ac8
commit f9cc6e6918
13 changed files with 495 additions and 487 deletions

View File

@@ -36,19 +36,19 @@ using System.IO;
namespace DiscImageChef.Filters
{
/// <summary>
/// ForcedSeekStream allows to seek a forward-readable stream (like System.IO.Compression streams)
/// by doing the slow and known trick of rewinding and forward reading until arriving the desired position.
/// ForcedSeekStream allows to seek a forward-readable stream (like System.IO.Compression streams)
/// by doing the slow and known trick of rewinding and forward reading until arriving the desired position.
/// </summary>
public class ForcedSeekStream<T> : Stream where T : Stream
{
const int BUFFER_LEN = 1048576;
string backFile;
FileStream backStream;
T baseStream;
long streamLength;
const int BUFFER_LEN = 1048576;
FileStream backStream;
string backFile;
/// <summary>
/// Initializes a new instance of the <see cref="T:DiscImageChef.Filters.ForcedSeekStream`1"/> class.
/// Initializes a new instance of the <see cref="T:DiscImageChef.Filters.ForcedSeekStream`1" /> class.
/// </summary>
/// <param name="length">The real (uncompressed) length of the stream.</param>
/// <param name="args">Parameters that are used to create the base stream.</param>
@@ -62,7 +62,7 @@ namespace DiscImageChef.Filters
}
/// <summary>
/// Initializes a new instance of the <see cref="T:DiscImageChef.Filters.ForcedSeekStream`1"/> class.
/// Initializes a new instance of the <see cref="T:DiscImageChef.Filters.ForcedSeekStream`1" /> class.
/// </summary>
/// <param name="args">Parameters that are used to create the base stream.</param>
public ForcedSeekStream(params object[] args)
@@ -73,27 +73,6 @@ namespace DiscImageChef.Filters
CalculateLength();
}
/// <summary>
/// Calculates the real (uncompressed) length of the stream.
/// It basically reads (uncompresses) the whole stream to memory discarding its contents,
/// so it should be used as a last resort.
/// </summary>
/// <returns>The length.</returns>
public void CalculateLength()
{
int read;
do
{
byte[] buffer = new byte[BUFFER_LEN];
read = baseStream.Read(buffer, 0, BUFFER_LEN);
backStream.Write(buffer, 0, read);
}
while(read == BUFFER_LEN);
streamLength = backStream.Length;
backStream.Position = 0;
}
public override bool CanRead => baseStream.CanRead;
public override bool CanSeek => true;
@@ -109,6 +88,27 @@ namespace DiscImageChef.Filters
set => SetPosition(value);
}
/// <summary>
/// Calculates the real (uncompressed) length of the stream.
/// It basically reads (uncompresses) the whole stream to memory discarding its contents,
/// so it should be used as a last resort.
/// </summary>
/// <returns>The length.</returns>
public void CalculateLength()
{
int read;
do
{
byte[] buffer = new byte[BUFFER_LEN];
read = baseStream.Read(buffer, 0, BUFFER_LEN);
backStream.Write(buffer, 0, read);
}
while(read == BUFFER_LEN);
streamLength = backStream.Length;
backStream.Position = 0;
}
void SetPosition(long position)
{
if(position == backStream.Position) return;