Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/SharpCompress/Archives/ArchiveFactory.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static async ValueTask<IAsyncArchive> OpenAsyncArchive(
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];
Expand Down Expand Up @@ -91,7 +91,7 @@ public static async ValueTask<IAsyncArchive> OpenAsyncArchive(
var streamsArray = streams.ToArray();
if (streamsArray.Length == 0)
{
throw new InvalidOperationException("No streams");
throw new ArchiveOperationException("No streams");
}

var firstStream = streamsArray[0];
Expand Down Expand Up @@ -164,7 +164,7 @@ await factory

var extensions = string.Join(", ", factories.Select(item => item.Name));

throw new InvalidOperationException(
throw new ArchiveOperationException(
$"Cannot determine compressed stream type. Supported Archive Formats: {extensions}"
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/SharpCompress/Archives/ArchiveFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static IArchive OpenArchive(
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];
Expand All @@ -75,7 +75,7 @@ public static IArchive OpenArchive(IEnumerable<Stream> streams, ReaderOptions? o
var streamsArray = streams.ToArray();
if (streamsArray.Length == 0)
{
throw new InvalidOperationException("No streams");
throw new ArchiveOperationException("No streams");
}

var firstStream = streamsArray[0];
Expand Down Expand Up @@ -143,7 +143,7 @@ public static T FindFactory<T>(Stream stream)

var extensions = string.Join(", ", factories.Select(item => item.Name));

throw new InvalidOperationException(
throw new ArchiveOperationException(
$"Cannot determine compressed stream type. Supported Archive Formats: {extensions}"
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/SharpCompress/Archives/ArchiveVolumeFactory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Text.RegularExpressions;
using SharpCompress.Common;

namespace SharpCompress.Archives;

Expand All @@ -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')
)
)
Expand Down
3 changes: 2 additions & 1 deletion src/SharpCompress/Archives/Rar/RarArchiveVolumeFactory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Text.RegularExpressions;
using SharpCompress.Common;

namespace SharpCompress.Archives.Rar;

Expand All @@ -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
)
Expand Down
5 changes: 2 additions & 3 deletions src/SharpCompress/Archives/Zip/ZipArchiveVolumeFactory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Text.RegularExpressions;
using SharpCompress.Common;

namespace SharpCompress.Archives.Zip;

Expand All @@ -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')
)
)
);
Expand Down
2 changes: 1 addition & 1 deletion src/SharpCompress/Common/Ace/Headers/AceHeader.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async ValueTask<byte[]> ReadHeaderAsync(
var checksum = AceCrc.AceCrc16(body);
if (checksum != HeaderCrc)
{
throw new InvalidDataException("Header checksum is invalid");
throw new InvalidFormatException("Header checksum is invalid");
}
return body;
}
Expand Down
2 changes: 1 addition & 1 deletion src/SharpCompress/Common/Ace/Headers/AceHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public byte[] ReadHeader(Stream stream)
var checksum = AceCrc.AceCrc16(body);
if (checksum != HeaderCrc)
{
throw new InvalidDataException("Header checksum is invalid");
throw new InvalidFormatException("Header checksum is invalid");
}
return body;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/SharpCompress/Common/Ace/Headers/AceMainHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public AceMainHeader(IArchiveEncoding archiveEncoding)
// 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;

Expand Down
12 changes: 6 additions & 6 deletions src/SharpCompress/Common/Arj/Headers/ArjHeader.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async ValueTask<byte[]> ReadHeaderAsync(

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
Expand All @@ -55,7 +55,7 @@ public async ValueTask<byte[]> ReadHeaderAsync(
// 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;
}
Expand All @@ -75,7 +75,7 @@ protected async ValueTask<List<byte[]>> ReadExtendedHeadersAsync(
.ConfigureAwait(false);
if (bytesRead < 2)
{
throw new EndOfStreamException(
throw new IncompleteArchiveException(
"Unexpected end of stream while reading extended header size."
);
}
Expand All @@ -92,7 +92,7 @@ protected async ValueTask<List<byte[]>> ReadExtendedHeadersAsync(
.ConfigureAwait(false);
if (bytesRead < extHeaderSize)
{
throw new EndOfStreamException(
throw new IncompleteArchiveException(
"Unexpected end of stream while reading extended header data."
);
}
Expand All @@ -103,15 +103,15 @@ protected async ValueTask<List<byte[]>> ReadExtendedHeadersAsync(
.ConfigureAwait(false);
if (bytesRead < 4)
{
throw new EndOfStreamException(
throw new IncompleteArchiveException(
"Unexpected end of stream while reading extended header CRC."
);
}

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);
Expand Down
12 changes: 6 additions & 6 deletions src/SharpCompress/Common/Arj/Headers/ArjHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public byte[] ReadHeader(Stream stream)

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
Expand All @@ -69,7 +69,7 @@ public byte[] ReadHeader(Stream stream)
// 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;
}
Expand All @@ -86,7 +86,7 @@ protected List<byte[]> ReadExtendedHeaders(Stream reader)
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."
);
}
Expand All @@ -101,7 +101,7 @@ protected List<byte[]> ReadExtendedHeaders(Stream reader)
bytesRead = reader.Read(header, 0, extHeaderSize);
if (bytesRead < extHeaderSize)
{
throw new EndOfStreamException(
throw new IncompleteArchiveException(
"Unexpected end of stream while reading extended header data."
);
}
Expand All @@ -110,15 +110,15 @@ protected List<byte[]> ReadExtendedHeaders(Stream reader)
bytesRead = reader.Read(crc, 0, 4);
if (bytesRead < 4)
{
throw new EndOfStreamException(
throw new IncompleteArchiveException(
"Unexpected end of stream while reading extended header CRC."
);
}

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);
Expand Down
4 changes: 2 additions & 2 deletions src/SharpCompress/Common/Arj/Headers/ArjLocalHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ int ReadInt16()
{
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;
Expand All @@ -76,7 +76,7 @@ long ReadInt32()
{
if (offset + 3 >= headerBytes.Length)
{
throw new EndOfStreamException();
throw new IncompleteArchiveException("Unexpected end of stream.");
}
long v =
headerBytes[offset] & 0xFF
Expand Down
6 changes: 3 additions & 3 deletions src/SharpCompress/Common/Arj/Headers/ArjMainHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ byte ReadByte()
{
if (offset >= headerBytes.Length)
{
throw new EndOfStreamException();
throw new IncompleteArchiveException("Unexpected end of stream.");
}
return (byte)(headerBytes[offset++] & 0xFF);
}
Expand All @@ -63,7 +63,7 @@ int ReadInt16()
{
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;
Expand All @@ -74,7 +74,7 @@ long ReadInt32()
{
if (offset + 3 >= headerBytes.Length)
{
throw new EndOfStreamException();
throw new IncompleteArchiveException("Unexpected end of stream.");
}
long v =
headerBytes[offset] & 0xFF
Expand Down
4 changes: 2 additions & 2 deletions src/SharpCompress/Common/Rar/AsyncMarkingBinaryReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ CancellationToken cancellationToken
shift += 7;
} while (shift <= maxShift);

throw new FormatException("malformed vint");
throw new InvalidFormatException("malformed vint");
}

public async ValueTask<uint> ReadRarVIntUInt32Async(
Expand Down Expand Up @@ -188,7 +188,7 @@ private async ValueTask<uint> DoReadRarVIntUInt32Async(
shift += 7;
} while (shift <= maxShift);

throw new FormatException("malformed vint");
throw new InvalidFormatException("malformed vint");
}

public virtual void Dispose() => _reader.Dispose();
Expand Down
2 changes: 1 addition & 1 deletion src/SharpCompress/Common/Rar/Headers/MarkHeader.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ CancellationToken cancellationToken
{
return buffer[0];
}
throw new EndOfStreamException();
throw new IncompleteArchiveException("Unexpected end of stream.");
}

public static async ValueTask<MarkHeader> ReadAsync(
Expand Down
2 changes: 1 addition & 1 deletion src/SharpCompress/Common/Rar/Headers/MarkHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private static byte GetByte(Stream stream)
{
return (byte)b;
}
throw new EndOfStreamException();
throw new IncompleteArchiveException("Unexpected end of stream.");
}

public static MarkHeader Read(Stream stream, bool leaveStreamOpen, bool lookForHeader)
Expand Down
2 changes: 1 addition & 1 deletion src/SharpCompress/Common/Rar/RarEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected RarEntry(IReaderOptions readerOptions)

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,
Expand Down
4 changes: 2 additions & 2 deletions src/SharpCompress/Common/Rar/RarVolume.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private void EnsureArchiveHeaderLoaded()
{
if (Mode == StreamingMode.Streaming)
{
throw new InvalidOperationException(
throw new ArchiveOperationException(
"ArchiveHeader should never been null in a streaming read."
);
}
Expand Down Expand Up @@ -243,7 +243,7 @@ private async ValueTask EnsureArchiveHeaderLoadedAsync(CancellationToken cancell
{
if (Mode == StreamingMode.Streaming)
{
throw new InvalidOperationException(
throw new ArchiveOperationException(
"ArchiveHeader should never been null in a streaming read."
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/SharpCompress/Common/SevenZip/ArchiveDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private void FillFolderStartFileIndex()
{
if (folderIndex >= _folders.Count)
{
throw new InvalidOperationException();
throw new ArchiveOperationException();
}

_folderStartFileIndex.Add(i); // check it
Expand Down
Loading