mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-09-23 07:25:11 +00:00
Merge pull request #1224 from adamhathcock/adam/conslidate-exceptions
Use more SharpCompress exceptions instead of generic ones
This commit is contained in:
@@ -62,7 +62,7 @@ public static partial class ArchiveFactory
|
||||
var filesArray = fileInfos.ToArray();
|
||||
if (filesArray.Length == 0)
|
||||
{
|
||||
throw new InvalidOperationException("No files to open");
|
||||
throw new ArchiveOperationException("No files to open");
|
||||
}
|
||||
|
||||
var fileInfo = filesArray[0];
|
||||
@@ -91,7 +91,7 @@ public static partial class ArchiveFactory
|
||||
var streamsArray = streams.ToArray();
|
||||
if (streamsArray.Length == 0)
|
||||
{
|
||||
throw new InvalidOperationException("No streams");
|
||||
throw new ArchiveOperationException("No streams");
|
||||
}
|
||||
|
||||
var firstStream = streamsArray[0];
|
||||
@@ -164,7 +164,7 @@ public static partial class ArchiveFactory
|
||||
|
||||
var extensions = string.Join(", ", factories.Select(item => item.Name));
|
||||
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
$"Cannot determine compressed stream type. Supported Archive Formats: {extensions}"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public static partial class ArchiveFactory
|
||||
var filesArray = fileInfos.ToArray();
|
||||
if (filesArray.Length == 0)
|
||||
{
|
||||
throw new InvalidOperationException("No files to open");
|
||||
throw new ArchiveOperationException("No files to open");
|
||||
}
|
||||
|
||||
var fileInfo = filesArray[0];
|
||||
@@ -75,7 +75,7 @@ public static partial class ArchiveFactory
|
||||
var streamsArray = streams.ToArray();
|
||||
if (streamsArray.Length == 0)
|
||||
{
|
||||
throw new InvalidOperationException("No streams");
|
||||
throw new ArchiveOperationException("No streams");
|
||||
}
|
||||
|
||||
var firstStream = streamsArray[0];
|
||||
@@ -143,7 +143,7 @@ public static partial class ArchiveFactory
|
||||
|
||||
var extensions = string.Join(", ", factories.Select(item => item.Name));
|
||||
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
$"Cannot determine compressed stream type. Supported Archive Formats: {extensions}"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Archives;
|
||||
|
||||
@@ -20,7 +21,7 @@ internal abstract class ArchiveVolumeFactory
|
||||
String.Concat(
|
||||
m.Groups[1].Value,
|
||||
(index + 1)
|
||||
.ToString(global::SharpCompress.Common.Constants.DefaultCultureInfo)
|
||||
.ToString(Constants.DefaultCultureInfo)
|
||||
.PadLeft(m.Groups[2].Value.Length, '0')
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Archives.Rar;
|
||||
|
||||
@@ -20,7 +21,7 @@ internal static class RarArchiveVolumeFactory
|
||||
String.Concat(
|
||||
m.Groups[1].Value,
|
||||
(index + 1)
|
||||
.ToString(global::SharpCompress.Common.Constants.DefaultCultureInfo)
|
||||
.ToString(Constants.DefaultCultureInfo)
|
||||
.PadLeft(m.Groups[2].Value.Length, '0'),
|
||||
m.Groups[3].Value
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Archives.Zip;
|
||||
|
||||
@@ -21,9 +22,7 @@ internal static class ZipArchiveVolumeFactory
|
||||
String.Concat(
|
||||
m.Groups[1].Value,
|
||||
Regex.Replace(m.Groups[2].Value, @"[^xz]", ""),
|
||||
index
|
||||
.ToString(global::SharpCompress.Common.Constants.DefaultCultureInfo)
|
||||
.PadLeft(2, '0')
|
||||
index.ToString(Constants.DefaultCultureInfo).PadLeft(2, '0')
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
@@ -48,7 +48,7 @@ public abstract partial class AceHeader
|
||||
var checksum = AceCrc.AceCrc16(body);
|
||||
if (checksum != HeaderCrc)
|
||||
{
|
||||
throw new InvalidDataException("Header checksum is invalid");
|
||||
throw new InvalidFormatException("Header checksum is invalid");
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ public abstract partial class AceHeader
|
||||
var checksum = AceCrc.AceCrc16(body);
|
||||
if (checksum != HeaderCrc)
|
||||
{
|
||||
throw new InvalidDataException("Header checksum is invalid");
|
||||
throw new InvalidFormatException("Header checksum is invalid");
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public sealed partial class AceMainHeader
|
||||
// Skip signature "**ACE**" (7 bytes)
|
||||
if (!CheckMagicBytes(headerData, offset))
|
||||
{
|
||||
throw new InvalidDataException("Invalid ACE archive signature.");
|
||||
throw new InvalidFormatException("Invalid ACE archive signature.");
|
||||
}
|
||||
offset += 7;
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ public sealed partial class AceMainHeader : AceHeader
|
||||
// Skip signature "**ACE**" (7 bytes)
|
||||
if (!CheckMagicBytes(headerData, offset))
|
||||
{
|
||||
throw new InvalidDataException("Invalid ACE archive signature.");
|
||||
throw new InvalidFormatException("Invalid ACE archive signature.");
|
||||
}
|
||||
offset += 7;
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public abstract partial class ArjHeader
|
||||
|
||||
if (!CheckMagicBytes(magic))
|
||||
{
|
||||
throw new InvalidDataException("Not an ARJ file (wrong magic bytes)");
|
||||
throw new InvalidFormatException("Not an ARJ file (wrong magic bytes)");
|
||||
}
|
||||
|
||||
// read header_size
|
||||
@@ -55,7 +55,7 @@ public abstract partial class ArjHeader
|
||||
// Compute the hash value
|
||||
if (checksum != BitConverter.ToUInt32(crc, 0))
|
||||
{
|
||||
throw new InvalidDataException("Header checksum is invalid");
|
||||
throw new InvalidFormatException("Header checksum is invalid");
|
||||
}
|
||||
return body;
|
||||
}
|
||||
@@ -75,7 +75,7 @@ public abstract partial class ArjHeader
|
||||
.ConfigureAwait(false);
|
||||
if (bytesRead < 2)
|
||||
{
|
||||
throw new EndOfStreamException(
|
||||
throw new IncompleteArchiveException(
|
||||
"Unexpected end of stream while reading extended header size."
|
||||
);
|
||||
}
|
||||
@@ -92,7 +92,7 @@ public abstract partial class ArjHeader
|
||||
.ConfigureAwait(false);
|
||||
if (bytesRead < extHeaderSize)
|
||||
{
|
||||
throw new EndOfStreamException(
|
||||
throw new IncompleteArchiveException(
|
||||
"Unexpected end of stream while reading extended header data."
|
||||
);
|
||||
}
|
||||
@@ -103,7 +103,7 @@ public abstract partial class ArjHeader
|
||||
.ConfigureAwait(false);
|
||||
if (bytesRead < 4)
|
||||
{
|
||||
throw new EndOfStreamException(
|
||||
throw new IncompleteArchiveException(
|
||||
"Unexpected end of stream while reading extended header CRC."
|
||||
);
|
||||
}
|
||||
@@ -111,7 +111,7 @@ public abstract partial class ArjHeader
|
||||
var checksum = Crc32Stream.Compute(header);
|
||||
if (checksum != BitConverter.ToUInt32(crcextended, 0))
|
||||
{
|
||||
throw new InvalidDataException("Extended header checksum is invalid");
|
||||
throw new InvalidFormatException("Extended header checksum is invalid");
|
||||
}
|
||||
|
||||
extendedHeader.Add(header);
|
||||
|
||||
@@ -44,7 +44,7 @@ public abstract partial class ArjHeader
|
||||
|
||||
if (!CheckMagicBytes(magic))
|
||||
{
|
||||
throw new InvalidDataException("Not an ARJ file (wrong magic bytes)");
|
||||
throw new InvalidFormatException("Not an ARJ file (wrong magic bytes)");
|
||||
}
|
||||
|
||||
// read header_size
|
||||
@@ -69,7 +69,7 @@ public abstract partial class ArjHeader
|
||||
// Compute the hash value
|
||||
if (checksum != BitConverter.ToUInt32(crc, 0))
|
||||
{
|
||||
throw new InvalidDataException("Header checksum is invalid");
|
||||
throw new InvalidFormatException("Header checksum is invalid");
|
||||
}
|
||||
return body;
|
||||
}
|
||||
@@ -86,7 +86,7 @@ public abstract partial class ArjHeader
|
||||
int bytesRead = reader.Read(buffer, 0, 2);
|
||||
if (bytesRead < 2)
|
||||
{
|
||||
throw new EndOfStreamException(
|
||||
throw new IncompleteArchiveException(
|
||||
"Unexpected end of stream while reading extended header size."
|
||||
);
|
||||
}
|
||||
@@ -101,7 +101,7 @@ public abstract partial class ArjHeader
|
||||
bytesRead = reader.Read(header, 0, extHeaderSize);
|
||||
if (bytesRead < extHeaderSize)
|
||||
{
|
||||
throw new EndOfStreamException(
|
||||
throw new IncompleteArchiveException(
|
||||
"Unexpected end of stream while reading extended header data."
|
||||
);
|
||||
}
|
||||
@@ -110,7 +110,7 @@ public abstract partial class ArjHeader
|
||||
bytesRead = reader.Read(crc, 0, 4);
|
||||
if (bytesRead < 4)
|
||||
{
|
||||
throw new EndOfStreamException(
|
||||
throw new IncompleteArchiveException(
|
||||
"Unexpected end of stream while reading extended header CRC."
|
||||
);
|
||||
}
|
||||
@@ -118,7 +118,7 @@ public abstract partial class ArjHeader
|
||||
var checksum = Crc32Stream.Compute(header);
|
||||
if (checksum != BitConverter.ToUInt32(crc, 0))
|
||||
{
|
||||
throw new InvalidDataException("Extended header checksum is invalid");
|
||||
throw new InvalidFormatException("Extended header checksum is invalid");
|
||||
}
|
||||
|
||||
extendedHeader.Add(header);
|
||||
|
||||
@@ -66,7 +66,7 @@ public partial class ArjLocalHeader : ArjHeader
|
||||
{
|
||||
if (offset + 1 >= headerBytes.Length)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
var v = headerBytes[offset] & 0xFF | (headerBytes[offset + 1] & 0xFF) << 8;
|
||||
offset += 2;
|
||||
@@ -76,7 +76,7 @@ public partial class ArjLocalHeader : ArjHeader
|
||||
{
|
||||
if (offset + 3 >= headerBytes.Length)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
long v =
|
||||
headerBytes[offset] & 0xFF
|
||||
|
||||
@@ -54,7 +54,7 @@ public partial class ArjMainHeader : ArjHeader
|
||||
{
|
||||
if (offset >= headerBytes.Length)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
return (byte)(headerBytes[offset++] & 0xFF);
|
||||
}
|
||||
@@ -63,7 +63,7 @@ public partial class ArjMainHeader : ArjHeader
|
||||
{
|
||||
if (offset + 1 >= headerBytes.Length)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
var v = headerBytes[offset] & 0xFF | (headerBytes[offset + 1] & 0xFF) << 8;
|
||||
offset += 2;
|
||||
@@ -74,7 +74,7 @@ public partial class ArjMainHeader : ArjHeader
|
||||
{
|
||||
if (offset + 3 >= headerBytes.Length)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
long v =
|
||||
headerBytes[offset] & 0xFF
|
||||
|
||||
@@ -124,7 +124,7 @@ internal class AsyncMarkingBinaryReader : IDisposable
|
||||
shift += 7;
|
||||
} while (shift <= maxShift);
|
||||
|
||||
throw new FormatException("malformed vint");
|
||||
throw new InvalidFormatException("malformed vint");
|
||||
}
|
||||
|
||||
public async ValueTask<uint> ReadRarVIntUInt32Async(
|
||||
@@ -188,7 +188,7 @@ internal class AsyncMarkingBinaryReader : IDisposable
|
||||
shift += 7;
|
||||
} while (shift <= maxShift);
|
||||
|
||||
throw new FormatException("malformed vint");
|
||||
throw new InvalidFormatException("malformed vint");
|
||||
}
|
||||
|
||||
public virtual void Dispose() => _reader.Dispose();
|
||||
|
||||
@@ -20,7 +20,7 @@ internal partial class MarkHeader
|
||||
{
|
||||
return buffer[0];
|
||||
}
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
|
||||
public static async ValueTask<MarkHeader> ReadAsync(
|
||||
|
||||
@@ -24,7 +24,7 @@ internal partial class MarkHeader : IRarHeader
|
||||
{
|
||||
return (byte)b;
|
||||
}
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
|
||||
public static MarkHeader Read(Stream stream, bool leaveStreamOpen, bool lookForHeader)
|
||||
|
||||
@@ -76,7 +76,7 @@ public abstract class RarEntry : Entry
|
||||
|
||||
public override string ToString() =>
|
||||
string.Format(
|
||||
global::SharpCompress.Common.Constants.DefaultCultureInfo,
|
||||
Constants.DefaultCultureInfo,
|
||||
"Entry Path: {0} Compressed Size: {1} Uncompressed Size: {2} CRC: {3}",
|
||||
Key,
|
||||
CompressedSize,
|
||||
|
||||
@@ -134,7 +134,7 @@ public abstract class RarVolume : Volume
|
||||
{
|
||||
if (Mode == StreamingMode.Streaming)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
"ArchiveHeader should never been null in a streaming read."
|
||||
);
|
||||
}
|
||||
@@ -243,7 +243,7 @@ public abstract class RarVolume : Volume
|
||||
{
|
||||
if (Mode == StreamingMode.Streaming)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
"ArchiveHeader should never been null in a streaming read."
|
||||
);
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ internal partial class ArchiveDatabase
|
||||
{
|
||||
if (folderIndex >= _folders.Count)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
|
||||
_folderStartFileIndex.Add(i); // check it
|
||||
|
||||
@@ -66,7 +66,7 @@ internal sealed partial class ArchiveReader
|
||||
|
||||
if (db._majorVersion != 0)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
|
||||
var crcFromArchive = DataReader.Get32(_header, 8);
|
||||
@@ -82,7 +82,7 @@ internal sealed partial class ArchiveReader
|
||||
|
||||
if (crc != crcFromArchive)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
|
||||
db._startPositionAfterHeader = _streamOrigin + 0x20;
|
||||
@@ -96,12 +96,12 @@ internal sealed partial class ArchiveReader
|
||||
|
||||
if (nextHeaderOffset < 0 || nextHeaderSize < 0 || nextHeaderSize > int.MaxValue)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
|
||||
if (nextHeaderOffset > _streamEnding - db._startPositionAfterHeader)
|
||||
{
|
||||
throw new InvalidOperationException("nextHeaderOffset is invalid");
|
||||
throw new ArchiveOperationException("nextHeaderOffset is invalid");
|
||||
}
|
||||
|
||||
_stream.Seek(nextHeaderOffset, SeekOrigin.Current);
|
||||
@@ -113,7 +113,7 @@ internal sealed partial class ArchiveReader
|
||||
|
||||
if (Crc.Finish(Crc.Update(Crc.INIT_CRC, header, 0, header.Length)) != nextHeaderCrc)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
|
||||
using (var streamSwitch = new CStreamSwitch())
|
||||
@@ -125,7 +125,7 @@ internal sealed partial class ArchiveReader
|
||||
{
|
||||
if (type != BlockType.EncodedHeader)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
|
||||
var dataVector = await ReadAndDecodePackedStreamsAsync(
|
||||
@@ -144,14 +144,14 @@ internal sealed partial class ArchiveReader
|
||||
|
||||
if (dataVector.Count != 1)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
|
||||
streamSwitch.Set(this, dataVector[0]);
|
||||
|
||||
if (ReadId() != BlockType.Header)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,7 +305,7 @@ internal sealed partial class ArchiveReader
|
||||
|
||||
if (type != BlockType.FilesInfo)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
|
||||
var numFiles = ReadNum();
|
||||
@@ -424,7 +424,7 @@ internal sealed partial class ArchiveReader
|
||||
{
|
||||
if (ReadByte() != 0)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -436,7 +436,7 @@ internal sealed partial class ArchiveReader
|
||||
var checkRecordsSize = (db._majorVersion > 0 || db._minorVersion > 2);
|
||||
if (checkRecordsSize && _currentReader.Offset - oldPos != size)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ internal partial class ArchiveReader
|
||||
}
|
||||
if (type == BlockType.End)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
SkipData();
|
||||
}
|
||||
@@ -749,7 +749,7 @@ internal partial class ArchiveReader
|
||||
|
||||
if (type != BlockType.FilesInfo)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
|
||||
var numFiles = ReadNum();
|
||||
@@ -888,7 +888,7 @@ internal partial class ArchiveReader
|
||||
{
|
||||
if (ReadByte() != 0)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -901,7 +901,7 @@ internal partial class ArchiveReader
|
||||
var checkRecordsSize = (db._majorVersion > 0 || db._minorVersion > 2);
|
||||
if (checkRecordsSize && _currentReader.Offset - oldPos != size)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -953,7 +953,7 @@ internal partial class ArchiveReader
|
||||
var delta = stream.Read(_header, offset, 0x20 - offset);
|
||||
if (delta == 0)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
|
||||
offset += delta;
|
||||
@@ -1005,7 +1005,7 @@ internal partial class ArchiveReader
|
||||
|
||||
if (db._majorVersion != 0)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
|
||||
var crcFromArchive = DataReader.Get32(_header, 8);
|
||||
@@ -1021,7 +1021,7 @@ internal partial class ArchiveReader
|
||||
|
||||
if (crc != crcFromArchive)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
|
||||
db._startPositionAfterHeader = _streamOrigin + 0x20;
|
||||
@@ -1035,12 +1035,12 @@ internal partial class ArchiveReader
|
||||
|
||||
if (nextHeaderOffset < 0 || nextHeaderSize < 0 || nextHeaderSize > int.MaxValue)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
|
||||
if (nextHeaderOffset > _streamEnding - db._startPositionAfterHeader)
|
||||
{
|
||||
throw new InvalidOperationException("nextHeaderOffset is invalid");
|
||||
throw new ArchiveOperationException("nextHeaderOffset is invalid");
|
||||
}
|
||||
|
||||
_stream.Seek(nextHeaderOffset, SeekOrigin.Current);
|
||||
@@ -1050,7 +1050,7 @@ internal partial class ArchiveReader
|
||||
|
||||
if (Crc.Finish(Crc.Update(Crc.INIT_CRC, header, 0, header.Length)) != nextHeaderCrc)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
|
||||
using (var streamSwitch = new CStreamSwitch())
|
||||
@@ -1062,7 +1062,7 @@ internal partial class ArchiveReader
|
||||
{
|
||||
if (type != BlockType.EncodedHeader)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
|
||||
var dataVector = ReadAndDecodePackedStreams(
|
||||
@@ -1079,14 +1079,14 @@ internal partial class ArchiveReader
|
||||
|
||||
if (dataVector.Count != 1)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
|
||||
streamSwitch.Set(this, dataVector[0]);
|
||||
|
||||
if (ReadId() != BlockType.Header)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1260,7 +1260,7 @@ internal partial class ArchiveReader
|
||||
var firstFileIndex = db._folderStartFileIndex[folderIndex];
|
||||
if (firstFileIndex > fileIndex || fileIndex - firstFileIndex >= numFilesInFolder)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
|
||||
var skipCount = fileIndex - firstFileIndex;
|
||||
|
||||
@@ -30,7 +30,7 @@ internal class CFolder
|
||||
}
|
||||
}
|
||||
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
|
||||
public int GetNumOutStreams()
|
||||
|
||||
@@ -44,7 +44,7 @@ internal struct CStreamSwitch : IDisposable
|
||||
var dataIndex = archive.ReadNum();
|
||||
if (dataIndex < 0 || dataIndex >= dataVector.Count)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
|
||||
_archive = archive;
|
||||
|
||||
@@ -49,7 +49,7 @@ internal class DataReader
|
||||
{
|
||||
if (Offset >= _ending)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
|
||||
return _buffer[Offset++];
|
||||
@@ -59,7 +59,7 @@ internal class DataReader
|
||||
{
|
||||
if (length > _ending - Offset)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
|
||||
while (length-- > 0)
|
||||
@@ -72,7 +72,7 @@ internal class DataReader
|
||||
{
|
||||
if (size > _ending - Offset)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
|
||||
Offset += (int)size;
|
||||
@@ -84,7 +84,7 @@ internal class DataReader
|
||||
{
|
||||
if (Offset >= _ending)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
|
||||
var firstByte = _buffer[Offset++];
|
||||
@@ -102,7 +102,7 @@ internal class DataReader
|
||||
|
||||
if (Offset >= _ending)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
|
||||
value |= (ulong)_buffer[Offset++] << (8 * i);
|
||||
@@ -127,7 +127,7 @@ internal class DataReader
|
||||
{
|
||||
if (Offset + 4 > _ending)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
|
||||
var res = Get32(_buffer, Offset);
|
||||
@@ -139,7 +139,7 @@ internal class DataReader
|
||||
{
|
||||
if (Offset + 8 > _ending)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
|
||||
var res = Get64(_buffer, Offset);
|
||||
@@ -155,7 +155,7 @@ internal class DataReader
|
||||
{
|
||||
if (ending + 2 > _ending)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
|
||||
if (_buffer[ending] == 0 && _buffer[ending + 1] == 0)
|
||||
|
||||
@@ -15,6 +15,17 @@ public class SharpCompressException : Exception
|
||||
|
||||
public class ArchiveException(string message) : SharpCompressException(message);
|
||||
|
||||
public class ArchiveOperationException : SharpCompressException
|
||||
{
|
||||
public ArchiveOperationException() { }
|
||||
|
||||
public ArchiveOperationException(string message)
|
||||
: base(message) { }
|
||||
|
||||
public ArchiveOperationException(string message, Exception inner)
|
||||
: base(message, inner) { }
|
||||
}
|
||||
|
||||
public class IncompleteArchiveException(string message) : ArchiveException(message);
|
||||
|
||||
public class CryptographicException(string message) : SharpCompressException(message);
|
||||
|
||||
@@ -27,7 +27,7 @@ internal sealed partial class TarHeader
|
||||
await WriteUstarAsync(output, cancellationToken).ConfigureAwait(false);
|
||||
break;
|
||||
default:
|
||||
throw new InvalidOperationException("This should be impossible...");
|
||||
throw new ArchiveOperationException("This should be impossible...");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ internal sealed partial class TarHeader
|
||||
|
||||
if (splitIndex == -1)
|
||||
{
|
||||
throw new InvalidDataException(
|
||||
throw new InvalidFormatException(
|
||||
$"Tar header USTAR format can not fit file name \"{fullName}\" of length {nameByteCount}! Directory separator not found! Try using GNU Tar format instead!"
|
||||
);
|
||||
}
|
||||
@@ -90,14 +90,14 @@ internal sealed partial class TarHeader
|
||||
|
||||
if (this.ArchiveEncoding.GetEncoding().GetByteCount(namePrefix) >= 155)
|
||||
{
|
||||
throw new InvalidDataException(
|
||||
throw new InvalidFormatException(
|
||||
$"Tar header USTAR format can not fit file name \"{fullName}\" of length {nameByteCount}! Try using GNU Tar format instead!"
|
||||
);
|
||||
}
|
||||
|
||||
if (this.ArchiveEncoding.GetEncoding().GetByteCount(name) >= 100)
|
||||
{
|
||||
throw new InvalidDataException(
|
||||
throw new InvalidFormatException(
|
||||
$"Tar header USTAR format can not fit file name \"{fullName}\" of length {nameByteCount}! Try using GNU Tar format instead!"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ internal sealed partial class TarHeader
|
||||
WriteUstar(output);
|
||||
break;
|
||||
default:
|
||||
throw new InvalidOperationException("This should be impossible...");
|
||||
throw new ArchiveOperationException("This should be impossible...");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ internal sealed partial class TarHeader
|
||||
|
||||
if (splitIndex == -1)
|
||||
{
|
||||
throw new InvalidDataException(
|
||||
throw new InvalidFormatException(
|
||||
$"Tar header USTAR format can not fit file name \"{fullName}\" of length {nameByteCount}! Directory separator not found! Try using GNU Tar format instead!"
|
||||
);
|
||||
}
|
||||
@@ -120,14 +120,14 @@ internal sealed partial class TarHeader
|
||||
|
||||
if (this.ArchiveEncoding.GetEncoding().GetByteCount(namePrefix) >= 155)
|
||||
{
|
||||
throw new InvalidDataException(
|
||||
throw new InvalidFormatException(
|
||||
$"Tar header USTAR format can not fit file name \"{fullName}\" of length {nameByteCount}! Try using GNU Tar format instead!"
|
||||
);
|
||||
}
|
||||
|
||||
if (this.ArchiveEncoding.GetEncoding().GetByteCount(name) >= 100)
|
||||
{
|
||||
throw new InvalidDataException(
|
||||
throw new InvalidFormatException(
|
||||
$"Tar header USTAR format can not fit file name \"{fullName}\" of length {nameByteCount}! Try using GNU Tar format instead!"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ internal sealed partial class SeekableZipHeaderFactory
|
||||
is not LocalEntryHeader localEntryHeader
|
||||
)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
|
||||
// populate fields only known from the DirectoryEntryHeader
|
||||
|
||||
@@ -148,7 +148,7 @@ internal sealed partial class SeekableZipHeaderFactory : ZipHeaderFactory
|
||||
var signature = reader.ReadUInt32();
|
||||
if (ReadHeader(signature, reader, _zip64) is not LocalEntryHeader localEntryHeader)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
|
||||
// populate fields only known from the DirectoryEntryHeader
|
||||
|
||||
@@ -82,7 +82,7 @@ internal sealed partial class StreamingZipHeaderFactory
|
||||
private ZipHeader? _current;
|
||||
|
||||
public ZipHeader Current =>
|
||||
_current ?? throw new InvalidOperationException("No current header is available.");
|
||||
_current ?? throw new ArchiveOperationException("No current header is available.");
|
||||
|
||||
/// <summary>
|
||||
/// Advances to the next ZIP header in the stream, honoring streaming data descriptors where applicable.
|
||||
|
||||
@@ -99,7 +99,7 @@ internal partial class WinzipAesCryptoStream
|
||||
{
|
||||
if (_isFinalBlock)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
|
||||
var bytesRemaining = last - offset;
|
||||
|
||||
@@ -127,7 +127,7 @@ internal partial class WinzipAesCryptoStream : Stream
|
||||
{
|
||||
if (_isFinalBlock)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
|
||||
var bytesRemaining = last - offset;
|
||||
|
||||
@@ -76,6 +76,6 @@ internal class WinzipAesEncryptionData
|
||||
WinzipAesKeySize.KeySize128 => 16,
|
||||
WinzipAesKeySize.KeySize192 => 24,
|
||||
WinzipAesKeySize.KeySize256 => 32,
|
||||
_ => throw new InvalidOperationException(),
|
||||
_ => throw new ArchiveOperationException(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ internal abstract partial class ZipFilePart
|
||||
|
||||
default:
|
||||
{
|
||||
throw new InvalidOperationException("Header.CompressionMethod is invalid");
|
||||
throw new ArchiveOperationException("Header.CompressionMethod is invalid");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ internal abstract partial class ZipFilePart : FilePart
|
||||
|
||||
default:
|
||||
{
|
||||
throw new InvalidOperationException("Header.CompressionMethod is invalid");
|
||||
throw new ArchiveOperationException("Header.CompressionMethod is invalid");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Compressors.RLE90;
|
||||
|
||||
namespace SharpCompress.Compressors.ArcLzw;
|
||||
@@ -74,7 +75,7 @@ public partial class ArcLzwStream : Stream
|
||||
{
|
||||
if (input[0] != BITS)
|
||||
{
|
||||
throw new InvalidDataException($"File packed with {input[0]}, expected {BITS}.");
|
||||
throw new InvalidFormatException($"File packed with {input[0]}, expected {BITS}.");
|
||||
}
|
||||
|
||||
input = input.Skip(1).ToArray();
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Compressors.Arj;
|
||||
|
||||
@@ -20,7 +21,7 @@ public partial class BitReader
|
||||
.ConfigureAwait(false);
|
||||
if (bytesRead < 1)
|
||||
{
|
||||
throw new EndOfStreamException("No more data available in BitReader.");
|
||||
throw new IncompleteArchiveException("No more data available in BitReader.");
|
||||
}
|
||||
|
||||
_bitBuffer = buffer[0];
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Compressors.Arj;
|
||||
|
||||
@@ -27,7 +28,7 @@ public partial class BitReader
|
||||
int nextByte = _input.ReadByte();
|
||||
if (nextByte < 0)
|
||||
{
|
||||
throw new EndOfStreamException("No more data available in BitReader.");
|
||||
throw new IncompleteArchiveException("No more data available in BitReader.");
|
||||
}
|
||||
|
||||
_bitBuffer = nextByte;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Compressors.Arj;
|
||||
|
||||
@@ -13,7 +14,7 @@ public sealed partial class HuffTree
|
||||
{
|
||||
if (_tree.Count == 0)
|
||||
{
|
||||
throw new InvalidOperationException("Tree not initialized");
|
||||
throw new ArchiveOperationException("Tree not initialized");
|
||||
}
|
||||
|
||||
TreeEntry node = _tree[0];
|
||||
@@ -29,7 +30,7 @@ public sealed partial class HuffTree
|
||||
|
||||
if (index >= _tree.Count)
|
||||
{
|
||||
throw new InvalidOperationException("Invalid branch index during read");
|
||||
throw new ArchiveOperationException("Invalid branch index during read");
|
||||
}
|
||||
|
||||
node = _tree[index];
|
||||
|
||||
@@ -87,7 +87,7 @@ public sealed partial class HuffTree
|
||||
|
||||
if (valueLengths.Length > TreeEntry.MAX_INDEX / 2)
|
||||
{
|
||||
throw new InvalidOperationException("Too many code lengths");
|
||||
throw new ArchiveOperationException("Too many code lengths");
|
||||
}
|
||||
|
||||
_tree.Clear();
|
||||
@@ -109,7 +109,7 @@ public sealed partial class HuffTree
|
||||
catch (ArgumentOutOfRangeException e)
|
||||
{
|
||||
_tree.Clear();
|
||||
throw new InvalidOperationException("Branch index exceeds limit", e);
|
||||
throw new ArchiveOperationException("Branch index exceeds limit", e);
|
||||
}
|
||||
|
||||
// each branch node allocates two children
|
||||
@@ -135,7 +135,7 @@ public sealed partial class HuffTree
|
||||
// sanity check (too many leaves)
|
||||
if (_tree.Count > maxAllocated)
|
||||
{
|
||||
throw new InvalidOperationException("Too many leaves");
|
||||
throw new ArchiveOperationException("Too many leaves");
|
||||
}
|
||||
|
||||
// stop when no longer finding longer codes
|
||||
@@ -148,7 +148,7 @@ public sealed partial class HuffTree
|
||||
// ensure tree is complete
|
||||
if (_tree.Count != maxAllocated)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
$"Missing some leaves: tree count = {_tree.Count}, expected = {maxAllocated}"
|
||||
);
|
||||
}
|
||||
@@ -158,7 +158,7 @@ public sealed partial class HuffTree
|
||||
{
|
||||
if (_tree.Count == 0)
|
||||
{
|
||||
throw new InvalidOperationException("Tree not initialized");
|
||||
throw new ArchiveOperationException("Tree not initialized");
|
||||
}
|
||||
|
||||
TreeEntry node = _tree[0];
|
||||
@@ -174,7 +174,7 @@ public sealed partial class HuffTree
|
||||
|
||||
if (index >= _tree.Count)
|
||||
{
|
||||
throw new InvalidOperationException("Invalid branch index during read");
|
||||
throw new ArchiveOperationException("Invalid branch index during read");
|
||||
}
|
||||
|
||||
node = _tree[index];
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Compressors.Arj;
|
||||
|
||||
@@ -34,7 +35,7 @@ public sealed partial class LHDecoderStream
|
||||
|
||||
if (backPtr >= _buffer.Count)
|
||||
{
|
||||
throw new InvalidDataException("Invalid back_ptr in LH stream");
|
||||
throw new InvalidFormatException("Invalid back_ptr in LH stream");
|
||||
}
|
||||
|
||||
int srcIndex = _buffer.Count - 1 - backPtr;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Compressors.Arj;
|
||||
|
||||
@@ -72,7 +73,7 @@ public sealed partial class LHDecoderStream : Stream
|
||||
|
||||
if (backPtr >= _buffer.Count)
|
||||
{
|
||||
throw new InvalidDataException("Invalid back_ptr in LH stream");
|
||||
throw new InvalidFormatException("Invalid back_ptr in LH stream");
|
||||
}
|
||||
|
||||
int srcIndex = _buffer.Count - 1 - backPtr;
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Compressors.Arj;
|
||||
|
||||
@@ -64,7 +65,7 @@ public sealed partial class LhaStream<TDecoderConfig>
|
||||
len++;
|
||||
if (len > 255)
|
||||
{
|
||||
throw new InvalidOperationException("Code length overflow");
|
||||
throw new ArchiveOperationException("Code length overflow");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,7 +115,7 @@ public sealed partial class LhaStream<TDecoderConfig>
|
||||
|
||||
if (numCodes > NUM_TEMP_CODELEN)
|
||||
{
|
||||
throw new InvalidDataException("temporary codelen table has invalid size");
|
||||
throw new InvalidFormatException("temporary codelen table has invalid size");
|
||||
}
|
||||
|
||||
// read actual lengths
|
||||
@@ -130,7 +131,7 @@ public sealed partial class LhaStream<TDecoderConfig>
|
||||
|
||||
if (3 + skip > numCodes)
|
||||
{
|
||||
throw new InvalidDataException("temporary codelen table has invalid size");
|
||||
throw new InvalidFormatException("temporary codelen table has invalid size");
|
||||
}
|
||||
|
||||
for (int i = 3 + skip; i < numCodes; i++)
|
||||
@@ -159,7 +160,7 @@ public sealed partial class LhaStream<TDecoderConfig>
|
||||
|
||||
if (numCodes > NUM_COMMANDS)
|
||||
{
|
||||
throw new InvalidDataException("commands codelen table has invalid size");
|
||||
throw new InvalidFormatException("commands codelen table has invalid size");
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
@@ -208,7 +209,7 @@ public sealed partial class LhaStream<TDecoderConfig>
|
||||
|
||||
if (numCodes > _config.HistoryBits)
|
||||
{
|
||||
throw new InvalidDataException("Offset code table too large");
|
||||
throw new InvalidFormatException("Offset code table too large");
|
||||
}
|
||||
|
||||
byte[] codeLengths = new byte[NUM_TEMP_CODELEN];
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Data;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Compressors.Arj;
|
||||
|
||||
@@ -86,7 +87,7 @@ public sealed partial class LhaStream<TDecoderConfig> : Stream
|
||||
len++;
|
||||
if (len > 255)
|
||||
{
|
||||
throw new InvalidOperationException("Code length overflow");
|
||||
throw new ArchiveOperationException("Code length overflow");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,7 +134,7 @@ public sealed partial class LhaStream<TDecoderConfig> : Stream
|
||||
|
||||
if (numCodes > NUM_TEMP_CODELEN)
|
||||
{
|
||||
throw new InvalidDataException("temporary codelen table has invalid size");
|
||||
throw new InvalidFormatException("temporary codelen table has invalid size");
|
||||
}
|
||||
|
||||
// read actual lengths
|
||||
@@ -148,7 +149,7 @@ public sealed partial class LhaStream<TDecoderConfig> : Stream
|
||||
|
||||
if (3 + skip > numCodes)
|
||||
{
|
||||
throw new InvalidDataException("temporary codelen table has invalid size");
|
||||
throw new InvalidFormatException("temporary codelen table has invalid size");
|
||||
}
|
||||
|
||||
for (int i = 3 + skip; i < numCodes; i++)
|
||||
@@ -176,7 +177,7 @@ public sealed partial class LhaStream<TDecoderConfig> : Stream
|
||||
|
||||
if (numCodes > NUM_COMMANDS)
|
||||
{
|
||||
throw new InvalidDataException("commands codelen table has invalid size");
|
||||
throw new InvalidFormatException("commands codelen table has invalid size");
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
@@ -218,7 +219,7 @@ public sealed partial class LhaStream<TDecoderConfig> : Stream
|
||||
|
||||
if (numCodes > _config.HistoryBits)
|
||||
{
|
||||
throw new InvalidDataException("Offset code table too large");
|
||||
throw new InvalidFormatException("Offset code table too large");
|
||||
}
|
||||
|
||||
byte[] codeLengths = new byte[NUM_TEMP_CODELEN];
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Buffers;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.IO;
|
||||
|
||||
namespace SharpCompress.Compressors.BZip2;
|
||||
@@ -68,7 +69,7 @@ internal partial class CBZip2InputStream
|
||||
}
|
||||
if (magic0 != 'B' || magic1 != 'Z' || magic2 != 'h')
|
||||
{
|
||||
throw new IOException("Not a BZIP2 marked stream");
|
||||
throw new InvalidFormatException("Not a BZIP2 marked stream");
|
||||
}
|
||||
var read3 = await bsStream
|
||||
.ReadAsync(singleByte, 0, 1, cancellationToken)
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Buffers;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
|
||||
/*
|
||||
* Copyright 2001,2004-2005 The Apache Software Foundation
|
||||
@@ -45,7 +46,7 @@ internal partial class CBZip2InputStream : Stream
|
||||
private static void Cadvise()
|
||||
{
|
||||
//System.out.Println("CRC Error");
|
||||
throw new InvalidOperationException("BZip2 error");
|
||||
throw new ArchiveOperationException("BZip2 error");
|
||||
}
|
||||
|
||||
private static void BadBGLengths() => Cadvise();
|
||||
@@ -54,7 +55,7 @@ internal partial class CBZip2InputStream : Stream
|
||||
|
||||
private static void CompressedStreamEOF()
|
||||
{
|
||||
throw new InvalidOperationException("BZip2 compressed file ends unexpectedly");
|
||||
throw new ArchiveOperationException("BZip2 compressed file ends unexpectedly");
|
||||
}
|
||||
|
||||
private void MakeMaps()
|
||||
@@ -259,7 +260,7 @@ internal partial class CBZip2InputStream : Stream
|
||||
}
|
||||
if (magic0 != 'B' || magic1 != 'Z' || magic2 != 'h')
|
||||
{
|
||||
throw new IOException("Not a BZIP2 marked stream");
|
||||
throw new InvalidFormatException("Not a BZIP2 marked stream");
|
||||
}
|
||||
var magic3 = bsStream.ReadByte();
|
||||
if (magic3 < '1' || magic3 > '9')
|
||||
@@ -1084,7 +1085,7 @@ internal partial class CBZip2InputStream : Stream
|
||||
{
|
||||
if (!(0 <= newSize100k && newSize100k <= 9 && 0 <= blockSize100k && blockSize100k <= 9))
|
||||
{
|
||||
// throw new IOException("Invalid block size");
|
||||
// throw new InvalidFormatException("Invalid block size");
|
||||
}
|
||||
|
||||
blockSize100k = newSize100k;
|
||||
|
||||
@@ -70,6 +70,7 @@
|
||||
|
||||
using System;
|
||||
using SharpCompress.Algorithms;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Compressors.Deflate;
|
||||
|
||||
@@ -1707,7 +1708,7 @@ internal sealed partial class DeflateManager
|
||||
{
|
||||
throw new ZlibException(
|
||||
string.Format(
|
||||
global::SharpCompress.Common.Constants.DefaultCultureInfo,
|
||||
Constants.DefaultCultureInfo,
|
||||
"memLevel must be in the range 1.. {0}",
|
||||
MEM_LEVEL_MAX
|
||||
)
|
||||
@@ -1882,7 +1883,7 @@ internal sealed partial class DeflateManager
|
||||
];
|
||||
throw new ZlibException(
|
||||
string.Format(
|
||||
global::SharpCompress.Common.Constants.DefaultCultureInfo,
|
||||
Constants.DefaultCultureInfo,
|
||||
"Something is fishy. [{0}]",
|
||||
_codec.Message
|
||||
)
|
||||
|
||||
@@ -29,6 +29,7 @@ using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.IO;
|
||||
|
||||
namespace SharpCompress.Compressors.Deflate;
|
||||
@@ -120,7 +121,7 @@ public partial class DeflateStream : Stream, IStreamStack
|
||||
{
|
||||
throw new ZlibException(
|
||||
string.Format(
|
||||
global::SharpCompress.Common.Constants.DefaultCultureInfo,
|
||||
Constants.DefaultCultureInfo,
|
||||
"Don't be silly. {0} bytes?? Use a bigger buffer, at least {1}.",
|
||||
value,
|
||||
ZlibConstants.WorkingBufferSizeMin
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.IO;
|
||||
|
||||
namespace SharpCompress.Compressors.Deflate;
|
||||
@@ -85,7 +86,7 @@ public partial class GZipStream
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +112,7 @@ public partial class GZipStream
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ public partial class GZipStream : Stream
|
||||
{
|
||||
throw new ZlibException(
|
||||
string.Format(
|
||||
global::SharpCompress.Common.Constants.DefaultCultureInfo,
|
||||
Constants.DefaultCultureInfo,
|
||||
"Don't be silly. {0} bytes?? Use a bigger buffer, at least {1}.",
|
||||
value,
|
||||
ZlibConstants.WorkingBufferSizeMin
|
||||
@@ -354,7 +354,7 @@ public partial class GZipStream : Stream
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -413,7 +413,7 @@ public partial class GZipStream : Stream
|
||||
}
|
||||
if (_fileName.EndsWith('\\'))
|
||||
{
|
||||
throw new InvalidOperationException("Illegal filename");
|
||||
throw new ArchiveOperationException("Illegal filename");
|
||||
}
|
||||
|
||||
#if LEGACY_DOTNET
|
||||
|
||||
@@ -66,6 +66,7 @@
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using SharpCompress.Algorithms;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Compressors.Deflate;
|
||||
|
||||
@@ -1746,7 +1747,7 @@ internal sealed class InflateManager
|
||||
{
|
||||
mode = InflateManagerMode.BAD;
|
||||
_codec.Message = string.Format(
|
||||
global::SharpCompress.Common.Constants.DefaultCultureInfo,
|
||||
Constants.DefaultCultureInfo,
|
||||
"unknown compression method (0x{0:X2})",
|
||||
method
|
||||
);
|
||||
@@ -1757,7 +1758,7 @@ internal sealed class InflateManager
|
||||
{
|
||||
mode = InflateManagerMode.BAD;
|
||||
_codec.Message = string.Format(
|
||||
global::SharpCompress.Common.Constants.DefaultCultureInfo,
|
||||
Constants.DefaultCultureInfo,
|
||||
"invalid window size ({0})",
|
||||
(method >> 4) + 8
|
||||
);
|
||||
@@ -1949,7 +1950,7 @@ internal sealed class InflateManager
|
||||
case InflateManagerMode.BAD:
|
||||
throw new ZlibException(
|
||||
string.Format(
|
||||
global::SharpCompress.Common.Constants.DefaultCultureInfo,
|
||||
Constants.DefaultCultureInfo,
|
||||
"Bad state ({0})",
|
||||
_codec.Message
|
||||
)
|
||||
|
||||
@@ -33,6 +33,7 @@ using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Common.Tar.Headers;
|
||||
using SharpCompress.IO;
|
||||
|
||||
@@ -276,12 +277,7 @@ internal class ZlibBaseStream : Stream, IStreamStack
|
||||
if (_z.Message is null)
|
||||
{
|
||||
throw new ZlibException(
|
||||
String.Format(
|
||||
global::SharpCompress.Common.Constants.DefaultCultureInfo,
|
||||
"{0}: (rc = {1})",
|
||||
verb,
|
||||
rc
|
||||
)
|
||||
String.Format(Constants.DefaultCultureInfo, "{0}: (rc = {1})", verb, rc)
|
||||
);
|
||||
}
|
||||
throw new ZlibException(verb + ": " + _z.Message);
|
||||
@@ -351,7 +347,7 @@ internal class ZlibBaseStream : Stream, IStreamStack
|
||||
{
|
||||
throw new ZlibException(
|
||||
String.Format(
|
||||
global::SharpCompress.Common.Constants.DefaultCultureInfo,
|
||||
Constants.DefaultCultureInfo,
|
||||
"Protocol error. AvailableBytesIn={0}, expected 8",
|
||||
_z.AvailableBytesIn + bytesRead
|
||||
)
|
||||
@@ -372,7 +368,7 @@ internal class ZlibBaseStream : Stream, IStreamStack
|
||||
{
|
||||
throw new ZlibException(
|
||||
String.Format(
|
||||
global::SharpCompress.Common.Constants.DefaultCultureInfo,
|
||||
Constants.DefaultCultureInfo,
|
||||
"Bad CRC32 in GZIP stream. (actual({0:X8})!=expected({1:X8}))",
|
||||
crc32_actual,
|
||||
crc32_expected
|
||||
@@ -384,7 +380,7 @@ internal class ZlibBaseStream : Stream, IStreamStack
|
||||
{
|
||||
throw new ZlibException(
|
||||
String.Format(
|
||||
global::SharpCompress.Common.Constants.DefaultCultureInfo,
|
||||
Constants.DefaultCultureInfo,
|
||||
"Bad size in GZIP stream. (actual({0})!=expected({1}))",
|
||||
isize_actual,
|
||||
isize_expected
|
||||
@@ -424,12 +420,7 @@ internal class ZlibBaseStream : Stream, IStreamStack
|
||||
if (_z.Message is null)
|
||||
{
|
||||
throw new ZlibException(
|
||||
String.Format(
|
||||
global::SharpCompress.Common.Constants.DefaultCultureInfo,
|
||||
"{0}: (rc = {1})",
|
||||
verb,
|
||||
rc
|
||||
)
|
||||
String.Format(Constants.DefaultCultureInfo, "{0}: (rc = {1})", verb, rc)
|
||||
);
|
||||
}
|
||||
throw new ZlibException(verb + ": " + _z.Message);
|
||||
@@ -887,7 +878,7 @@ internal class ZlibBaseStream : Stream, IStreamStack
|
||||
{
|
||||
throw new ZlibException(
|
||||
String.Format(
|
||||
global::SharpCompress.Common.Constants.DefaultCultureInfo,
|
||||
Constants.DefaultCultureInfo,
|
||||
"Deflating: rc={0} msg={1}",
|
||||
rc,
|
||||
_z.Message
|
||||
@@ -944,7 +935,7 @@ internal class ZlibBaseStream : Stream, IStreamStack
|
||||
{
|
||||
throw new ZlibException(
|
||||
String.Format(
|
||||
global::SharpCompress.Common.Constants.DefaultCultureInfo,
|
||||
Constants.DefaultCultureInfo,
|
||||
"{0}flating: rc={1} msg={2}",
|
||||
(_wantCompress ? "de" : "in"),
|
||||
rc,
|
||||
@@ -985,7 +976,7 @@ internal class ZlibBaseStream : Stream, IStreamStack
|
||||
{
|
||||
throw new ZlibException(
|
||||
String.Format(
|
||||
global::SharpCompress.Common.Constants.DefaultCultureInfo,
|
||||
Constants.DefaultCultureInfo,
|
||||
"Deflating: rc={0} msg={1}",
|
||||
rc,
|
||||
_z.Message
|
||||
@@ -1079,7 +1070,7 @@ internal class ZlibBaseStream : Stream, IStreamStack
|
||||
{
|
||||
throw new ZlibException(
|
||||
String.Format(
|
||||
global::SharpCompress.Common.Constants.DefaultCultureInfo,
|
||||
Constants.DefaultCultureInfo,
|
||||
"Deflating: rc={0} msg={1}",
|
||||
rc,
|
||||
_z.Message
|
||||
@@ -1138,7 +1129,7 @@ internal class ZlibBaseStream : Stream, IStreamStack
|
||||
{
|
||||
throw new ZlibException(
|
||||
String.Format(
|
||||
global::SharpCompress.Common.Constants.DefaultCultureInfo,
|
||||
Constants.DefaultCultureInfo,
|
||||
"{0}flating: rc={1} msg={2}",
|
||||
(_wantCompress ? "de" : "in"),
|
||||
rc,
|
||||
@@ -1179,7 +1170,7 @@ internal class ZlibBaseStream : Stream, IStreamStack
|
||||
{
|
||||
throw new ZlibException(
|
||||
String.Format(
|
||||
global::SharpCompress.Common.Constants.DefaultCultureInfo,
|
||||
Constants.DefaultCultureInfo,
|
||||
"Deflating: rc={0} msg={1}",
|
||||
rc,
|
||||
_z.Message
|
||||
|
||||
@@ -66,6 +66,7 @@
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Compressors.Deflate;
|
||||
|
||||
@@ -696,7 +697,7 @@ internal sealed class ZlibCodec
|
||||
{
|
||||
throw new ZlibException(
|
||||
string.Format(
|
||||
global::SharpCompress.Common.Constants.DefaultCultureInfo,
|
||||
Constants.DefaultCultureInfo,
|
||||
"Invalid State. (pending.Length={0}, pendingCount={1})",
|
||||
dstate.pending.Length,
|
||||
dstate.pendingCount
|
||||
|
||||
@@ -30,6 +30,7 @@ using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Compressors.Deflate;
|
||||
|
||||
@@ -107,7 +108,7 @@ public partial class ZlibStream : Stream
|
||||
{
|
||||
throw new ZlibException(
|
||||
string.Format(
|
||||
global::SharpCompress.Common.Constants.DefaultCultureInfo,
|
||||
Constants.DefaultCultureInfo,
|
||||
"Don't be silly. {0} bytes?? Use a bigger buffer, at least {1}.",
|
||||
value,
|
||||
ZlibConstants.WorkingBufferSizeMin
|
||||
|
||||
@@ -141,7 +141,7 @@ public sealed partial class Deflate64Stream : Stream
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private static void ThrowCannotWriteToDeflateManagedStreamException() =>
|
||||
throw new InvalidOperationException("Deflate64: cannot write to this stream");
|
||||
throw new ArchiveOperationException("Deflate64: cannot write to this stream");
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count) =>
|
||||
ThrowCannotWriteToDeflateManagedStreamException();
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Common.Zip.Headers;
|
||||
using SharpCompress.IO;
|
||||
|
||||
@@ -279,7 +280,7 @@ public partial class ExplodeStream
|
||||
|
||||
if (literalResult.returnCode != 0)
|
||||
{
|
||||
throw new InvalidDataException("Error decoding literal value");
|
||||
throw new InvalidFormatException("Error decoding literal value");
|
||||
}
|
||||
|
||||
huftPointer = literalResult.huftPointer;
|
||||
@@ -319,7 +320,7 @@ public partial class ExplodeStream
|
||||
|
||||
if (distanceResult.returnCode != 0)
|
||||
{
|
||||
throw new InvalidDataException("Error decoding distance high bits");
|
||||
throw new InvalidFormatException("Error decoding distance high bits");
|
||||
}
|
||||
|
||||
huftPointer = distanceResult.huftPointer;
|
||||
@@ -335,7 +336,7 @@ public partial class ExplodeStream
|
||||
|
||||
if (lengthResult.returnCode != 0)
|
||||
{
|
||||
throw new InvalidDataException("Error decoding coded length");
|
||||
throw new InvalidFormatException("Error decoding coded length");
|
||||
}
|
||||
|
||||
huftPointer = lengthResult.huftPointer;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Common.Zip.Headers;
|
||||
|
||||
namespace SharpCompress.Compressors.Explode;
|
||||
@@ -697,7 +698,7 @@ public partial class ExplodeStream : Stream
|
||||
) != 0
|
||||
)
|
||||
{
|
||||
throw new InvalidDataException("Error decoding literal value");
|
||||
throw new InvalidFormatException("Error decoding literal value");
|
||||
}
|
||||
|
||||
nextByte = (byte)huftPointer.Value;
|
||||
@@ -736,7 +737,7 @@ public partial class ExplodeStream : Stream
|
||||
) != 0
|
||||
)
|
||||
{
|
||||
throw new InvalidDataException("Error decoding distance high bits");
|
||||
throw new InvalidFormatException("Error decoding distance high bits");
|
||||
}
|
||||
|
||||
distance = windowIndex - (distance + huftPointer.Value); /* construct offset */
|
||||
@@ -752,7 +753,7 @@ public partial class ExplodeStream : Stream
|
||||
) != 0
|
||||
)
|
||||
{
|
||||
throw new InvalidDataException("Error decoding coded length");
|
||||
throw new InvalidFormatException("Error decoding coded length");
|
||||
}
|
||||
|
||||
length = huftPointer.Value;
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Compressors.LZMA;
|
||||
|
||||
@@ -41,7 +42,7 @@ internal sealed partial class AesDecoderStream
|
||||
if (read == 0)
|
||||
{
|
||||
// We are not done decoding and have less than 16 bytes.
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
|
||||
mEnding += read;
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Compressors.LZMA.Utilities;
|
||||
|
||||
namespace SharpCompress.Compressors.LZMA;
|
||||
@@ -44,7 +45,7 @@ internal sealed partial class AesDecoderStream : DecoderStream2
|
||||
var key = InitKey(numCyclesPower, salt, passwordBytes);
|
||||
if (key == null)
|
||||
{
|
||||
throw new InvalidOperationException("Initialized with null key");
|
||||
throw new ArchiveOperationException("Initialized with null key");
|
||||
}
|
||||
|
||||
using (var aes = Aes.Create())
|
||||
@@ -107,7 +108,7 @@ internal sealed partial class AesDecoderStream : DecoderStream2
|
||||
if (read == 0)
|
||||
{
|
||||
// We are not done decoding and have less than 16 bytes.
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
|
||||
mEnding += read;
|
||||
@@ -160,7 +161,7 @@ internal sealed partial class AesDecoderStream : DecoderStream2
|
||||
var ivSize = (bt >> 6) & 1;
|
||||
if (info.Length == 1)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
|
||||
var bt2 = info[1];
|
||||
@@ -168,7 +169,7 @@ internal sealed partial class AesDecoderStream : DecoderStream2
|
||||
ivSize += (bt2 & 15);
|
||||
if (info.Length < 2 + saltSize + ivSize)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
|
||||
salt = new byte[saltSize];
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Compressors.LZMA;
|
||||
|
||||
@@ -32,7 +33,7 @@ internal class Bcj2DecoderStream : DecoderStream2
|
||||
var bt = _mStream.ReadByte();
|
||||
if (bt < 0)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
|
||||
return (byte)bt;
|
||||
@@ -233,7 +234,7 @@ internal class Bcj2DecoderStream : DecoderStream2
|
||||
var b0 = s.ReadByte();
|
||||
if (b0 < 0)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
|
||||
src <<= 8;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Compressors.LZMA;
|
||||
|
||||
@@ -39,7 +40,7 @@ internal static class Crc
|
||||
var delta = stream.Read(buffer, 0, (int)Math.Min(length, buffer.Length));
|
||||
if (delta == 0)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
crc = Update(crc, buffer, 0, delta);
|
||||
length -= delta;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Compressors.LZMA;
|
||||
|
||||
@@ -16,7 +17,7 @@ internal static class Log
|
||||
{
|
||||
if (INDENT.Count == 1)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
|
||||
INDENT.Pop();
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Compressors.LZMA.RangeCoder;
|
||||
|
||||
@@ -91,7 +92,7 @@ internal partial class Decoder
|
||||
.ConfigureAwait(false);
|
||||
if (read == 0)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
_code = (_code << 8) | buffer[0];
|
||||
}
|
||||
@@ -108,7 +109,7 @@ internal partial class Decoder
|
||||
.ConfigureAwait(false);
|
||||
if (read == 0)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
_code = (_code << 8) | buffer[0];
|
||||
_range <<= 8;
|
||||
@@ -126,7 +127,7 @@ internal partial class Decoder
|
||||
.ConfigureAwait(false);
|
||||
if (read == 0)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
_code = (_code << 8) | buffer[0];
|
||||
_range <<= 8;
|
||||
@@ -157,7 +158,7 @@ internal partial class Decoder
|
||||
.ConfigureAwait(false);
|
||||
if (read == 0)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
code = (code << 8) | buffer[0];
|
||||
range <<= 8;
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Compressors.LZMA.Utilities;
|
||||
|
||||
@@ -17,7 +18,7 @@ internal partial class CrcBuilderStream : Stream
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
if (_mFinished)
|
||||
{
|
||||
throw new InvalidOperationException("CRC calculation has been finished.");
|
||||
throw new ArchiveOperationException("CRC calculation has been finished.");
|
||||
}
|
||||
|
||||
Processed += count;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Compressors.LZMA.Utilities;
|
||||
|
||||
@@ -57,7 +58,7 @@ internal partial class CrcBuilderStream : Stream
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count) =>
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException();
|
||||
|
||||
@@ -67,7 +68,7 @@ internal partial class CrcBuilderStream : Stream
|
||||
{
|
||||
if (_mFinished)
|
||||
{
|
||||
throw new InvalidOperationException("CRC calculation has been finished.");
|
||||
throw new ArchiveOperationException("CRC calculation has been finished.");
|
||||
}
|
||||
|
||||
Processed += count;
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Buffers;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Compressors.LZMA.Utilities;
|
||||
|
||||
@@ -25,7 +26,7 @@ public class CrcCheckStream(uint crc) : Stream
|
||||
|
||||
if (_mCurrentCrc != crc) //moved test to here
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,7 +54,7 @@ public class CrcCheckStream(uint crc) : Stream
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count) =>
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException();
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public partial class LzwStream
|
||||
{
|
||||
throw new IncompleteArchiveException(
|
||||
String.Format(
|
||||
global::SharpCompress.Common.Constants.DefaultCultureInfo,
|
||||
Constants.DefaultCultureInfo,
|
||||
"Wrong LZW header. Magic bytes don't match. 0x{0:x2} 0x{1:x2}",
|
||||
hdr[0],
|
||||
hdr[1]
|
||||
@@ -326,7 +326,7 @@ public partial class LzwStream
|
||||
{
|
||||
throw new IncompleteArchiveException(
|
||||
String.Format(
|
||||
global::SharpCompress.Common.Constants.DefaultCultureInfo,
|
||||
Constants.DefaultCultureInfo,
|
||||
"Wrong LZW header. Magic bytes don't match. 0x{0:x2} 0x{1:x2}",
|
||||
hdr[0],
|
||||
hdr[1]
|
||||
|
||||
@@ -64,7 +64,7 @@ public partial class LzwStream : Stream
|
||||
{
|
||||
throw new IncompleteArchiveException(
|
||||
String.Format(
|
||||
global::SharpCompress.Common.Constants.DefaultCultureInfo,
|
||||
Constants.DefaultCultureInfo,
|
||||
"Wrong LZW header. Magic bytes don't match. 0x{0:x2} 0x{1:x2}",
|
||||
hdr[0],
|
||||
hdr[1]
|
||||
@@ -398,7 +398,7 @@ public partial class LzwStream : Stream
|
||||
{
|
||||
throw new IncompleteArchiveException(
|
||||
String.Format(
|
||||
global::SharpCompress.Common.Constants.DefaultCultureInfo,
|
||||
Constants.DefaultCultureInfo,
|
||||
"Wrong LZW header. Magic bytes don't match. 0x{0:x2} 0x{1:x2}",
|
||||
hdr[0],
|
||||
hdr[1]
|
||||
|
||||
@@ -67,7 +67,7 @@ internal sealed partial class MultiVolumeReadOnlyAsyncStream : MultiVolumeReadOn
|
||||
.ConfigureAwait(false);
|
||||
if (read < 0)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
|
||||
currentPosition += read;
|
||||
@@ -129,7 +129,7 @@ internal sealed partial class MultiVolumeReadOnlyAsyncStream : MultiVolumeReadOn
|
||||
.ConfigureAwait(false);
|
||||
if (read < 0)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
|
||||
currentPosition += read;
|
||||
|
||||
@@ -34,7 +34,7 @@ internal sealed partial class MultiVolumeReadOnlyStream : MultiVolumeReadOnlyStr
|
||||
.ConfigureAwait(false);
|
||||
if (read < 0)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
|
||||
currentPosition += read;
|
||||
@@ -96,7 +96,7 @@ internal sealed partial class MultiVolumeReadOnlyStream : MultiVolumeReadOnlyStr
|
||||
.ConfigureAwait(false);
|
||||
if (read < 0)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
|
||||
currentPosition += read;
|
||||
|
||||
@@ -57,7 +57,7 @@ internal sealed partial class MultiVolumeReadOnlyStream : MultiVolumeReadOnlyStr
|
||||
var read = currentStream.NotNull().Read(buffer, currentOffset, readSize);
|
||||
if (read < 0)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
|
||||
currentPosition += read;
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Buffers;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Common.Rar.Headers;
|
||||
using SharpCompress.IO;
|
||||
|
||||
@@ -69,7 +70,7 @@ internal partial class RarStream
|
||||
if (count > 0 && outTotal == 0 && _position < Length)
|
||||
{
|
||||
// sanity check, eg if we try to decompress a redir entry
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
$"unpacked file size does not match header: expected {Length} found {_position}"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.IO;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Common.Rar.Headers;
|
||||
|
||||
namespace SharpCompress.Compressors.Rar;
|
||||
@@ -99,7 +100,7 @@ internal partial class RarStream : Stream
|
||||
if (count > 0 && outTotal == 0 && _position < Length)
|
||||
{
|
||||
// sanity check, eg if we try to decompress a redir entry
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
$"unpacked file size does not match header: expected {Length} found {_position}"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using SharpCompress.Common;
|
||||
using size_t = System.UInt32;
|
||||
|
||||
namespace SharpCompress.Compressors.Rar.UnpackV2017;
|
||||
@@ -63,7 +64,7 @@ internal partial class FragmentedWindow
|
||||
// sharpcompress: don't need this, freshly allocated above
|
||||
//Utility.Memset(NewMem,0,Size);
|
||||
|
||||
Mem[BlockNum] = NewMem ?? throw new InvalidOperationException();
|
||||
Mem[BlockNum] = NewMem ?? throw new ArchiveOperationException();
|
||||
TotalSize += Size;
|
||||
MemSize[BlockNum] = TotalSize;
|
||||
BlockNum++;
|
||||
@@ -71,7 +72,7 @@ internal partial class FragmentedWindow
|
||||
if (TotalSize < WinSize) // Not found enough free blocks.
|
||||
//throw std::bad_alloc();
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
throw new ArchiveOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Compressors.Shrink;
|
||||
|
||||
@@ -49,7 +50,7 @@ internal partial class ShrinkStream : Stream
|
||||
.ConfigureAwait(false);
|
||||
if (bytesRead == 0)
|
||||
{
|
||||
throw new EndOfStreamException(
|
||||
throw new IncompleteArchiveException(
|
||||
"Unexpected end of stream while reading compressed data"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Compressors.Squeezed;
|
||||
|
||||
@@ -17,7 +18,7 @@ public partial class BitReader
|
||||
.ConfigureAwait(false);
|
||||
if (bytesRead == 0)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
|
||||
_bitBuffer = buffer[0];
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Compressors.Squeezed;
|
||||
|
||||
@@ -23,7 +24,7 @@ public partial class BitReader
|
||||
int nextByte = _stream.ReadByte();
|
||||
if (nextByte == -1)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
|
||||
_bitBuffer = nextByte;
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Compressors.RLE90;
|
||||
|
||||
namespace SharpCompress.Compressors.Squeezed;
|
||||
@@ -73,7 +74,7 @@ public partial class SqueezeStream
|
||||
|
||||
if (bytesRead != 4)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
|
||||
dnode[j, 0] = (short)(nodeBytes[0] | (nodeBytes[1] << 8));
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Buffers.Binary;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Compressors.Xz;
|
||||
|
||||
@@ -17,7 +18,7 @@ public static partial class BinaryUtils
|
||||
var read = await stream.ReadFullyAsync(bytes, cancellationToken).ConfigureAwait(false);
|
||||
if (!read)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
return BinaryPrimitives.ReadInt32LittleEndian(bytes);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Buffers.Binary;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Compressors.Xz;
|
||||
|
||||
@@ -24,7 +25,7 @@ public static partial class BinaryUtils
|
||||
var read = stream.ReadFully(bytes);
|
||||
if (!read)
|
||||
{
|
||||
throw new EndOfStreamException();
|
||||
throw new IncompleteArchiveException("Unexpected end of stream.");
|
||||
}
|
||||
return BinaryPrimitives.ReadInt32LittleEndian(bytes);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public partial class Lzma2Filter : BlockFilter
|
||||
{
|
||||
if (_dictionarySize > 40)
|
||||
{
|
||||
throw new OverflowException("Dictionary size greater than UInt32.Max");
|
||||
throw new InvalidFormatException("Dictionary size greater than UInt32.Max");
|
||||
}
|
||||
|
||||
if (_dictionarySize == 40)
|
||||
|
||||
@@ -115,7 +115,7 @@ public sealed partial class XZBlock
|
||||
.ConfigureAwait(false);
|
||||
if (read != BlockHeaderSize - 5)
|
||||
{
|
||||
throw new EndOfStreamException("Reached end of stream unexpectedly");
|
||||
throw new IncompleteArchiveException("Reached end of stream unexpectedly");
|
||||
}
|
||||
|
||||
var crc = await BaseStream
|
||||
|
||||
@@ -139,7 +139,7 @@ public sealed partial class XZBlock : XZReadOnlyStream
|
||||
var read = BaseStream.Read(blockHeaderWithoutCrc, 1, BlockHeaderSize - 5);
|
||||
if (read != BlockHeaderSize - 5)
|
||||
{
|
||||
throw new EndOfStreamException("Reached end of stream unexpectedly");
|
||||
throw new IncompleteArchiveException("Reached end of stream unexpectedly");
|
||||
}
|
||||
|
||||
var crc = BaseStream.ReadLittleEndianUInt32();
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Buffers;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Compressors.ZStandard.Unsafe;
|
||||
|
||||
namespace SharpCompress.Compressors.ZStandard;
|
||||
@@ -78,7 +79,7 @@ public partial class DecompressionStream
|
||||
{
|
||||
if (checkEndOfStream && lastDecompressResult != 0)
|
||||
{
|
||||
throw new EndOfStreamException("Premature end of stream");
|
||||
throw new IncompleteArchiveException("Premature end of stream");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Buffers;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Compressors.ZStandard.Unsafe;
|
||||
|
||||
namespace SharpCompress.Compressors.ZStandard;
|
||||
@@ -151,7 +152,7 @@ public partial class DecompressionStream : Stream
|
||||
{
|
||||
if (checkEndOfStream && lastDecompressResult != 0)
|
||||
{
|
||||
throw new EndOfStreamException("Premature end of stream");
|
||||
throw new IncompleteArchiveException("Premature end of stream");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -46,7 +46,7 @@ internal class MarkingBinaryReader(Stream stream)
|
||||
{
|
||||
throw new InvalidFormatException(
|
||||
string.Format(
|
||||
global::SharpCompress.Common.Constants.DefaultCultureInfo,
|
||||
Constants.DefaultCultureInfo,
|
||||
"Could not read the requested amount of bytes. End of stream reached. Requested: {0} Read: {1}",
|
||||
count,
|
||||
bytes.Length
|
||||
@@ -115,7 +115,7 @@ internal class MarkingBinaryReader(Stream stream)
|
||||
shift += 7;
|
||||
} while (shift <= maxShift);
|
||||
|
||||
throw new FormatException("malformed vint");
|
||||
throw new InvalidFormatException("malformed vint");
|
||||
}
|
||||
|
||||
public uint ReadRarVIntUInt32(int maxBytes = 5) =>
|
||||
@@ -153,6 +153,6 @@ internal class MarkingBinaryReader(Stream stream)
|
||||
shift += 7;
|
||||
} while (shift <= maxShift);
|
||||
|
||||
throw new FormatException("malformed vint");
|
||||
throw new InvalidFormatException("malformed vint");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.IO;
|
||||
|
||||
@@ -33,7 +34,7 @@ internal sealed partial class SeekableSharpCompressStream
|
||||
}
|
||||
if (ThrowOnDispose)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
$"Attempt to dispose of a {nameof(SeekableSharpCompressStream)} when {nameof(ThrowOnDispose)} is true"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.IO;
|
||||
|
||||
@@ -97,7 +98,7 @@ internal sealed partial class SeekableSharpCompressStream : SharpCompressStream
|
||||
}
|
||||
if (ThrowOnDispose)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
$"Attempt to dispose of a {nameof(SeekableSharpCompressStream)} when {nameof(ThrowOnDispose)} is true"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.IO;
|
||||
|
||||
@@ -71,7 +72,7 @@ public partial class SharpCompressStream
|
||||
// Verify data is available in ring buffer
|
||||
if (!_ringBuffer!.CanReadFromEnd(bytesFromEnd))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
$"Ring buffer underflow: trying to read {bytesFromEnd} bytes back, "
|
||||
+ $"but buffer only holds {_ringBuffer.Length} bytes."
|
||||
);
|
||||
@@ -161,7 +162,7 @@ public partial class SharpCompressStream
|
||||
// Verify data is available in ring buffer
|
||||
if (!_ringBuffer!.CanReadFromEnd(bytesFromEnd))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
$"Ring buffer underflow: trying to read {bytesFromEnd} bytes back, "
|
||||
+ $"but buffer only holds {_ringBuffer.Length} bytes."
|
||||
);
|
||||
@@ -263,7 +264,7 @@ public partial class SharpCompressStream
|
||||
{
|
||||
if (ThrowOnDispose)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
$"Attempt to dispose of a {nameof(SharpCompressStream)} when {nameof(ThrowOnDispose)} is true"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public partial class SharpCompressStream : Stream, IStreamStack
|
||||
}
|
||||
if (ThrowOnDispose)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
$"Attempt to dispose of a {nameof(SharpCompressStream)} when {nameof(ThrowOnDispose)} is true"
|
||||
);
|
||||
}
|
||||
@@ -115,14 +115,14 @@ public partial class SharpCompressStream : Stream, IStreamStack
|
||||
{
|
||||
if (_isPassthrough)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
"Rewind cannot be called on a passthrough stream. Use Create() first."
|
||||
);
|
||||
}
|
||||
|
||||
if (_recordingStartPosition is null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
"Rewind can only be called after StartRecording() has been called."
|
||||
);
|
||||
}
|
||||
@@ -131,7 +131,7 @@ public partial class SharpCompressStream : Stream, IStreamStack
|
||||
long anchorAge = streamPosition - _recordingStartPosition.Value;
|
||||
if (anchorAge > _ringBuffer!.Length)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
$"Cannot rewind: recording anchor is {anchorAge} bytes behind current position, "
|
||||
+ $"but ring buffer only holds {_ringBuffer.Length} bytes. "
|
||||
+ $"Recording buffer overflow - increase DefaultRollingBufferSize or reduce format detection reads."
|
||||
@@ -154,13 +154,13 @@ public partial class SharpCompressStream : Stream, IStreamStack
|
||||
{
|
||||
if (_isPassthrough)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
"StopRecording cannot be called on a passthrough stream. Use Create() first."
|
||||
);
|
||||
}
|
||||
if (!IsRecording)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
"StopRecording can only be called when recording is active."
|
||||
);
|
||||
}
|
||||
@@ -179,13 +179,13 @@ public partial class SharpCompressStream : Stream, IStreamStack
|
||||
{
|
||||
if (_isPassthrough)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
"StartRecording cannot be called on a passthrough stream. Use Create() first."
|
||||
);
|
||||
}
|
||||
if (IsRecording)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
"StartRecording can only be called when not already recording."
|
||||
);
|
||||
}
|
||||
@@ -337,7 +337,7 @@ public partial class SharpCompressStream : Stream, IStreamStack
|
||||
// Verify data is available in ring buffer
|
||||
if (!_ringBuffer!.CanReadFromEnd(bytesFromEnd))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
$"Ring buffer underflow: trying to read {bytesFromEnd} bytes back, "
|
||||
+ $"but buffer only holds {_ringBuffer.Length} bytes."
|
||||
);
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Readers;
|
||||
|
||||
namespace SharpCompress.IO;
|
||||
@@ -206,7 +207,7 @@ public partial class SourceStream : Stream, IStreamStack
|
||||
if (!SetStream(_stream + 1))
|
||||
{
|
||||
// No more streams available, cannot seek to requested position
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
$"Cannot seek to position {pos}. End of stream reached at position {_prevSize}."
|
||||
);
|
||||
}
|
||||
@@ -216,7 +217,7 @@ public partial class SourceStream : Stream, IStreamStack
|
||||
if (currentLength <= 0 && Current.Length <= 0)
|
||||
{
|
||||
// Both old and new stream have zero length - cannot make progress
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
$"Cannot seek to position {pos}. Encountered zero-length streams at position {_prevSize}."
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress;
|
||||
|
||||
@@ -117,12 +118,12 @@ public static class AsyncEnumerableExtensions
|
||||
|
||||
if (!await enumerator.MoveNextAsync().ConfigureAwait(false))
|
||||
{
|
||||
throw new InvalidOperationException("The source sequence is empty.");
|
||||
throw new ArchiveOperationException("The source sequence is empty.");
|
||||
}
|
||||
var value = enumerator.Current;
|
||||
if (await enumerator.MoveNextAsync().ConfigureAwait(false))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
"The source sequence contains more than one element."
|
||||
);
|
||||
}
|
||||
@@ -135,7 +136,7 @@ public static class AsyncEnumerableExtensions
|
||||
{
|
||||
return item;
|
||||
}
|
||||
throw new InvalidOperationException("The source sequence is empty.");
|
||||
throw new ArchiveOperationException("The source sequence is empty.");
|
||||
}
|
||||
|
||||
public async ValueTask<T?> FirstOrDefaultAsync(
|
||||
|
||||
@@ -62,14 +62,14 @@ public sealed class CompressionProviderRegistry
|
||||
/// <param name="destination">The destination stream.</param>
|
||||
/// <param name="level">The compression level.</param>
|
||||
/// <returns>A compression stream.</returns>
|
||||
/// <exception cref="InvalidOperationException">If no provider is registered for the type.</exception>
|
||||
/// <exception cref="ArchiveOperationException">If no provider is registered for the type.</exception>
|
||||
/// <exception cref="NotSupportedException">If the provider does not support compression.</exception>
|
||||
public Stream CreateCompressStream(CompressionType type, Stream destination, int level)
|
||||
{
|
||||
var provider = GetProvider(type);
|
||||
if (provider is null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
$"No compression provider registered for type: {type}"
|
||||
);
|
||||
}
|
||||
@@ -82,14 +82,14 @@ public sealed class CompressionProviderRegistry
|
||||
/// <param name="type">The compression type.</param>
|
||||
/// <param name="source">The source stream.</param>
|
||||
/// <returns>A decompression stream.</returns>
|
||||
/// <exception cref="InvalidOperationException">If no provider is registered for the type.</exception>
|
||||
/// <exception cref="ArchiveOperationException">If no provider is registered for the type.</exception>
|
||||
/// <exception cref="NotSupportedException">If the provider does not support decompression.</exception>
|
||||
public Stream CreateDecompressStream(CompressionType type, Stream source)
|
||||
{
|
||||
var provider = GetProvider(type);
|
||||
if (provider is null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
$"No compression provider registered for type: {type}"
|
||||
);
|
||||
}
|
||||
@@ -104,7 +104,7 @@ public sealed class CompressionProviderRegistry
|
||||
/// <param name="level">The compression level.</param>
|
||||
/// <param name="context">Context information for the compression.</param>
|
||||
/// <returns>A compression stream.</returns>
|
||||
/// <exception cref="InvalidOperationException">If no provider is registered for the type.</exception>
|
||||
/// <exception cref="ArchiveOperationException">If no provider is registered for the type.</exception>
|
||||
/// <exception cref="NotSupportedException">If the provider does not support compression.</exception>
|
||||
public Stream CreateCompressStream(
|
||||
CompressionType type,
|
||||
@@ -116,7 +116,7 @@ public sealed class CompressionProviderRegistry
|
||||
var provider = GetProvider(type);
|
||||
if (provider is null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
$"No compression provider registered for type: {type}"
|
||||
);
|
||||
}
|
||||
@@ -130,7 +130,7 @@ public sealed class CompressionProviderRegistry
|
||||
/// <param name="source">The source stream.</param>
|
||||
/// <param name="context">Context information for the decompression.</param>
|
||||
/// <returns>A decompression stream.</returns>
|
||||
/// <exception cref="InvalidOperationException">If no provider is registered for the type.</exception>
|
||||
/// <exception cref="ArchiveOperationException">If no provider is registered for the type.</exception>
|
||||
/// <exception cref="NotSupportedException">If the provider does not support decompression.</exception>
|
||||
public Stream CreateDecompressStream(
|
||||
CompressionType type,
|
||||
@@ -141,7 +141,7 @@ public sealed class CompressionProviderRegistry
|
||||
var provider = GetProvider(type);
|
||||
if (provider is null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
$"No compression provider registered for type: {type}"
|
||||
);
|
||||
}
|
||||
@@ -156,7 +156,7 @@ public sealed class CompressionProviderRegistry
|
||||
/// <param name="level">The compression level.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>A task containing the compression stream.</returns>
|
||||
/// <exception cref="InvalidOperationException">If no provider is registered for the type.</exception>
|
||||
/// <exception cref="ArchiveOperationException">If no provider is registered for the type.</exception>
|
||||
/// <exception cref="NotSupportedException">If the provider does not support compression.</exception>
|
||||
public ValueTask<Stream> CreateCompressStreamAsync(
|
||||
CompressionType type,
|
||||
@@ -168,7 +168,7 @@ public sealed class CompressionProviderRegistry
|
||||
var provider = GetProvider(type);
|
||||
if (provider is null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
$"No compression provider registered for type: {type}"
|
||||
);
|
||||
}
|
||||
@@ -182,7 +182,7 @@ public sealed class CompressionProviderRegistry
|
||||
/// <param name="source">The source stream.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>A task containing the decompression stream.</returns>
|
||||
/// <exception cref="InvalidOperationException">If no provider is registered for the type.</exception>
|
||||
/// <exception cref="ArchiveOperationException">If no provider is registered for the type.</exception>
|
||||
/// <exception cref="NotSupportedException">If the provider does not support decompression.</exception>
|
||||
public ValueTask<Stream> CreateDecompressStreamAsync(
|
||||
CompressionType type,
|
||||
@@ -193,7 +193,7 @@ public sealed class CompressionProviderRegistry
|
||||
var provider = GetProvider(type);
|
||||
if (provider is null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
$"No compression provider registered for type: {type}"
|
||||
);
|
||||
}
|
||||
@@ -209,7 +209,7 @@ public sealed class CompressionProviderRegistry
|
||||
/// <param name="context">Context information for the compression.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>A task containing the compression stream.</returns>
|
||||
/// <exception cref="InvalidOperationException">If no provider is registered for the type.</exception>
|
||||
/// <exception cref="ArchiveOperationException">If no provider is registered for the type.</exception>
|
||||
/// <exception cref="NotSupportedException">If the provider does not support compression.</exception>
|
||||
public ValueTask<Stream> CreateCompressStreamAsync(
|
||||
CompressionType type,
|
||||
@@ -222,7 +222,7 @@ public sealed class CompressionProviderRegistry
|
||||
var provider = GetProvider(type);
|
||||
if (provider is null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
$"No compression provider registered for type: {type}"
|
||||
);
|
||||
}
|
||||
@@ -237,7 +237,7 @@ public sealed class CompressionProviderRegistry
|
||||
/// <param name="context">Context information for the decompression.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>A task containing the decompression stream.</returns>
|
||||
/// <exception cref="InvalidOperationException">If no provider is registered for the type.</exception>
|
||||
/// <exception cref="ArchiveOperationException">If no provider is registered for the type.</exception>
|
||||
/// <exception cref="NotSupportedException">If the provider does not support decompression.</exception>
|
||||
public ValueTask<Stream> CreateDecompressStreamAsync(
|
||||
CompressionType type,
|
||||
@@ -249,7 +249,7 @@ public sealed class CompressionProviderRegistry
|
||||
var provider = GetProvider(type);
|
||||
if (provider is null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
$"No compression provider registered for type: {type}"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using SharpCompress.Common;
|
||||
|
||||
namespace SharpCompress.Providers;
|
||||
|
||||
@@ -12,7 +13,7 @@ public abstract class ContextRequiredDecompressionProviderBase : DecompressionOn
|
||||
protected virtual string DecompressionContextRequirementSuffix => string.Empty;
|
||||
|
||||
public sealed override Stream CreateDecompressStream(Stream source) =>
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
$"{DecompressionContextRequirementDescription}. "
|
||||
+ $"Use CreateDecompressStream(Stream, CompressionContext) overload{DecompressionContextRequirementSuffix}."
|
||||
);
|
||||
@@ -21,7 +22,7 @@ public abstract class ContextRequiredDecompressionProviderBase : DecompressionOn
|
||||
Stream source,
|
||||
CancellationToken cancellationToken = default
|
||||
) =>
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
$"{DecompressionContextRequirementDescription}. "
|
||||
+ "Use CreateDecompressStreamAsync(Stream, CompressionContext, CancellationToken) "
|
||||
+ $"overload{DecompressionContextRequirementSuffix}."
|
||||
|
||||
@@ -19,7 +19,7 @@ public sealed class LzmaCompressingProvider : CompressionProviderBase, ICompress
|
||||
|
||||
public override Stream CreateCompressStream(Stream destination, int compressionLevel)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
"LZMA compression requires context with CanSeek information. "
|
||||
+ "Use CreateCompressStream(Stream, int, CompressionContext) overload."
|
||||
);
|
||||
@@ -39,7 +39,7 @@ public sealed class LzmaCompressingProvider : CompressionProviderBase, ICompress
|
||||
|
||||
public override Stream CreateDecompressStream(Stream source)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
"LZMA decompression requires properties. "
|
||||
+ "Use CreateDecompressStream(Stream, CompressionContext) overload with Properties."
|
||||
);
|
||||
@@ -62,7 +62,7 @@ public sealed class LzmaCompressingProvider : CompressionProviderBase, ICompress
|
||||
Stream source,
|
||||
CancellationToken cancellationToken = default
|
||||
) =>
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
"LZMA decompression requires properties. "
|
||||
+ "Use CreateDecompressStreamAsync(Stream, CompressionContext, CancellationToken) overload with Properties."
|
||||
);
|
||||
|
||||
@@ -41,7 +41,7 @@ public sealed class PpmdCompressingProvider : CompressionProviderBase, ICompress
|
||||
|
||||
public override Stream CreateDecompressStream(Stream source)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
"PPMd decompression requires properties. "
|
||||
+ "Use CreateDecompressStream(Stream, CompressionContext) overload with Properties."
|
||||
);
|
||||
@@ -65,7 +65,7 @@ public sealed class PpmdCompressingProvider : CompressionProviderBase, ICompress
|
||||
Stream source,
|
||||
CancellationToken cancellationToken = default
|
||||
) =>
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
"PPMd decompression requires properties. "
|
||||
+ "Use CreateDecompressStreamAsync(Stream, CompressionContext, CancellationToken) overload with Properties."
|
||||
);
|
||||
|
||||
@@ -89,7 +89,7 @@ public abstract partial class AbstractReader<TEntry, TVolume> : IReader, IAsyncR
|
||||
{
|
||||
if (_entriesForCurrentReadStreamAsync is not null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
$"{nameof(MoveToNextEntry)} cannot be used after {nameof(MoveToNextEntryAsync)} has been used."
|
||||
);
|
||||
}
|
||||
@@ -122,7 +122,7 @@ public abstract partial class AbstractReader<TEntry, TVolume> : IReader, IAsyncR
|
||||
{
|
||||
if (_entriesForCurrentReadStreamAsync is not null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
throw new ArchiveOperationException(
|
||||
$"{nameof(LoadStreamForReading)} cannot be used after {nameof(LoadStreamForReadingAsync)} has been used."
|
||||
);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public abstract partial class RarReader
|
||||
{
|
||||
if (Entry.IsRedir)
|
||||
{
|
||||
throw new InvalidOperationException("no stream for redirect entry");
|
||||
throw new ArchiveOperationException("no stream for redirect entry");
|
||||
}
|
||||
|
||||
var stream = await MultiVolumeReadOnlyAsyncStream
|
||||
|
||||
@@ -114,7 +114,7 @@ public abstract partial class RarReader : AbstractReader<RarReaderEntry, RarVolu
|
||||
{
|
||||
if (Entry.IsRedir)
|
||||
{
|
||||
throw new InvalidOperationException("no stream for redirect entry");
|
||||
throw new ArchiveOperationException("no stream for redirect entry");
|
||||
}
|
||||
|
||||
var stream = new MultiVolumeReadOnlyStream(
|
||||
|
||||
@@ -63,7 +63,7 @@ public partial class ZipReader
|
||||
}
|
||||
|
||||
public ZipEntry Current =>
|
||||
_current ?? throw new InvalidOperationException("No current entry is available.");
|
||||
_current ?? throw new ArchiveOperationException("No current entry is available.");
|
||||
|
||||
/// <summary>
|
||||
/// Advances to the next non-directory entry-relevant header and materializes a <see cref="ZipEntry"/>,
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user