Skip to content

Commit

Permalink
get rid of more ! and update csharpier
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Hathcock committed Apr 22, 2024
1 parent fb55624 commit b550df2
Show file tree
Hide file tree
Showing 30 changed files with 163 additions and 153 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"csharpier": {
"version": "0.27.3",
"version": "0.28.1",
"commands": [
"dotnet-csharpier"
]
Expand Down
1 change: 0 additions & 1 deletion src/SharpCompress/Archives/AbstractArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ internal AbstractArchive(ArchiveType type)
lazyEntries = new LazyReadOnlyCollection<TEntry>(Enumerable.Empty<TEntry>());
}


public ArchiveType Type { get; }

void IArchiveExtractionListener.FireEntryExtractionBegin(IArchiveEntry entry) =>
Expand Down
6 changes: 5 additions & 1 deletion src/SharpCompress/Archives/GZip/GZipArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,11 @@ IEnumerable<GZipArchiveEntry> newEntries
foreach (var entry in oldEntries.Concat(newEntries).Where(x => !x.IsDirectory))
{
using var entryStream = entry.OpenEntryStream();
writer.Write(entry.Key.NotNull("Entry Key is null"), entryStream, entry.LastModifiedTime);
writer.Write(
entry.Key.NotNull("Entry Key is null"),
entryStream,
entry.LastModifiedTime
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/SharpCompress/Archives/Rar/RarArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal RarArchive(SourceStream srcStream)
protected override IEnumerable<RarVolume> LoadVolumes(SourceStream srcStream)
{
var sourceStream = SrcStream.NotNull("SourceStream is null");
sourceStream .LoadAllParts(); //request all streams
sourceStream.LoadAllParts(); //request all streams
var streams = sourceStream.Streams.ToArray();
var idx = 0;
if (streams.Length > 1 && IsRarFile(streams[1], ReaderOptions)) //test part 2 - true = multipart not split
Expand Down
10 changes: 8 additions & 2 deletions src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ private static bool SignatureMatch(Stream stream)
public override bool IsSolid =>
Entries.Where(x => !x.IsDirectory).GroupBy(x => x.FilePart.Folder).Count() > 1;

public override long TotalSize => database?._packSizes.Aggregate(0L, (total, packSize) => total + packSize) ?? 0;
public override long TotalSize =>
database?._packSizes.Aggregate(0L, (total, packSize) => total + packSize) ?? 0;

private sealed class SevenZipReader : AbstractReader<SevenZipEntry, SevenZipVolume>
{
Expand Down Expand Up @@ -245,7 +246,12 @@ protected override IEnumerable<SevenZipEntry> GetEntries(Stream stream)
}

protected override EntryStream GetEntryStream() =>
CreateEntryStream(new ReadOnlySubStream(currentStream.NotNull("currentStream is not null"), currentItem?.Size ?? 0));
CreateEntryStream(
new ReadOnlySubStream(
currentStream.NotNull("currentStream is not null"),
currentItem?.Size ?? 0
)
);
}

private class PasswordProvider : IPasswordProvider
Expand Down
7 changes: 6 additions & 1 deletion src/SharpCompress/Archives/Tar/TarArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,12 @@ IEnumerable<TarArchiveEntry> newEntries
foreach (var entry in oldEntries.Concat(newEntries).Where(x => !x.IsDirectory))
{
using var entryStream = entry.OpenEntryStream();
writer.Write(entry.Key.NotNull("Entry Key is null"), entryStream, entry.LastModifiedTime, entry.Size);
writer.Write(
entry.Key.NotNull("Entry Key is null"),
entryStream,
entry.LastModifiedTime,
entry.Size
);
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/SharpCompress/Archives/Zip/ZipArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ protected override IEnumerable<ZipVolume> LoadVolumes(SourceStream srcStream)

var streams = stream.Streams.ToList();
var idx = 0;
if (streams.Count > 1) //test part 2 - true = multipart not split
if (streams.Count() > 1) //test part 2 - true = multipart not split
{
streams[1].Position += 4; //skip the POST_DATA_DESCRIPTOR to prevent an exception
var isZip = IsZipFile(streams[1], ReaderOptions.Password);
Expand Down Expand Up @@ -229,7 +229,6 @@ protected override IEnumerable<ZipArchiveEntry> LoadEntries(IEnumerable<ZipVolum
switch (h.ZipHeaderType)
{
case ZipHeaderType.DirectoryEntry:

{
var deh = (DirectoryEntryHeader)h;
Stream s;
Expand Down Expand Up @@ -280,7 +279,11 @@ IEnumerable<ZipArchiveEntry> newEntries
foreach (var entry in oldEntries.Concat(newEntries).Where(x => !x.IsDirectory))
{
using var entryStream = entry.OpenEntryStream();
writer.Write(entry.Key.NotNull("Entry Key is null"), entryStream, entry.LastModifiedTime);
writer.Write(
entry.Key.NotNull("Entry Key is null"),
entryStream,
entry.LastModifiedTime
);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/SharpCompress/Common/ExtractionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ internal static class ExtractionMethods
var file = Path.GetFileName(entry.Key.NotNull("Entry Key is null")).NotNull("File is null");
if (options.ExtractFullPath)
{
var folder = Path.GetDirectoryName(entry.Key.NotNull("Entry Key is null")).NotNull("Directory is null");
var folder = Path.GetDirectoryName(entry.Key.NotNull("Entry Key is null"))
.NotNull("Directory is null");
var destdir = Path.GetFullPath(Path.Combine(fullDestinationDirectoryPath, folder));

if (!Directory.Exists(destdir))
Expand Down
6 changes: 0 additions & 6 deletions src/SharpCompress/Common/Rar/Headers/FileHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ private void ReadFromReaderV5(MarkingBinaryReader reader)
switch (type)
{
case FHEXTRA_CRYPT: // file encryption

{
Rar5CryptoInfo = new Rar5CryptoInfo(reader, true);

Expand All @@ -132,7 +131,6 @@ private void ReadFromReaderV5(MarkingBinaryReader reader)
}
break;
case FHEXTRA_HASH:

{
const uint FHEXTRA_HASH_BLAKE2 = 0x0;
// const uint HASH_BLAKE2 = 0x03;
Expand All @@ -146,7 +144,6 @@ private void ReadFromReaderV5(MarkingBinaryReader reader)
}
break;
case FHEXTRA_HTIME: // file time

{
var flags = reader.ReadRarVIntUInt16();
var isWindowsTime = (flags & 1) == 0;
Expand All @@ -171,7 +168,6 @@ private void ReadFromReaderV5(MarkingBinaryReader reader)
// }
// break;
case FHEXTRA_REDIR: // file system redirection

{
RedirType = reader.ReadRarVIntByte();
RedirFlags = reader.ReadRarVIntByte();
Expand Down Expand Up @@ -284,7 +280,6 @@ private void ReadFromReaderV4(MarkingBinaryReader reader)
switch (HeaderCode)
{
case HeaderCodeV.RAR4_FILE_HEADER:

{
if (HasFlag(FileFlagsV4.UNICODE))
{
Expand All @@ -311,7 +306,6 @@ private void ReadFromReaderV4(MarkingBinaryReader reader)
}
break;
case HeaderCodeV.RAR4_NEW_SUB_HEADER:

{
var datasize = HeaderSize - newLhdSize - nameSize;
if (HasFlag(FileFlagsV4.SALT))
Expand Down
6 changes: 0 additions & 6 deletions src/SharpCompress/Common/Rar/Headers/RarHeaderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,11 @@ public IEnumerable<IRarHeader> ReadHeaders(Stream stream)
switch (StreamingMode)
{
case StreamingMode.Seekable:

{
reader.BaseStream.Position += ph.DataSize;
}
break;
case StreamingMode.Streaming:

{
reader.BaseStream.Skip(ph.DataSize);
}
Expand Down Expand Up @@ -146,14 +144,12 @@ public IEnumerable<IRarHeader> ReadHeaders(Stream stream)
switch (StreamingMode)
{
case StreamingMode.Seekable:

{
fh.DataStartPosition = reader.BaseStream.Position;
reader.BaseStream.Position += fh.CompressedSize;
}
break;
case StreamingMode.Streaming:

{
var ms = new ReadOnlySubStream(reader.BaseStream, fh.CompressedSize);
if (fh.R4Salt is null && fh.Rar5CryptoInfo is null)
Expand Down Expand Up @@ -204,14 +200,12 @@ private void SkipData(FileHeader fh, RarCrcBinaryReader reader)
switch (StreamingMode)
{
case StreamingMode.Seekable:

{
fh.DataStartPosition = reader.BaseStream.Position;
reader.BaseStream.Position += fh.CompressedSize;
}
break;
case StreamingMode.Streaming:

{
//skip the data because it's useless?
reader.BaseStream.Skip(fh.CompressedSize);
Expand Down
4 changes: 0 additions & 4 deletions src/SharpCompress/Common/Rar/RarVolume.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,16 @@ internal IEnumerable<RarFilePart> GetVolumeFileParts()
switch (header.HeaderType)
{
case HeaderType.Mark:

{
lastMarkHeader = (MarkHeader)header;
}
break;
case HeaderType.Archive:

{
ArchiveHeader = (ArchiveHeader)header;
}
break;
case HeaderType.File:

{
var fh = (FileHeader)header;
if (_maxCompressionAlgorithm < fh.CompressionAlgorithm)
Expand All @@ -63,7 +60,6 @@ internal IEnumerable<RarFilePart> GetVolumeFileParts()
}
break;
case HeaderType.Service:

{
var fh = (FileHeader)header;
if (fh.FileName == "CMT")
Expand Down
9 changes: 5 additions & 4 deletions src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ public CompressionType CompressionType
internal CompressionType GetCompression()
{
if (Header.IsDir)
{
return CompressionType.None;
}

var coder = Folder!._coders.First();
var coder = Folder.NotNull()._coders.First();
switch (coder._methodId._id)
{
case K_LZMA:
Expand All @@ -100,7 +102,6 @@ internal CompressionType GetCompression()
}

internal bool IsEncrypted =>
Header.IsDir
? false
: Folder!._coders.FindIndex(c => c._methodId._id == CMethodId.K_AES_ID) != -1;
!Header.IsDir
&& Folder?._coders.FindIndex(c => c._methodId._id == CMethodId.K_AES_ID) != -1;
}
4 changes: 3 additions & 1 deletion src/SharpCompress/Common/Tar/Headers/TarHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ internal void Write(Stream output)
WriteOctalBytes(0, buffer, 116, 8); // group ID

//ArchiveEncoding.UTF8.GetBytes("magic").CopyTo(buffer, 257);
var nameByteCount = ArchiveEncoding.GetEncoding().GetByteCount(Name.NotNull("Name is null"));
var nameByteCount = ArchiveEncoding
.GetEncoding()
.GetByteCount(Name.NotNull("Name is null"));
if (nameByteCount > 100)
{
// Set mock filename and filetype to indicate the next block is the actual name of the file
Expand Down
2 changes: 1 addition & 1 deletion src/SharpCompress/Common/Tar/TarFilePart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal override Stream GetCompressedStream()
{
if (_seekableStream != null)
{
_seekableStream.Position = Header.DataStartPosition!.Value;
_seekableStream.Position = Header.DataStartPosition ?? 0;
return new TarReadOnlySubStream(_seekableStream, Header.Size);
}
return Header.PackedStream.NotNull();
Expand Down
2 changes: 0 additions & 2 deletions src/SharpCompress/Common/Tar/TarHeaderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ ArchiveEncoding archiveEncoding
switch (mode)
{
case StreamingMode.Seekable:

{
header.DataStartPosition = reader.BaseStream.Position;

Expand All @@ -37,7 +36,6 @@ ArchiveEncoding archiveEncoding
}
break;
case StreamingMode.Streaming:

{
header.PackedStream = new TarReadOnlySubStream(stream, header.Size);
}
Expand Down
8 changes: 4 additions & 4 deletions src/SharpCompress/Common/Zip/SeekableZipFilePart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ private void LoadLocalHeader()

protected override Stream CreateBaseStream()
{
BaseStream.Position = Header.DataStartPosition!.Value;
BaseStream.Position = Header.DataStartPosition.NotNull();

if (
(Header.CompressedSize == 0)
&& FlagUtility.HasFlag(Header.Flags, HeaderFlags.UsePostDataDescriptor)
&& (_directoryEntryHeader?.HasData == true)
&& (_directoryEntryHeader?.CompressedSize != 0)
&& _directoryEntryHeader.HasData
&& (_directoryEntryHeader.CompressedSize != 0)
)
{
return new ReadOnlySubStream(BaseStream, _directoryEntryHeader!.CompressedSize);
return new ReadOnlySubStream(BaseStream, _directoryEntryHeader.CompressedSize);
}

return BaseStream;
Expand Down
10 changes: 5 additions & 5 deletions src/SharpCompress/Common/Zip/ZipEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ internal ZipEntry(ZipFilePart? filePart)
{
return;
}
_filePart = filePart;
LastModifiedTime = Utility.DosDateToDateTime(
filePart.Header.LastModifiedDate,
filePart.Header.LastModifiedTime
);
_filePart = filePart;
LastModifiedTime = Utility.DosDateToDateTime(
filePart.Header.LastModifiedDate,
filePart.Header.LastModifiedTime
);
}

public override CompressionType CompressionType =>
Expand Down
8 changes: 7 additions & 1 deletion src/SharpCompress/Common/Zip/ZipHeaderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ ArchiveEncoding archiveEncoding
}
case POST_DATA_DESCRIPTOR:
{
if (FlagUtility.HasFlag(_lastEntryHeader!.Flags, HeaderFlags.UsePostDataDescriptor))
if (
FlagUtility.HasFlag(
_lastEntryHeader.NotNull().Flags,
HeaderFlags.UsePostDataDescriptor
)
&& _lastEntryHeader != null
)
{
_lastEntryHeader.Crc = reader.ReadUInt32();
_lastEntryHeader.CompressedSize = zip64
Expand Down
8 changes: 4 additions & 4 deletions src/SharpCompress/Compressors/LZMA/LZipStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@ public void Finish()
var crc32Stream = (Crc32Stream)_stream;
crc32Stream.WrappedStream.Dispose();
crc32Stream.Dispose();
var compressedCount = _countingWritableSubStream!.Count;
var compressedCount = _countingWritableSubStream.NotNull().Count;

Span<byte> intBuf = stackalloc byte[8];
BinaryPrimitives.WriteUInt32LittleEndian(intBuf, crc32Stream.Crc);
_countingWritableSubStream.Write(intBuf.Slice(0, 4));
_countingWritableSubStream?.Write(intBuf.Slice(0, 4));

BinaryPrimitives.WriteInt64LittleEndian(intBuf, _writeCount);
_countingWritableSubStream.Write(intBuf);
_countingWritableSubStream?.Write(intBuf);

//total with headers
BinaryPrimitives.WriteUInt64LittleEndian(intBuf, compressedCount + 6 + 20);
_countingWritableSubStream.Write(intBuf);
_countingWritableSubStream?.Write(intBuf);
}
_finished = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,6 @@ private byte[] ApplyFilter(byte[] __d, uint DataSize, UnpackFilter Flt)
{
case FILTER_E8:
case FILTER_E8E9:

{
var FileOffset = (uint)WrittenFileSize;

Expand Down Expand Up @@ -569,7 +568,6 @@ private byte[] ApplyFilter(byte[] __d, uint DataSize, UnpackFilter Flt)
}
return SrcData;
case FILTER_ARM:

{
var FileOffset = (uint)WrittenFileSize;
// DataSize is unsigned, so we use "CurPos+3" and not "DataSize-3"
Expand Down

0 comments on commit b550df2

Please sign in to comment.