Skip to content

Commit

Permalink
Fix usings and add braces for better merging
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhathcock committed Apr 3, 2020
1 parent 762497b commit 400d2c1
Show file tree
Hide file tree
Showing 60 changed files with 736 additions and 66 deletions.
5 changes: 4 additions & 1 deletion SharpCompress.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,7 @@
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002ECSharpPlaceAttributeOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean>
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=6af8f80e_002D9fdd_002D4223_002D8e02_002D473db916f9b2/@EntryIndexedValue">&lt;SessionState ContinuousTestingIsOn="False" ContinuousTestingMode="0" FrameworkVersion="{x:Null}" IsLocked="False" Name="All tests from Solution" PlatformMonoPreference="{x:Null}" PlatformType="{x:Null}" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
&lt;Solution /&gt;
&lt;/SessionState&gt;</s:String></wpf:ResourceDictionary>
1 change: 0 additions & 1 deletion src/SharpCompress/Common/GZip/GZipEntry.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace SharpCompress.Common.GZip
{
Expand Down
1 change: 0 additions & 1 deletion src/SharpCompress/Common/IEntry.Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.IO;
using SharpCompress.Readers;

namespace SharpCompress.Common
{
Expand Down
4 changes: 3 additions & 1 deletion src/SharpCompress/Common/Rar/Headers/AVHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ internal class AvHeader : RarHeader
public AvHeader(RarHeader header, RarCrcBinaryReader reader)
: base(header, reader, HeaderType.Av)
{
if (IsRar5)
if (IsRar5)
{
throw new InvalidFormatException("unexpected rar5 record");
}
}

protected override void ReadFinish(MarkingBinaryReader reader)
Expand Down
6 changes: 5 additions & 1 deletion src/SharpCompress/Common/Rar/Headers/ArchiveHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ protected override void ReadFinish(MarkingBinaryReader reader)
private void ReadLocator(MarkingBinaryReader reader) {
var size = reader.ReadRarVIntUInt16();
var type = reader.ReadRarVIntUInt16();
if (type != 1) throw new InvalidFormatException("expected locator record");
if (type != 1)
{
throw new InvalidFormatException("expected locator record");
}

var flags = reader.ReadRarVIntUInt16();
const ushort hasQuickOpenOffset = 0x01;
const ushort hasRecoveryOffset = 0x02;
Expand Down
5 changes: 4 additions & 1 deletion src/SharpCompress/Common/Rar/Headers/CommentHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ internal class CommentHeader : RarHeader
protected CommentHeader(RarHeader header, RarCrcBinaryReader reader)
: base(header, reader, HeaderType.Comment)
{
if (IsRar5) throw new InvalidFormatException("unexpected rar5 record");
if (IsRar5)
{
throw new InvalidFormatException("unexpected rar5 record");
}
}

protected override void ReadFinish(MarkingBinaryReader reader)
Expand Down
41 changes: 34 additions & 7 deletions src/SharpCompress/Common/Rar/Headers/MarkHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,38 @@ public static MarkHeader Read(Stream stream, bool leaveStreamOpen, bool lookForH
if (b == 0x61)
{
b = GetByte(stream); start++;
if (b != 0x72) continue;
if (b != 0x72)
{
continue;
}

b = GetByte(stream); start++;
if (b != 0x21) continue;
if (b != 0x21)
{
continue;
}

b = GetByte(stream); start++;
if (b != 0x1a) continue;
if (b != 0x1a)
{
continue;
}

b = GetByte(stream); start++;
if (b != 0x07) continue;
if (b != 0x07)
{
continue;
}

b = GetByte(stream); start++;
if (b == 1)
{
b = GetByte(stream); start++;
if (b != 0) continue;
if (b != 0)
{
continue;
}

return new MarkHeader(true); // Rar5
}
else if (b == 0)
Expand All @@ -69,9 +88,17 @@ public static MarkHeader Read(Stream stream, bool leaveStreamOpen, bool lookForH
else if (b == 0x45)
{
b = GetByte(stream); start++;
if (b != 0x7e) continue;
if (b != 0x7e)
{
continue;
}

b = GetByte(stream); start++;
if (b != 0x5e) continue;
if (b != 0x5e)
{
continue;
}

throw new InvalidFormatException("Rar format version pre-4 is unsupported.");
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/SharpCompress/Common/Rar/Headers/ProtectHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ internal class ProtectHeader : RarHeader
public ProtectHeader(RarHeader header, RarCrcBinaryReader reader)
: base(header, reader, HeaderType.Protect)
{
if (IsRar5) throw new InvalidFormatException("unexpected rar5 record");
if (IsRar5)
{
throw new InvalidFormatException("unexpected rar5 record");
}
}

protected override void ReadFinish(MarkingBinaryReader reader)
Expand Down
1 change: 0 additions & 1 deletion src/SharpCompress/Common/Rar/Headers/RarHeaderFactory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.IO;
using SharpCompress.IO;
Expand Down
5 changes: 4 additions & 1 deletion src/SharpCompress/Common/Rar/Headers/SignHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ internal class SignHeader : RarHeader
protected SignHeader(RarHeader header, RarCrcBinaryReader reader)
: base(header, reader, HeaderType.Sign)
{
if (IsRar5) throw new InvalidFormatException("unexpected rar5 record");
if (IsRar5)
{
throw new InvalidFormatException("unexpected rar5 record");
}
}

protected override void ReadFinish(MarkingBinaryReader reader)
Expand Down
1 change: 0 additions & 1 deletion src/SharpCompress/Common/SevenZip/SevenZipVolume.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.IO;
using SharpCompress.Archives;
using SharpCompress.Readers;

namespace SharpCompress.Common.SevenZip
Expand Down
1 change: 0 additions & 1 deletion src/SharpCompress/Common/Tar/TarEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.IO;
using SharpCompress.Common.Tar.Headers;
using SharpCompress.IO;
using System.Text;

namespace SharpCompress.Common.Tar
{
Expand Down
1 change: 0 additions & 1 deletion src/SharpCompress/Common/Tar/TarHeaderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.IO;
using SharpCompress.Common.Tar.Headers;
using SharpCompress.IO;
using System.Text;

namespace SharpCompress.Common.Tar
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.IO;
using System.Linq;
using System.Text;

namespace SharpCompress.Common.Zip.Headers
{
Expand Down
3 changes: 1 addition & 2 deletions src/SharpCompress/Common/Zip/Headers/IgnoreHeader.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.IO;
using System.IO;

namespace SharpCompress.Common.Zip.Headers
{
Expand Down
1 change: 0 additions & 1 deletion src/SharpCompress/Common/Zip/Headers/LocalEntryHeader.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.IO;
using System.Linq;
using System.Text;

namespace SharpCompress.Common.Zip.Headers
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.IO;
using System.IO;

namespace SharpCompress.Common.Zip.Headers
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Text;
using SharpCompress.Common.Zip.Headers;
using SharpCompress.Compressors.Deflate;

Expand Down
5 changes: 4 additions & 1 deletion src/SharpCompress/Common/Zip/SeekableZipHeaderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.IO;
using SharpCompress.Common.Zip.Headers;
using SharpCompress.IO;
using System.Text;

namespace SharpCompress.Common.Zip
{
Expand Down Expand Up @@ -35,7 +34,9 @@ internal IEnumerable<ZipHeader> ReadSeekableHeader(Stream stream)
stream.Seek(zip64Locator.RelativeOffsetOfTheEndOfDirectoryRecord, SeekOrigin.Begin);
uint zip64Signature = reader.ReadUInt32();
if (zip64Signature != ZIP64_END_OF_CENTRAL_DIRECTORY)
{
throw new ArchiveException("Failed to locate the Zip64 Header");
}

var zip64Entry = new Zip64DirectoryEndHeader();
zip64Entry.Read(reader);
Expand All @@ -55,7 +56,9 @@ internal IEnumerable<ZipHeader> ReadSeekableHeader(Stream stream)
position = stream.Position;

if (nextHeader == null)
{
yield break;
}

if (nextHeader is DirectoryEntryHeader entryHeader)
{
Expand Down
1 change: 0 additions & 1 deletion src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.IO;
using SharpCompress.Common.Zip.Headers;
using SharpCompress.IO;
using System.Text;

namespace SharpCompress.Common.Zip
{
Expand Down
1 change: 0 additions & 1 deletion src/SharpCompress/Common/Zip/ZipHeaderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Linq;
using SharpCompress.Common.Zip.Headers;
using SharpCompress.IO;
using System.Text;

namespace SharpCompress.Common.Zip
{
Expand Down
29 changes: 28 additions & 1 deletion src/SharpCompress/Compressors/Deflate64/Deflate64Stream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.

using SharpCompress.Common.Zip;
using SharpCompress.Compressors.Deflate;
using System;
using System.Diagnostics;
using System.IO;
Expand All @@ -23,11 +22,19 @@ public sealed class Deflate64Stream : Stream
public Deflate64Stream(Stream stream, CompressionMode mode)
{
if (stream == null)
{
throw new ArgumentNullException(nameof(stream));
}

if (mode != CompressionMode.Decompress)
{
throw new NotImplementedException("Deflate64: this implementation only supports decompression");
}

if (!stream.CanRead)
{
throw new ArgumentException("Deflate64: input stream is not readable", nameof(stream));
}

InitializeInflater(stream, ZipCompressionMethod.Deflate64);
}
Expand All @@ -40,7 +47,9 @@ private void InitializeInflater(Stream stream, ZipCompressionMethod method = Zip
Debug.Assert(stream != null);
Debug.Assert(method == ZipCompressionMethod.Deflate || method == ZipCompressionMethod.Deflate64);
if (!stream.CanRead)
{
throw new ArgumentException("Deflate64: input stream is not readable", nameof(stream));
}

_inflater = new InflaterManaged(method == ZipCompressionMethod.Deflate64);

Expand Down Expand Up @@ -152,22 +161,32 @@ public override int Read(byte[] array, int offset, int count)
private void ValidateParameters(byte[] array, int offset, int count)
{
if (array == null)
{
throw new ArgumentNullException(nameof(array));
}

if (offset < 0)
{
throw new ArgumentOutOfRangeException(nameof(offset));
}

if (count < 0)
{
throw new ArgumentOutOfRangeException(nameof(count));
}

if (array.Length - offset < count)
{
throw new ArgumentException("Deflate64: invalid offset/count combination");
}
}

private void EnsureNotDisposed()
{
if (_stream == null)
{
ThrowStreamClosedException();
}
}

[MethodImpl(MethodImplOptions.NoInlining)]
Expand All @@ -179,7 +198,9 @@ private static void ThrowStreamClosedException()
private void EnsureDecompressionMode()
{
if (_mode != CompressionMode.Decompress)
{
ThrowCannotReadFromDeflateManagedStreamException();
}
}

[MethodImpl(MethodImplOptions.NoInlining)]
Expand All @@ -191,7 +212,9 @@ private static void ThrowCannotReadFromDeflateManagedStreamException()
private void EnsureCompressionMode()
{
if (_mode != CompressionMode.Compress)
{
ThrowCannotWriteToDeflateManagedStreamException();
}
}

[MethodImpl(MethodImplOptions.NoInlining)]
Expand All @@ -209,10 +232,14 @@ public override void Write(byte[] array, int offset, int count)
private void PurgeBuffers(bool disposing)
{
if (!disposing)
{
return;
}

if (_stream == null)
{
return;
}

Flush();
}
Expand Down
5 changes: 5 additions & 0 deletions src/SharpCompress/Compressors/Deflate64/HuffmanTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,14 @@ public int GetNextSymbol(InputBuffer input)
{
symbol = -symbol;
if ((bitBuffer & mask) == 0)
{
symbol = _left[symbol];
}
else
{
symbol = _right[symbol];
}

mask <<= 1;
} while (symbol < 0);
}
Expand Down
2 changes: 2 additions & 0 deletions src/SharpCompress/Compressors/Deflate64/InflaterManaged.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ private bool Decode()
// reading bfinal bit
// Need 1 bit
if (!_input.EnsureBitsAvailable(1))
{
return false;
}

_bfinal = _input.GetBits(1);
_state = InflaterState.ReadingBType;
Expand Down
Loading

0 comments on commit 400d2c1

Please sign in to comment.