diff --git a/Aaru.Archives/Symbian/Files.cs b/Aaru.Archives/Symbian/Files.cs
index 9ef08777c..f5d436d27 100644
--- a/Aaru.Archives/Symbian/Files.cs
+++ b/Aaru.Archives/Symbian/Files.cs
@@ -35,6 +35,7 @@ using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using Aaru.Filters;
+using Aaru.Helpers.IO;
using FileAttributes = System.IO.FileAttributes;
namespace Aaru.Archives;
diff --git a/Aaru.Compression/Aaru.Compression.csproj b/Aaru.Compression/Aaru.Compression.csproj
index 456441051..01669204c 100644
--- a/Aaru.Compression/Aaru.Compression.csproj
+++ b/Aaru.Compression/Aaru.Compression.csproj
@@ -58,7 +58,6 @@
-
diff --git a/Aaru.Compression/FLAC.cs b/Aaru.Compression/FLAC.cs
index fb8451d5d..767ff9afd 100644
--- a/Aaru.Compression/FLAC.cs
+++ b/Aaru.Compression/FLAC.cs
@@ -28,6 +28,7 @@
using System.IO;
using System.Runtime.InteropServices;
+using Aaru.Helpers.IO;
using CUETools.Codecs;
using CUETools.Codecs.Flake;
diff --git a/Aaru.Compression/NonClosableStream.cs b/Aaru.Compression/NonClosableStream.cs
deleted file mode 100644
index d36c17bdb..000000000
--- a/Aaru.Compression/NonClosableStream.cs
+++ /dev/null
@@ -1,81 +0,0 @@
-// /***************************************************************************
-// Aaru Data Preservation Suite
-// ----------------------------------------------------------------------------
-//
-// Filename : NonClosableStream.cs
-// Author(s) : Natalia Portillo
-//
-// Component : Compression.
-//
-// --[ Description ] ----------------------------------------------------------
-//
-// Overrides MemoryStream to ignore standard close requests.
-//
-// --[ License ] --------------------------------------------------------------
-//
-// This library is free software; you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as
-// published by the Free Software Foundation; either version 2.1 of the
-// License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, see .
-//
-// ----------------------------------------------------------------------------
-// Copyright © 2011-2023 Natalia Portillo
-// ****************************************************************************/
-
-using System.Diagnostics.CodeAnalysis;
-using System.IO;
-using Aaru.Helpers;
-
-namespace Aaru.Compression;
-
-///
-/// Creates a MemoryStream that ignores close commands
-[SuppressMessage("ReSharper", "UnusedMember.Global")]
-sealed class NonClosableStream : Stream
-{
- readonly MemoryStream _baseStream;
-
- internal NonClosableStream(byte[] buffer) => _baseStream = new MemoryStream(buffer);
-
- internal NonClosableStream() => _baseStream = new MemoryStream();
-
- public override bool CanRead => _baseStream.CanRead;
- public override bool CanSeek => _baseStream.CanSeek;
- public override bool CanWrite => _baseStream.CanWrite;
- public override long Length => _baseStream.Length;
-
- public override long Position
- {
- get => _baseStream.Position;
- set => _baseStream.Position = value;
- }
-
- public override void Flush() => _baseStream.Flush();
-
- public override int Read(byte[] buffer, int offset, int count) => _baseStream.EnsureRead(buffer, offset, count);
-
- public override long Seek(long offset, SeekOrigin origin) => _baseStream.Seek(offset, origin);
-
- public override void SetLength(long value) => _baseStream.SetLength(value);
-
- public override void Write(byte[] buffer, int offset, int count) => _baseStream.Write(buffer, offset, count);
-
- public override void Close()
- {
- // Do nothing
- }
-
- internal byte[] GetBuffer() => _baseStream.GetBuffer();
-
- internal byte[] ToArray() => _baseStream.ToArray();
-
- internal void ReallyClose() => _baseStream.Close();
-}
\ No newline at end of file
diff --git a/Aaru.Filters/AppleDouble.cs b/Aaru.Filters/AppleDouble.cs
index 240758e1d..8ccff5ba1 100644
--- a/Aaru.Filters/AppleDouble.cs
+++ b/Aaru.Filters/AppleDouble.cs
@@ -38,6 +38,7 @@ using System.Runtime.InteropServices;
using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Interfaces;
using Aaru.Helpers;
+using Aaru.Helpers.IO;
using Marshal = Aaru.Helpers.Marshal;
namespace Aaru.Filters;
diff --git a/Aaru.Filters/AppleSingle.cs b/Aaru.Filters/AppleSingle.cs
index 408016731..1fdb885ab 100644
--- a/Aaru.Filters/AppleSingle.cs
+++ b/Aaru.Filters/AppleSingle.cs
@@ -38,6 +38,7 @@ using System.Runtime.InteropServices;
using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Interfaces;
using Aaru.Helpers;
+using Aaru.Helpers.IO;
using Marshal = Aaru.Helpers.Marshal;
namespace Aaru.Filters;
diff --git a/Aaru.Filters/BZip2.cs b/Aaru.Filters/BZip2.cs
index 4ec84d8a6..9ee51194c 100644
--- a/Aaru.Filters/BZip2.cs
+++ b/Aaru.Filters/BZip2.cs
@@ -35,6 +35,7 @@ using System.IO;
using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Interfaces;
using Aaru.Helpers;
+using Aaru.Helpers.IO;
using Ionic.BZip2;
namespace Aaru.Filters;
diff --git a/Aaru.Filters/ForcedSeekStream.cs b/Aaru.Filters/ForcedSeekStream.cs
deleted file mode 100644
index 5e40f641f..000000000
--- a/Aaru.Filters/ForcedSeekStream.cs
+++ /dev/null
@@ -1,258 +0,0 @@
-// /***************************************************************************
-// Aaru Data Preservation Suite
-// ----------------------------------------------------------------------------
-//
-// Filename : ForcedSeekStream.cs
-// Author(s) : Natalia Portillo
-//
-// Component : Filters.
-//
-// --[ Description ] ----------------------------------------------------------
-//
-// Provides a seekable stream from a forward-readable stream.
-//
-// --[ License ] --------------------------------------------------------------
-//
-// This library is free software; you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as
-// published by the Free Software Foundation; either version 2.1 of the
-// License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, see .
-//
-// ----------------------------------------------------------------------------
-// Copyright © 2011-2023 Natalia Portillo
-// ****************************************************************************/
-
-using System;
-using System.IO;
-using Aaru.Helpers;
-
-namespace Aaru.Filters;
-
-///
-/// 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.
-///
-///
-public sealed class ForcedSeekStream : Stream where T : Stream
-{
- const int BUFFER_LEN = 1048576;
- readonly string _backFile;
- readonly FileStream _backStream;
- readonly T _baseStream;
- long _streamLength;
-
- /// Initializes a new instance of the class.
- /// The real (uncompressed) length of the stream.
- /// Parameters that are used to create the base stream.
- ///
- public ForcedSeekStream(long length, params object[] args)
- {
- _streamLength = length;
- _baseStream = (T)Activator.CreateInstance(typeof(T), args);
- _backFile = Path.GetTempFileName();
- _backStream = new FileStream(_backFile, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
-
- if(length == 0)
- CalculateLength();
- }
-
- /// Initializes a new instance of the class.
- /// Parameters that are used to create the base stream.
- ///
- public ForcedSeekStream(params object[] args)
- {
- _baseStream = (T)Activator.CreateInstance(typeof(T), args);
- _backFile = Path.GetTempFileName();
- _backStream = new FileStream(_backFile, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
- CalculateLength();
- }
-
- ///
- public override bool CanRead => _baseStream.CanRead;
-
- ///
- public override bool CanSeek => true;
-
- ///
- public override bool CanWrite => false;
-
- ///
- public override long Length => _streamLength;
-
- ///
- public override long Position
- {
- get => _backStream.Position;
-
- set => SetPosition(value);
- }
-
- ///
- /// 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.
- ///
- /// The length.
- public void CalculateLength()
- {
- int read;
-
- do
- {
- var buffer = new byte[BUFFER_LEN];
- read = _baseStream.EnsureRead(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;
-
- if(position < _backStream.Length)
- {
- _backStream.Position = position;
-
- return;
- }
-
- if(position > _streamLength)
- position = _streamLength;
-
- _backStream.Position = _backStream.Length;
- long toPosition = position - _backStream.Position;
- var fullBufferReads = (int)(toPosition / BUFFER_LEN);
- var restToRead = (int)(toPosition % BUFFER_LEN);
- byte[] buffer;
- int bufPos;
- int left;
-
- for(var i = 0; i < fullBufferReads; i++)
- {
- buffer = new byte[BUFFER_LEN];
- bufPos = 0;
- left = BUFFER_LEN;
-
- while(left > 0)
- {
- int done = _baseStream.EnsureRead(buffer, bufPos, left);
- left -= done;
- bufPos += done;
- }
-
- _backStream.Write(buffer, 0, BUFFER_LEN);
- }
-
- buffer = new byte[restToRead];
- bufPos = 0;
- left = restToRead;
-
- while(left > 0)
- {
- int done = _baseStream.EnsureRead(buffer, bufPos, left);
- left -= done;
- bufPos += done;
- }
-
- _backStream.Write(buffer, 0, restToRead);
- }
-
- ///
- public override void Flush()
- {
- _baseStream.Flush();
- _backStream.Flush();
- }
-
- ///
- public override int Read(byte[] buffer, int offset, int count)
- {
- if(_backStream.Position + count > _streamLength)
- count = (int)(_streamLength - _backStream.Position);
-
- if(_backStream.Position + count <= _backStream.Length)
- return _backStream.EnsureRead(buffer, offset, count);
-
- long oldPosition = _backStream.Position;
- SetPosition(_backStream.Position + count);
- SetPosition(oldPosition);
-
- return _backStream.EnsureRead(buffer, offset, count);
- }
-
- ///
- public override int ReadByte()
- {
- if(_backStream.Position + 1 > _streamLength)
- return -1;
-
- if(_backStream.Position + 1 <= _backStream.Length)
- return _backStream.ReadByte();
-
- SetPosition(_backStream.Position + 1);
- SetPosition(_backStream.Position - 1);
-
- return _backStream.ReadByte();
- }
-
- ///
- public override long Seek(long offset, SeekOrigin origin)
- {
- switch(origin)
- {
- case SeekOrigin.Begin:
- if(offset < 0)
- throw new IOException(Localization.Cannot_seek_before_stream_start);
-
- SetPosition(offset);
-
- break;
- case SeekOrigin.End:
- if(offset > 0)
- throw new IOException(Localization.Cannot_seek_after_stream_end);
-
- if(_streamLength == 0)
- CalculateLength();
-
- SetPosition(_streamLength + offset);
-
- break;
- default:
- SetPosition(_backStream.Position + offset);
-
- break;
- }
-
- return _backStream.Position;
- }
-
- ///
- public override void SetLength(long value) => throw new NotSupportedException();
-
- ///
- public override void Write(byte[] buffer, int offset, int count) => throw new NotSupportedException();
-
- ///
- public override void Close()
- {
- _backStream?.Close();
- File.Delete(_backFile);
- }
-
- ~ForcedSeekStream()
- {
- _backStream?.Close();
- File.Delete(_backFile);
- }
-}
\ No newline at end of file
diff --git a/Aaru.Filters/GZip.cs b/Aaru.Filters/GZip.cs
index d7e231929..5ee86f209 100644
--- a/Aaru.Filters/GZip.cs
+++ b/Aaru.Filters/GZip.cs
@@ -36,6 +36,7 @@ using System.IO.Compression;
using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Interfaces;
using Aaru.Helpers;
+using Aaru.Helpers.IO;
namespace Aaru.Filters;
diff --git a/Aaru.Filters/LZip.cs b/Aaru.Filters/LZip.cs
index 508ce5ff0..dff30c12b 100644
--- a/Aaru.Filters/LZip.cs
+++ b/Aaru.Filters/LZip.cs
@@ -35,6 +35,7 @@ using System.IO;
using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Interfaces;
using Aaru.Helpers;
+using Aaru.Helpers.IO;
using SharpCompress.Compressors;
using SharpCompress.Compressors.LZMA;
diff --git a/Aaru.Filters/Localization/Localization.Designer.cs b/Aaru.Filters/Localization/Localization.Designer.cs
index 9c3f79d8e..acb88643f 100644
--- a/Aaru.Filters/Localization/Localization.Designer.cs
+++ b/Aaru.Filters/Localization/Localization.Designer.cs
@@ -77,15 +77,6 @@ namespace Aaru.Filters {
}
}
- ///
- /// Looks up a localized string similar to Asynchronous I/O is not supported..
- ///
- internal static string Asynchronous_IO_is_not_supported {
- get {
- return ResourceManager.GetString("Asynchronous_IO_is_not_supported", resourceCulture);
- }
- }
-
///
/// Looks up a localized string similar to BZip2.
///
@@ -95,78 +86,6 @@ namespace Aaru.Filters {
}
}
- ///
- /// Looks up a localized string similar to Cannot read past stream end..
- ///
- internal static string Cannot_read_past_stream_end {
- get {
- return ResourceManager.GetString("Cannot_read_past_stream_end", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Cannot seek after stream end..
- ///
- internal static string Cannot_seek_after_stream_end {
- get {
- return ResourceManager.GetString("Cannot_seek_after_stream_end", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Cannot seek before stream start..
- ///
- internal static string Cannot_seek_before_stream_start {
- get {
- return ResourceManager.GetString("Cannot_seek_before_stream_start", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Cannot set position past stream end..
- ///
- internal static string Cannot_set_position_past_stream_end {
- get {
- return ResourceManager.GetString("Cannot_set_position_past_stream_end", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Cannot write past stream end..
- ///
- internal static string Cannot_write_past_stream_end {
- get {
- return ResourceManager.GetString("Cannot_write_past_stream_end", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to End can't be a negative number..
- ///
- internal static string End_cant_be_a_negative_number {
- get {
- return ResourceManager.GetString("End_cant_be_a_negative_number", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to End is after stream end..
- ///
- internal static string End_is_after_stream_end {
- get {
- return ResourceManager.GetString("End_is_after_stream_end", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Growing OffsetStream is not supported..
- ///
- internal static string Growing_OffsetStream_is_not_supported {
- get {
- return ResourceManager.GetString("Growing_OffsetStream_is_not_supported", resourceCulture);
- }
- }
-
///
/// Looks up a localized string similar to GZip.
///
@@ -194,24 +113,6 @@ namespace Aaru.Filters {
}
}
- ///
- /// Looks up a localized string similar to Non-readable streams are not supported.
- ///
- internal static string Non_readable_streams_are_not_supported {
- get {
- return ResourceManager.GetString("Non_readable_streams_are_not_supported", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to Non-seekable streams are not supported.
- ///
- internal static string Non_seekable_streams_are_not_supported {
- get {
- return ResourceManager.GetString("Non_seekable_streams_are_not_supported", resourceCulture);
- }
- }
-
///
/// Looks up a localized string similar to PCExchange.
///
@@ -221,24 +122,6 @@ namespace Aaru.Filters {
}
}
- ///
- /// Looks up a localized string similar to Start can't be a negative number..
- ///
- internal static string Start_cant_be_a_negative_number {
- get {
- return ResourceManager.GetString("Start_cant_be_a_negative_number", resourceCulture);
- }
- }
-
- ///
- /// Looks up a localized string similar to This stream is read-only.
- ///
- internal static string This_stream_is_read_only {
- get {
- return ResourceManager.GetString("This_stream_is_read_only", resourceCulture);
- }
- }
-
///
/// Looks up a localized string similar to XZ.
///
diff --git a/Aaru.Filters/Localization/Localization.es.resx b/Aaru.Filters/Localization/Localization.es.resx
index badeea524..43bbdf342 100644
--- a/Aaru.Filters/Localization/Localization.es.resx
+++ b/Aaru.Filters/Localization/Localization.es.resx
@@ -21,36 +21,9 @@
AppleSingle
-
-
- E/S asíncrona no soportada.
BZip2
-
-
- No se puede leer más allá del final de la secuencia.
-
-
- No se puede posicionar después del final de la secuencia.
-
-
- No se puede posicionar antes del comienzo de la secuencia.
-
-
- No se puede establecer la posición más allá del final de la secuencia.
-
-
- No se puede escribir después del final de la secuencia.
-
-
- El final no puede ser un número negativo.
-
-
- El final está después del final de la secuencia.
-
-
- No se puede agrandar un OffsetStream.
GZip
@@ -60,21 +33,9 @@
MacBinary
-
-
- Las secuencias no legíbles no están soportadas.
-
-
- Las secuencias no posicionables no están soportadas.
PCExchange
-
-
- El comienzo no puede ser un número negativo.
-
-
- Esta secuencia es de sólo lectura.
XZ
diff --git a/Aaru.Filters/Localization/Localization.resx b/Aaru.Filters/Localization/Localization.resx
index 712480c09..7f910c6ec 100644
--- a/Aaru.Filters/Localization/Localization.resx
+++ b/Aaru.Filters/Localization/Localization.resx
@@ -31,12 +31,6 @@
BZip2
-
-
- Cannot seek before stream start.
-
-
- Cannot seek after stream end.
GZip
@@ -46,42 +40,9 @@
MacBinary
-
-
- Start can't be a negative number.
-
-
- End can't be a negative number.
-
-
- End is after stream end.
-
-
- Cannot set position past stream end.
-
-
- Cannot read past stream end.
-
-
- Cannot write past stream end.
-
-
- Growing OffsetStream is not supported.
-
+
PCExchange
-
-
- Non-seekable streams are not supported
-
-
- Non-readable streams are not supported
-
-
- Asynchronous I/O is not supported.
-
-
- This stream is read-only
XZ
diff --git a/Aaru.Filters/MacBinary.cs b/Aaru.Filters/MacBinary.cs
index 93e76e702..b4a700352 100644
--- a/Aaru.Filters/MacBinary.cs
+++ b/Aaru.Filters/MacBinary.cs
@@ -37,6 +37,7 @@ using System.Text;
using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Interfaces;
using Aaru.Helpers;
+using Aaru.Helpers.IO;
using Marshal = Aaru.Helpers.Marshal;
namespace Aaru.Filters;
diff --git a/Aaru.Filters/OffsetStream.cs b/Aaru.Filters/OffsetStream.cs
deleted file mode 100644
index 41f4e12c2..000000000
--- a/Aaru.Filters/OffsetStream.cs
+++ /dev/null
@@ -1,681 +0,0 @@
-// /***************************************************************************
-// Aaru Data Preservation Suite
-// ----------------------------------------------------------------------------
-//
-// Filename : OffsetStream.cs
-// Author(s) : Natalia Portillo
-//
-// Component : Filters.
-//
-// --[ Description ] ----------------------------------------------------------
-//
-// Provides a stream that's a subset of another stream.
-//
-// --[ License ] --------------------------------------------------------------
-//
-// This library is free software; you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as
-// published by the Free Software Foundation; either version 2.1 of the
-// License, or (at your option) any later version.
-//
-// This library is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, see .
-//
-// ----------------------------------------------------------------------------
-// Copyright © 2011-2023 Natalia Portillo
-// ****************************************************************************/
-
-using System;
-using System.Diagnostics.CodeAnalysis;
-using System.IO;
-using Aaru.Helpers;
-using Microsoft.Win32.SafeHandles;
-#if !NETSTANDARD2_0
-
-#endif
-
-namespace Aaru.Filters;
-
-/// Creates a stream that is a subset of another stream.
-///
-[SuppressMessage("ReSharper", "UnusedMember.Global")]
-public sealed class OffsetStream : Stream
-{
- readonly Stream _baseStream;
- readonly long _streamEnd;
- readonly long _streamStart;
-
- ///
- ///
- /// Initializes a stream that only allows reading from to of the
- /// specified stream, both inclusive.
- ///
- /// Base stream
- /// Start position
- /// Last readable position
- /// Invalid range
- public OffsetStream(Stream stream, long start, long end)
- {
- if(start < 0)
- throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number);
-
- if(end < 0)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number);
-
- _streamStart = start;
- _streamEnd = end;
-
- _baseStream = stream;
-
- if(end > _baseStream.Length)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end);
-
- _baseStream.Position = start;
- }
-
- ///
- ///
- /// Initializes a stream that only allows reading from to of the
- /// specified file, both inclusive.
- ///
- /// A relative or absolute path for the file that the stream will encapsulate.
- /// One of the enumeration values that determines how to open or create the file.
- ///
- /// A bitwise combination of the enumeration values that determines how the file can be accessed by a
- /// object.
- ///
- ///
- /// A bitwise combination of the enumeration values that determines how the file will be shared by
- /// processes.
- ///
- ///
- /// A positive Int32 value greater than 0 indicating the buffer size. The default buffer size is
- /// 4096.
- ///
- /// A bitwise combination of the enumeration values that specifies additional file options.
- /// Start position
- /// Last readable position
- /// Invalid range
- public OffsetStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize,
- FileOptions options, long start, long end)
- {
- if(start < 0)
- throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number);
-
- if(end < 0)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number);
-
- _streamStart = start;
- _streamEnd = end;
-
- _baseStream = new FileStream(path, mode, access, share, bufferSize, options);
-
- if(end > _baseStream.Length)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end);
-
- _baseStream.Position = start;
- }
-
- ///
- ///
- /// Initializes a stream that only allows reading from to of the
- /// specified file, both inclusive.
- ///
- /// A file handle for the file that the stream will encapsulate.
- ///
- /// A bitwise combination of the enumeration values that determines how the file can be accessed by a
- /// object.
- ///
- /// Start position
- /// Last readable position
- /// Invalid range
- public OffsetStream(SafeFileHandle handle, FileAccess access, long start, long end)
- {
- if(start < 0)
- throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number);
-
- if(end < 0)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number);
-
- _streamStart = start;
- _streamEnd = end;
-
- _baseStream = new FileStream(handle, access);
-
- if(end > _baseStream.Length)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end);
-
- _baseStream.Position = start;
- }
-
- ///
- ///
- /// Initializes a stream that only allows reading from to of the
- /// specified file, both inclusive.
- ///
- /// A file handle for the file that the stream will encapsulate.
- ///
- /// A bitwise combination of the enumeration values that determines how the file can be accessed by a
- /// object.
- ///
- ///
- /// A positive Int32 value greater than 0 indicating the buffer size. The default buffer size is
- /// 4096.
- ///
- /// Start position
- /// Last readable position
- /// Invalid range
- public OffsetStream(SafeFileHandle handle, FileAccess access, int bufferSize, long start, long end)
- {
- if(start < 0)
- throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number);
-
- if(end < 0)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number);
-
- _streamStart = start;
- _streamEnd = end;
-
- _baseStream = new FileStream(handle, access, bufferSize);
-
- if(end > _baseStream.Length)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end);
-
- _baseStream.Position = start;
- }
-
- ///
- ///
- /// Initializes a stream that only allows reading from to of the
- /// specified file, both inclusive.
- ///
- /// A file handle for the file that the stream will encapsulate.
- ///
- /// A bitwise combination of the enumeration values that determines how the file can be accessed by a
- /// object.
- ///
- ///
- /// A positive Int32 value greater than 0 indicating the buffer size. The default buffer size is
- /// 4096.
- ///
- /// Specifies whether to use asynchronous I/O or synchronous I/O.
- /// Start position
- /// Last readable position
- /// Invalid range
- public OffsetStream(SafeFileHandle handle, FileAccess access, int bufferSize, bool isAsync, long start, long end)
- {
- if(start < 0)
- throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number);
-
- if(end < 0)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number);
-
- _streamStart = start;
- _streamEnd = end;
-
- _baseStream = new FileStream(handle, access, bufferSize, isAsync);
-
- if(end > _baseStream.Length)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end);
-
- _baseStream.Position = start;
- }
-
- ///
- ///
- /// Initializes a stream that only allows reading from to of the
- /// specified file, both inclusive.
- ///
- /// A relative or absolute path for the file that the stream will encapsulate.
- /// One of the enumeration values that determines how to open or create the file.
- ///
- /// A bitwise combination of the enumeration values that determines how the file can be accessed by a
- /// object.
- ///
- ///
- /// A bitwise combination of the enumeration values that determines how the file will be shared by
- /// processes.
- ///
- ///
- /// A positive Int32 value greater than 0 indicating the buffer size. The default buffer size is
- /// 4096.
- ///
- /// Specifies whether to use asynchronous I/O or synchronous I/O.
- /// Start position
- /// Last readable position
- /// Invalid range
- public OffsetStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, bool useAsync,
- long start, long end)
- {
- if(start < 0)
- throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number);
-
- if(end < 0)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number);
-
- _streamStart = start;
- _streamEnd = end;
-
- _baseStream = new FileStream(path, mode, access, share, bufferSize, useAsync);
-
- if(end > _baseStream.Length)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end);
-
- _baseStream.Position = start;
- }
-
- ///
- ///
- /// Initializes a stream that only allows reading from to of the
- /// specified file, both inclusive.
- ///
- /// A relative or absolute path for the file that the stream will encapsulate.
- /// One of the enumeration values that determines how to open or create the file.
- ///
- /// A bitwise combination of the enumeration values that determines how the file can be accessed by a
- /// object.
- ///
- ///
- /// A bitwise combination of the enumeration values that determines how the file will be shared by
- /// processes.
- ///
- ///
- /// A positive Int32 value greater than 0 indicating the buffer size. The default buffer size is
- /// 4096.
- ///
- /// Start position
- /// Last readable position
- /// Invalid range
- public OffsetStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, long start,
- long end)
- {
- if(start < 0)
- throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number);
-
- if(end < 0)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number);
-
- _streamStart = start;
- _streamEnd = end;
-
- _baseStream = new FileStream(path, mode, access, share, bufferSize);
-
- if(end > _baseStream.Length)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end);
-
- _baseStream.Position = start;
- }
-
- ///
- ///
- /// Initializes a stream that only allows reading from to of the
- /// specified file, both inclusive.
- ///
- /// A relative or absolute path for the file that the stream will encapsulate.
- /// One of the enumeration values that determines how to open or create the file.
- ///
- /// A bitwise combination of the enumeration values that determines how the file can be accessed by a
- /// object.
- ///
- ///
- /// A bitwise combination of the enumeration values that determines how the file will be shared by
- /// processes.
- ///
- /// Start position
- /// Last readable position
- /// Invalid range
- public OffsetStream(string path, FileMode mode, FileAccess access, FileShare share, long start, long end)
- {
- if(start < 0)
- throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number);
-
- if(end < 0)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number);
-
- _streamStart = start;
- _streamEnd = end;
-
- _baseStream = new FileStream(path, mode, access, share);
-
- if(end > _baseStream.Length)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end);
-
- _baseStream.Position = start;
- }
-
- ///
- ///
- /// Initializes a stream that only allows reading from to of the
- /// specified file, both inclusive.
- ///
- /// A relative or absolute path for the file that the stream will encapsulate.
- /// One of the enumeration values that determines how to open or create the file.
- ///
- /// A bitwise combination of the enumeration values that determines how the file can be accessed by a
- /// object.
- ///
- /// Start position
- /// Last readable position
- /// Invalid range
- public OffsetStream(string path, FileMode mode, FileAccess access, long start, long end)
- {
- if(start < 0)
- throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number);
-
- if(end < 0)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number);
-
- _streamStart = start;
- _streamEnd = end;
-
- _baseStream = new FileStream(path, mode, access);
-
- if(end > _baseStream.Length)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end);
-
- _baseStream.Position = start;
- }
-
- ///
- ///
- /// Initializes a stream that only allows reading from to of the
- /// specified file, both inclusive.
- ///
- /// A relative or absolute path for the file that the stream will encapsulate.
- /// One of the enumeration values that determines how to open or create the file.
- /// Start position
- /// Last readable position
- /// Invalid range
- public OffsetStream(string path, FileMode mode, long start, long end)
- {
- if(start < 0)
- throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number);
-
- if(end < 0)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number);
-
- _streamStart = start;
- _streamEnd = end;
-
- _baseStream = new FileStream(path, mode);
-
- if(end > _baseStream.Length)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end);
-
- _baseStream.Position = start;
- }
-
- ///
- ///
- /// Initializes a stream that only allows reading from to of the
- /// specified byte array, both inclusive.
- ///
- /// The array of unsigned bytes to add at the end of this stream.
- /// The index into at which the stream begins.
- /// The length in bytes to add to the end of the current stream.
- /// The setting of the CanWrite property, currently ignored.
- /// Currently ignored.
- /// Start position
- /// Last readable position
- /// Invalid range
- public OffsetStream(byte[] buffer, int index, int count, bool writable, bool publiclyVisible, long start, long end)
- {
- if(start < 0)
- throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number);
-
- if(end < 0)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number);
-
- _streamStart = start;
- _streamEnd = end;
-
- _baseStream = new MemoryStream(buffer, index, count, writable, publiclyVisible);
-
- if(end > _baseStream.Length)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end);
-
- _baseStream.Position = start;
- }
-
- ///
- ///
- /// Initializes a stream that only allows reading from to of the
- /// specified byte array, both inclusive.
- ///
- /// The array of unsigned bytes to add at the end of this stream.
- /// The index into at which the stream begins.
- /// The length in bytes to add to the end of the current stream.
- /// The setting of the CanWrite property, currently ignored.
- /// Start position
- /// Last readable position
- /// Invalid range
- public OffsetStream(byte[] buffer, int index, int count, bool writable, long start, long end)
- {
- if(start < 0)
- throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number);
-
- if(end < 0)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number);
-
- _streamStart = start;
- _streamEnd = end;
-
- _baseStream = new MemoryStream(buffer, index, count, writable);
-
- if(end > _baseStream.Length)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end);
-
- _baseStream.Position = start;
- }
-
- ///
- ///
- /// Initializes a stream that only allows reading from to of the
- /// specified byte array, both inclusive.
- ///
- /// The array of unsigned bytes to add at the end of this stream.
- /// The index into at which the stream begins.
- /// The length in bytes to add to the end of the current stream.
- /// Start position
- /// Last readable position
- /// Invalid range
- public OffsetStream(byte[] buffer, int index, int count, long start, long end)
- {
- if(start < 0)
- throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number);
-
- if(end < 0)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number);
-
- _streamStart = start;
- _streamEnd = end;
-
- _baseStream = new MemoryStream(buffer, index, count);
-
- if(end > _baseStream.Length)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end);
-
- _baseStream.Position = start;
- }
-
- ///
- ///
- /// Initializes a stream that only allows reading from to of the
- /// specified byte array, both inclusive.
- ///
- /// The array of unsigned bytes to add at the end of this stream.
- /// The setting of the CanWrite property, currently ignored.
- /// Start position
- /// Last readable position
- /// Invalid range
- public OffsetStream(byte[] buffer, bool writable, long start, long end)
- {
- if(start < 0)
- throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number);
-
- if(end < 0)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number);
-
- _streamStart = start;
- _streamEnd = end;
-
- _baseStream = new MemoryStream(buffer, writable);
-
- if(end > _baseStream.Length)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end);
-
- _baseStream.Position = start;
- }
-
- ///
- ///
- /// Initializes a stream that only allows reading from to of the
- /// specified byte array, both inclusive.
- ///
- /// The array of unsigned bytes to add at the end of this stream.
- /// Start position
- /// Last readable position
- /// Invalid range
- public OffsetStream(byte[] buffer, long start, long end)
- {
- if(start < 0)
- throw new ArgumentOutOfRangeException(nameof(start), Localization.Start_cant_be_a_negative_number);
-
- if(end < 0)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_cant_be_a_negative_number);
-
- _streamStart = start;
- _streamEnd = end;
-
- _baseStream = new MemoryStream(buffer);
-
- if(end > _baseStream.Length)
- throw new ArgumentOutOfRangeException(nameof(end), Localization.End_is_after_stream_end);
-
- _baseStream.Position = start;
- }
-
- ///
- public override bool CanRead => _baseStream.CanRead;
-
- ///
- public override bool CanSeek => _baseStream.CanSeek;
-
- ///
- public override bool CanWrite => _baseStream.CanWrite;
-
- ///
- public override long Length => _streamEnd - _streamStart + 1;
-
- ///
- public override long Position
- {
- get => _baseStream.Position - _streamStart;
-
- set
- {
- if(value + _streamStart > _streamEnd)
- throw new IOException(Localization.Cannot_set_position_past_stream_end);
-
- _baseStream.Position = value + _streamStart;
- }
- }
-
- ~OffsetStream()
- {
- _baseStream.Close();
- _baseStream.Dispose();
- }
-
- ///
- public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
- {
- if(_baseStream.Position + count > _streamEnd)
- throw new IOException(Localization.Cannot_read_past_stream_end);
-
- return _baseStream.BeginRead(buffer, offset, count, callback, state);
- }
-
- ///
- public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
- {
- if(_baseStream.Position + count > _streamEnd)
- throw new IOException(Localization.Cannot_write_past_stream_end);
-
- return _baseStream.BeginWrite(buffer, offset, count, callback, state);
- }
-
- ///
- public override void Close() => _baseStream.Close();
-
- ///
- public override int EndRead(IAsyncResult asyncResult) => _baseStream.EndRead(asyncResult);
-
- ///
- public override void EndWrite(IAsyncResult asyncResult) => _baseStream.EndWrite(asyncResult);
-
- ///
- public override int ReadByte() => _baseStream.Position == _streamEnd + 1 ? -1 : _baseStream.ReadByte();
-
- ///
- public override void WriteByte(byte value)
- {
- if(_baseStream.Position + 1 > _streamEnd)
- throw new IOException(Localization.Cannot_write_past_stream_end);
-
- _baseStream.WriteByte(value);
- }
-
- ///
- public override void Flush() => _baseStream.Flush();
-
- ///
- public override int Read(byte[] buffer, int offset, int count)
- {
- if(_baseStream.Position + count > _streamEnd + 1)
- throw new IOException(Localization.Cannot_read_past_stream_end);
-
- return _baseStream.EnsureRead(buffer, offset, count);
- }
-
- ///
- public override long Seek(long offset, SeekOrigin origin)
- {
- switch(origin)
- {
- case SeekOrigin.Begin:
- if(offset + _streamStart > _streamEnd)
- throw new IOException(Localization.Cannot_seek_after_stream_end);
-
- return _baseStream.Seek(offset + _streamStart, SeekOrigin.Begin) - _streamStart;
- case SeekOrigin.End:
- if(offset - (_baseStream.Length - _streamEnd) < _streamStart)
- throw new IOException(Localization.Cannot_seek_before_stream_start);
-
- return _baseStream.Seek(offset - (_baseStream.Length - _streamEnd), SeekOrigin.End) - _streamStart;
- default:
- if(offset + _baseStream.Position > _streamEnd)
- throw new IOException(Localization.Cannot_seek_after_stream_end);
-
- return _baseStream.Seek(offset, SeekOrigin.Current) - _streamStart;
- }
- }
-
- ///
- public override void SetLength(long value) =>
- throw new NotSupportedException(Localization.Growing_OffsetStream_is_not_supported);
-
- ///
- public override void Write(byte[] buffer, int offset, int count)
- {
- if(_baseStream.Position + count > _streamEnd)
- throw new IOException(Localization.Cannot_write_past_stream_end);
-
- _baseStream.Write(buffer, offset, count);
- }
-}
\ No newline at end of file
diff --git a/Aaru.Filters/SplitJoinStream.cs b/Aaru.Filters/SplitJoinStream.cs
deleted file mode 100644
index 96a23a0b4..000000000
--- a/Aaru.Filters/SplitJoinStream.cs
+++ /dev/null
@@ -1,382 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Data;
-using System.Diagnostics.CodeAnalysis;
-using System.IO;
-using System.Linq;
-using Aaru.CommonTypes.Interfaces;
-using Microsoft.Win32.SafeHandles;
-
-namespace Aaru.Filters;
-
-///
-/// Implements a stream that joins two or more files (sequentially) as a single stream
-[SuppressMessage("ReSharper", "UnusedMember.Global")]
-public class SplitJoinStream : Stream
-{
- readonly Dictionary _baseStreams;
- long _position;
- long _streamLength;
-
- ///
- public SplitJoinStream()
- {
- _baseStreams = new Dictionary();
- _streamLength = 0;
- _position = 0;
- Filter = new ZZZNoFilter();
- Filter.Open(this);
- }
-
- ///
- public override bool CanRead => true;
-
- ///
- public override bool CanSeek => true;
-
- ///
- public override bool CanWrite => false;
-
- ///
- public override long Length => _streamLength;
-
- ///
- public override long Position
- {
- get => _position;
-
- set
- {
- if(value >= _streamLength)
- throw new IOException(Localization.Cannot_set_position_past_stream_end);
-
- _position = value;
- }
- }
-
- /// Gets a filter from this stream
- public IFilter Filter { get; }
-
- /// Adds a stream at the end of the current stream
- /// Stream to add
- /// The specified stream is non-readable or non-seekable
- public void Add(Stream stream)
- {
- if(!stream.CanSeek)
- throw new ArgumentException(Localization.Non_seekable_streams_are_not_supported);
-
- if(!stream.CanRead)
- throw new ArgumentException(Localization.Non_readable_streams_are_not_supported);
-
- _baseStreams[_streamLength] = stream;
- _streamLength += stream.Length;
- }
-
- /// Adds the specified file to the end of the current stream
- /// A relative or absolute path for the file that the stream will encapsulate.
- /// One of the enumeration values that determines how to open or create the file.
- ///
- /// A bitwise combination of the enumeration values that determines how the file can be accessed by a
- /// object.
- ///
- ///
- /// A bitwise combination of the enumeration values that determines how the file will be shared by
- /// processes.
- ///
- ///
- /// A positive Int32 value greater than 0 indicating the buffer size. The default buffer size is
- /// 4096.
- ///
- /// A bitwise combination of the enumeration values that specifies additional file options.
- public void Add(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize,
- FileOptions options) => Add(new FileStream(path, mode, access, share, bufferSize, options));
-
- /// Adds the specified file to the end of the current stream
- /// A file handle for the file that the stream will encapsulate.
- ///
- /// A bitwise combination of the enumeration values that determines how the file can be accessed by a
- /// object.
- ///
- public void Add(SafeFileHandle handle, FileAccess access) => Add(new FileStream(handle, access));
-
- /// Adds the specified file to the end of the current stream
- /// A file handle for the file that the stream will encapsulate.
- ///
- /// A bitwise combination of the enumeration values that determines how the file can be accessed by a
- /// object.
- ///
- ///
- /// A positive Int32 value greater than 0 indicating the buffer size. The default buffer size is
- /// 4096.
- ///
- public void Add(SafeFileHandle handle, FileAccess access, int bufferSize) =>
- Add(new FileStream(handle, access, bufferSize));
-
- /// Adds the specified file to the end of the current stream
- /// A file handle for the file that the stream will encapsulate.
- ///
- /// A bitwise combination of the enumeration values that determines how the file can be accessed by a
- /// object.
- ///
- ///
- /// A positive Int32 value greater than 0 indicating the buffer size. The default buffer size is
- /// 4096.
- ///
- /// Specifies whether to use asynchronous I/O or synchronous I/O.
- public void Add(SafeFileHandle handle, FileAccess access, int bufferSize, bool isAsync) =>
- Add(new FileStream(handle, access, bufferSize, isAsync));
-
- /// Adds the specified file to the end of the current stream
- /// A relative or absolute path for the file that the stream will encapsulate.
- /// One of the enumeration values that determines how to open or create the file.
- ///
- /// A bitwise combination of the enumeration values that determines how the file can be accessed by a
- /// object.
- ///
- ///
- /// A bitwise combination of the enumeration values that determines how the file will be shared by
- /// processes.
- ///
- ///
- /// A positive Int32 value greater than 0 indicating the buffer size. The default buffer size is
- /// 4096.
- ///
- /// Specifies whether to use asynchronous I/O or synchronous I/O.
- public void Add(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, bool useAsync) =>
- Add(new FileStream(path, mode, access, share, bufferSize, useAsync));
-
- /// Adds the specified file to the end of the current stream
- /// A relative or absolute path for the file that the stream will encapsulate.
- /// One of the enumeration values that determines how to open or create the file.
- ///
- /// A bitwise combination of the enumeration values that determines how the file can be accessed by a
- /// object.
- ///
- ///
- /// A bitwise combination of the enumeration values that determines how the file will be shared by
- /// processes.
- ///
- ///
- /// A positive Int32 value greater than 0 indicating the buffer size. The default buffer size is
- /// 4096.
- ///
- public void Add(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize) =>
- Add(new FileStream(path, mode, access, share, bufferSize));
-
- /// Adds the specified file to the end of the current stream
- /// A relative or absolute path for the file that the stream will encapsulate.
- /// One of the enumeration values that determines how to open or create the file.
- ///
- /// A bitwise combination of the enumeration values that determines how the file can be accessed by a
- /// object.
- ///
- ///
- /// A bitwise combination of the enumeration values that determines how the file will be shared by
- /// processes.
- ///
- public void Add(string path, FileMode mode, FileAccess access, FileShare share) =>
- Add(new FileStream(path, mode, access, share));
-
- /// Adds the specified file to the end of the current stream
- /// A relative or absolute path for the file that the stream will encapsulate.
- /// One of the enumeration values that determines how to open or create the file.
- ///
- /// A bitwise combination of the enumeration values that determines how the file can be accessed by a
- /// object.
- ///
- public void Add(string path, FileMode mode, FileAccess access) => Add(new FileStream(path, mode, access));
-
- /// Adds the specified file to the end of the current stream
- /// A relative or absolute path for the file that the stream will encapsulate.
- /// One of the enumeration values that determines how to open or create the file.
- public void Add(string path, FileMode mode) => Add(new FileStream(path, mode));
-
- /// Adds the specified byte array to the end of the current stream
- /// The array of unsigned bytes to add at the end of this stream.
- /// The index into at which the stream begins.
- /// The length in bytes to add to the end of the current stream.
- /// The setting of the CanWrite property, currently ignored.
- /// Currently ignored.
- public void Add(byte[] buffer, int index, int count, bool writable, bool publiclyVisible) =>
- Add(new MemoryStream(buffer, index, count, writable, publiclyVisible));
-
- /// Adds the specified byte array to the end of the current stream
- /// The array of unsigned bytes to add at the end of this stream.
- /// The index into at which the stream begins.
- /// The length in bytes to add to the end of the current stream.
- /// The setting of the CanWrite property, currently ignored.
- public void Add(byte[] buffer, int index, int count, bool writable) =>
- Add(new MemoryStream(buffer, index, count, writable));
-
- /// Adds the specified byte array to the end of the current stream
- /// The array of unsigned bytes to add at the end of this stream.
- /// The index into at which the stream begins.
- /// The length in bytes to add to the end of the current stream.
- public void Add(byte[] buffer, int index, int count) => Add(new MemoryStream(buffer, index, count));
-
- /// Adds the specified byte array to the end of the current stream
- /// The array of unsigned bytes to add at the end of this stream.
- /// The setting of the CanWrite property, currently ignored.
- public void Add(byte[] buffer, bool writable) => Add(new MemoryStream(buffer, writable));
-
- /// Adds the specified byte array to the end of the current stream
- /// The array of unsigned bytes to add at the end of this stream.
- public void Add(byte[] buffer) => Add(new MemoryStream(buffer));
-
- /// Adds the data fork of the specified filter to the end of the current stream
- /// Filter
- public void Add(IFilter filter) => Add(filter.GetDataForkStream());
-
- /// Adds a range of files to the end of the current stream, alphabetically sorted
- /// Base file path, directory path only
- /// Counter format, includes filename and a formatting string
- /// Counter start, defaults to 0
- ///
- /// A bitwise combination of the enumeration values that determines how the file can be accessed by a
- /// object.
- ///
- public void AddRange(string basePath, string counterFormat = "{0:D3}", int counterStart = 0,
- FileAccess access = FileAccess.Read)
- {
- while(true)
- {
- string filePath = Path.Combine(basePath, string.Format(counterFormat, counterStart));
-
- if(!File.Exists(filePath))
- break;
-
- Add(filePath, FileMode.Open, access);
-
- counterStart++;
- }
- }
-
- ~SplitJoinStream()
- {
- foreach(Stream stream in _baseStreams.Values)
- {
- stream.Close();
- stream.Dispose();
- }
-
- _baseStreams.Clear();
- _position = 0;
- }
-
- ///
- public override IAsyncResult
- BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) =>
- throw new NotSupportedException(Localization.Asynchronous_IO_is_not_supported);
-
- ///
- public override IAsyncResult
- BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) =>
- throw new NotSupportedException(Localization.Asynchronous_IO_is_not_supported);
-
- ///
- public override void Close()
- {
- foreach(Stream stream in _baseStreams.Values)
- stream.Close();
-
- _baseStreams.Clear();
- _position = 0;
- }
-
- ///
- public override int EndRead(IAsyncResult asyncResult) =>
- throw new NotSupportedException(Localization.Asynchronous_IO_is_not_supported);
-
- ///
- public override void EndWrite(IAsyncResult asyncResult) =>
- throw new NotSupportedException(Localization.Asynchronous_IO_is_not_supported);
-
- ///
- public override int ReadByte()
- {
- if(_position >= _streamLength)
- return -1;
-
- KeyValuePair baseStream = _baseStreams.FirstOrDefault(s => s.Key >= _position);
-
- if(baseStream.Value == null)
- return -1;
-
- baseStream.Value.Position = _position - baseStream.Key;
- _position++;
-
- return baseStream.Value.ReadByte();
- }
-
- ///
- public override void WriteByte(byte value) => throw new ReadOnlyException(Localization.This_stream_is_read_only);
-
- ///
- public override void Flush() {}
-
- ///
- public override int Read(byte[] buffer, int offset, int count)
- {
- var read = 0;
-
- while(count > 0)
- {
- KeyValuePair baseStream = _baseStreams.LastOrDefault(s => s.Key <= _position);
-
- if(baseStream.Value == null)
- break;
-
- baseStream.Value.Position = _position - baseStream.Key;
-
- int currentCount = count;
-
- if(baseStream.Value.Position + currentCount > baseStream.Value.Length)
- currentCount = (int)(baseStream.Value.Length - baseStream.Value.Position);
-
- read += baseStream.Value.Read(buffer, offset, currentCount);
-
- count -= currentCount;
- offset += currentCount;
- }
-
- return read;
- }
-
- ///
- public override long Seek(long offset, SeekOrigin origin)
- {
- switch(origin)
- {
- case SeekOrigin.Begin:
- if(offset >= _streamLength)
- throw new IOException(Localization.Cannot_seek_after_stream_end);
-
- _position = offset;
-
- break;
- case SeekOrigin.End:
- if(_position - offset < 0)
- throw new IOException(Localization.Cannot_seek_before_stream_start);
-
- _position -= offset;
-
- break;
- default:
- if(_position + offset >= _streamLength)
- throw new IOException(Localization.Cannot_seek_after_stream_end);
-
- _position += offset;
-
- break;
- }
-
- return _position;
- }
-
- ///
- public override void SetLength(long value) => throw new ReadOnlyException(Localization.This_stream_is_read_only);
-
- ///
- public override void Write(byte[] buffer, int offset, int count) =>
- throw new ReadOnlyException(Localization.This_stream_is_read_only);
-}
\ No newline at end of file
diff --git a/Aaru.Filters/XZ.cs b/Aaru.Filters/XZ.cs
index 04c92781a..b638cea27 100644
--- a/Aaru.Filters/XZ.cs
+++ b/Aaru.Filters/XZ.cs
@@ -35,6 +35,7 @@ using System.IO;
using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Interfaces;
using Aaru.Helpers;
+using Aaru.Helpers.IO;
using SharpCompress.Compressors.Xz;
namespace Aaru.Filters;
diff --git a/Aaru.Helpers b/Aaru.Helpers
index a03ee5efe..0a5ccd5a9 160000
--- a/Aaru.Helpers
+++ b/Aaru.Helpers
@@ -1 +1 @@
-Subproject commit a03ee5efee746bfd60689fa28da759aabe14ba06
+Subproject commit 0a5ccd5a9a3a4963589e2cc9e444a0a0ac01cba2
diff --git a/Aaru.Images/BlindWrite5/Read.cs b/Aaru.Images/BlindWrite5/Read.cs
index c8de0290f..81a46a66f 100644
--- a/Aaru.Images/BlindWrite5/Read.cs
+++ b/Aaru.Images/BlindWrite5/Read.cs
@@ -48,6 +48,7 @@ using Aaru.Decoders.SCSI;
using Aaru.Decoders.SCSI.MMC;
using Aaru.Filters;
using Aaru.Helpers;
+using Aaru.Helpers.IO;
using DMI = Aaru.Decoders.Xbox.DMI;
using Sector = Aaru.Decoders.CD.Sector;
using Session = Aaru.CommonTypes.Structs.Session;
@@ -980,8 +981,9 @@ public sealed partial class BlindWrite5
return ErrorNumber.NoSuchFile;
}
- track.Filter = splitStream.Filter;
- track.File = $"{filename}.{extension}";
+ track.Filter = new ZZZNoFilter();
+ track.Filter.Open(splitStream);
+ track.File = $"{filename}.{extension}";
if(trk.startLba >= 0)
track.FileOffset = (ulong)(trk.startLba * splitStartChars.SectorSize + splitStartChars.Offset);
@@ -1001,9 +1003,10 @@ public sealed partial class BlindWrite5
_imageInfo.ReadableSectorTags.Add(SectorTagType.CdSectorSubchannel);
}
- splitStartChars.FileFilter = splitStream.Filter;
- splitStartChars.Sectors = trk.sectors;
- splitStartChars.StartLba = trk.startLba;
+ splitStartChars.FileFilter = new ZZZNoFilter();
+ splitStartChars.FileFilter.Open(splitStream);
+ splitStartChars.Sectors = trk.sectors;
+ splitStartChars.StartLba = trk.startLba;
_filePaths.Clear();
_filePaths.Add(splitStartChars);
}