diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json
index d1ac7eef..f92b715a 100644
--- a/.config/dotnet-tools.json
+++ b/.config/dotnet-tools.json
@@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"csharpier": {
- "version": "0.21.0",
+ "version": "0.23.0",
"commands": [
"dotnet-csharpier"
]
diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml
index 530ec766..45abba29 100644
--- a/.github/workflows/dotnetcore.yml
+++ b/.github/workflows/dotnetcore.yml
@@ -18,6 +18,13 @@ jobs:
- uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
+ - name: NuGet Caching
+ uses: actions/cache@v3
+ with:
+ path: ~/.nuget/packages
+ key: ${{ runner.os }}-nuget-${{ hashFiles('packages.lock.json', '*/packages.lock.json') }}
+ restore-keys: |
+ ${{ runner.os }}-nuget-
- run: dotnet run --project build/build.csproj
- uses: actions/upload-artifact@v3
with:
diff --git a/README.md b/README.md
index f60272b8..777b383d 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@ SharpCompress is a compression library in pure C# for .NET Standard 2.0, 2.1, .N
The major feature is support for non-seekable streams so large files can be processed on the fly (i.e. download stream).
GitHub Actions Build -
-[](https://circleci.com/gh/adamhathcock/sharpcompress)
+[](https://github.com/adamhathcock/sharpcompress/actions/workflows/dotnetcore.yml)
## Need Help?
diff --git a/SharpCompress.sln b/SharpCompress.sln
index 5b033547..71ec294e 100644
--- a/SharpCompress.sln
+++ b/SharpCompress.sln
@@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.6
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F18F1765-4A02-42FD-9BEF-F0E2FCBD9D17}"
-EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{3C5BE746-03E5-4895-9988-0B57F162F86C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{0F0901FF-E8D9-426A-B5A2-17C7F47C1529}"
@@ -15,6 +13,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpCompress.Test", "tests
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "build", "build\build.csproj", "{D4D613CB-5E94-47FB-85BE-B8423D20C545}"
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Config", "Config", "{CDB42573-7D22-4490-BA12-1B7FB99CE7FB}"
+ ProjectSection(SolutionItems) = preProject
+ Directory.Build.props = Directory.Build.props
+ global.json = global.json
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
diff --git a/USAGE.md b/USAGE.md
index a7a7f0d6..c96f9c1b 100644
--- a/USAGE.md
+++ b/USAGE.md
@@ -33,6 +33,18 @@ If using Compression Stream classes directly and you don't want the wrapped stre
Also, look over the tests for more thorough [examples](https://github.com/adamhathcock/sharpcompress/tree/master/tests/SharpCompress.Test)
+### Create Zip Archive from multiple files
+```C#
+using(var archive = ZipArchive.Create())
+{
+ archive.AddEntry("file01.txt", "C:\\file01.txt");
+ archive.AddEntry("file02.txt", "C:\\file02.txt");
+ ...
+
+ archive.SaveTo("C:\\temp.zip", CompressionType.Deflate);
+}
+```
+
### Create Zip Archive from all files in a directory to a file
```C#
@@ -143,4 +155,4 @@ foreach(var entry in tr.Entries)
{
Console.WriteLine($"{entry.Key}");
}
-```
\ No newline at end of file
+```
diff --git a/build/Program.cs b/build/Program.cs
index 000051dd..9475a66b 100644
--- a/build/Program.cs
+++ b/build/Program.cs
@@ -7,8 +7,10 @@ using static Bullseye.Targets;
using static SimpleExec.Command;
const string Clean = "clean";
+const string Restore = "restore";
const string Build = "build";
const string Test = "test";
+const string Format = "format";
const string Publish = "publish";
Target(
@@ -38,10 +40,21 @@ Target(
);
Target(
- Build,
+ Format,
() =>
{
- Run("dotnet", "build src/SharpCompress/SharpCompress.csproj -c Release");
+ Run("dotnet", "tool restore");
+ Run("dotnet", "csharpier --check .");
+ }
+);
+Target(Restore, DependsOn(Format), () => Run("dotnet", "restore"));
+
+Target(
+ Build,
+ DependsOn(Restore),
+ () =>
+ {
+ Run("dotnet", "build src/SharpCompress/SharpCompress.csproj -c Release --no-restore");
}
);
@@ -63,7 +76,7 @@ Target(
foreach (var file in GetFiles("**/*.Test.csproj"))
{
- Run("dotnet", $"test {file} -c Release -f {framework}");
+ Run("dotnet", $"test {file} -c Release -f {framework} --no-restore --verbosity=normal");
}
}
);
diff --git a/build/build.csproj b/build/build.csproj
index 66d55099..7b478cf3 100644
--- a/build/build.csproj
+++ b/build/build.csproj
@@ -6,7 +6,7 @@
-
+
diff --git a/src/SharpCompress/Archives/AbstractWritableArchive.cs b/src/SharpCompress/Archives/AbstractWritableArchive.cs
index cf97aff8..30083ec7 100644
--- a/src/SharpCompress/Archives/AbstractWritableArchive.cs
+++ b/src/SharpCompress/Archives/AbstractWritableArchive.cs
@@ -38,7 +38,8 @@ public abstract class AbstractWritableArchive
private bool hasModifications;
private bool pauseRebuilding;
- internal AbstractWritableArchive(ArchiveType type) : base(type) { }
+ internal AbstractWritableArchive(ArchiveType type)
+ : base(type) { }
internal AbstractWritableArchive(ArchiveType type, SourceStream srcStream)
: base(type, srcStream) { }
diff --git a/src/SharpCompress/Archives/ArchiveFactory.cs b/src/SharpCompress/Archives/ArchiveFactory.cs
index 6b489fa1..cd0952f1 100644
--- a/src/SharpCompress/Archives/ArchiveFactory.cs
+++ b/src/SharpCompress/Archives/ArchiveFactory.cs
@@ -128,14 +128,16 @@ public static class ArchiveFactory
}
}
- private static T FindFactory(FileInfo finfo) where T : IFactory
+ private static T FindFactory(FileInfo finfo)
+ where T : IFactory
{
finfo.CheckNotNull(nameof(finfo));
using Stream stream = finfo.OpenRead();
return FindFactory(stream);
}
- private static T FindFactory(Stream stream) where T : IFactory
+ private static T FindFactory(Stream stream)
+ where T : IFactory
{
stream.CheckNotNull(nameof(stream));
if (!stream.CanRead || !stream.CanSeek)
@@ -173,7 +175,7 @@ public static class ArchiveFactory
return IsArchive(s, out type);
}
- private static bool IsArchive(Stream stream, out ArchiveType? type)
+ public static bool IsArchive(Stream stream, out ArchiveType? type)
{
type = null;
stream.CheckNotNull(nameof(stream));
diff --git a/src/SharpCompress/Archives/GZip/GZipArchive.cs b/src/SharpCompress/Archives/GZip/GZipArchive.cs
index eea56db0..fb2f7691 100644
--- a/src/SharpCompress/Archives/GZip/GZipArchive.cs
+++ b/src/SharpCompress/Archives/GZip/GZipArchive.cs
@@ -101,7 +101,8 @@ public class GZipArchive : AbstractWritableArchive
///
///
///
- internal GZipArchive(SourceStream srcStream) : base(ArchiveType.Tar, srcStream) { }
+ internal GZipArchive(SourceStream srcStream)
+ : base(ArchiveType.Tar, srcStream) { }
protected override IEnumerable LoadVolumes(SourceStream srcStream)
{
@@ -150,7 +151,8 @@ public class GZipArchive : AbstractWritableArchive
return true;
}
- internal GZipArchive() : base(ArchiveType.GZip) { }
+ internal GZipArchive()
+ : base(ArchiveType.GZip) { }
protected override GZipArchiveEntry CreateEntryInternal(
string filePath,
diff --git a/src/SharpCompress/Archives/GZip/GZipArchiveEntry.cs b/src/SharpCompress/Archives/GZip/GZipArchiveEntry.cs
index 0109ad98..be872e80 100644
--- a/src/SharpCompress/Archives/GZip/GZipArchiveEntry.cs
+++ b/src/SharpCompress/Archives/GZip/GZipArchiveEntry.cs
@@ -6,8 +6,8 @@ namespace SharpCompress.Archives.GZip;
public class GZipArchiveEntry : GZipEntry, IArchiveEntry
{
- internal GZipArchiveEntry(GZipArchive archive, GZipFilePart part) : base(part) =>
- Archive = archive;
+ internal GZipArchiveEntry(GZipArchive archive, GZipFilePart part)
+ : base(part) => Archive = archive;
public virtual Stream OpenEntryStream()
{
diff --git a/src/SharpCompress/Archives/GZip/GZipWritableArchiveEntry.cs b/src/SharpCompress/Archives/GZip/GZipWritableArchiveEntry.cs
index 7685ceb1..27dfc2bf 100644
--- a/src/SharpCompress/Archives/GZip/GZipWritableArchiveEntry.cs
+++ b/src/SharpCompress/Archives/GZip/GZipWritableArchiveEntry.cs
@@ -20,7 +20,8 @@ internal sealed class GZipWritableArchiveEntry : GZipArchiveEntry, IWritableArch
long size,
DateTime? lastModified,
bool closeStream
- ) : base(archive, null)
+ )
+ : base(archive, null)
{
this.stream = stream;
Key = path;
diff --git a/src/SharpCompress/Archives/Rar/FileInfoRarFilePart.cs b/src/SharpCompress/Archives/Rar/FileInfoRarFilePart.cs
index b5416f9e..02d2f769 100644
--- a/src/SharpCompress/Archives/Rar/FileInfoRarFilePart.cs
+++ b/src/SharpCompress/Archives/Rar/FileInfoRarFilePart.cs
@@ -11,7 +11,8 @@ internal sealed class FileInfoRarFilePart : SeekableFilePart
MarkHeader mh,
FileHeader fh,
FileInfo fi
- ) : base(mh, fh, volume.Index, volume.Stream, password) => FileInfo = fi;
+ )
+ : base(mh, fh, volume.Index, volume.Stream, password) => FileInfo = fi;
internal FileInfo FileInfo { get; }
diff --git a/src/SharpCompress/Archives/Rar/RarArchive.cs b/src/SharpCompress/Archives/Rar/RarArchive.cs
index 48f4ef45..29d733f6 100644
--- a/src/SharpCompress/Archives/Rar/RarArchive.cs
+++ b/src/SharpCompress/Archives/Rar/RarArchive.cs
@@ -23,7 +23,8 @@ public class RarArchive : AbstractArchive
///
///
///
- internal RarArchive(SourceStream srcStream) : base(ArchiveType.Rar, srcStream) { }
+ internal RarArchive(SourceStream srcStream)
+ : base(ArchiveType.Rar, srcStream) { }
protected override IEnumerable LoadEntries(IEnumerable volumes) =>
RarArchiveEntryFactory.GetEntries(this, volumes, ReaderOptions);
diff --git a/src/SharpCompress/Archives/Rar/RarArchiveVolumeFactory.cs b/src/SharpCompress/Archives/Rar/RarArchiveVolumeFactory.cs
index 6903bc5f..72ccf60f 100644
--- a/src/SharpCompress/Archives/Rar/RarArchiveVolumeFactory.cs
+++ b/src/SharpCompress/Archives/Rar/RarArchiveVolumeFactory.cs
@@ -26,7 +26,7 @@ internal static class RarArchiveVolumeFactory
else
{
//old style - ...rar, .r00, .r01 ...
- m = Regex.Match(part1.Name, @"^(.*\.r)(ar|[0-9]+)$", RegexOptions.IgnoreCase);
+ m = Regex.Match(part1.Name, @"^(.*\.)([r-z{])(ar|[0-9]+)$", RegexOptions.IgnoreCase);
if (m.Success)
item = new FileInfo(
Path.Combine(
@@ -34,8 +34,9 @@ internal static class RarArchiveVolumeFactory
String.Concat(
m.Groups[1].Value,
index == 0
- ? "ar"
- : (index - 1).ToString().PadLeft(m.Groups[2].Value.Length, '0')
+ ? m.Groups[2].Value + m.Groups[3].Value
+ : (char)(m.Groups[2].Value[0] + ((index - 1) / 100))
+ + (index - 1).ToString("D4").Substring(2)
)
)
);
diff --git a/src/SharpCompress/Archives/Rar/SeekableFilePart.cs b/src/SharpCompress/Archives/Rar/SeekableFilePart.cs
index e7247eae..08aceb13 100644
--- a/src/SharpCompress/Archives/Rar/SeekableFilePart.cs
+++ b/src/SharpCompress/Archives/Rar/SeekableFilePart.cs
@@ -15,7 +15,8 @@ internal class SeekableFilePart : RarFilePart
int index,
Stream stream,
string? password
- ) : base(mh, fh, index)
+ )
+ : base(mh, fh, index)
{
this.stream = stream;
this.password = password;
diff --git a/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs b/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs
index 8bb782f0..7577b43d 100644
--- a/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs
+++ b/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs
@@ -104,7 +104,8 @@ public class SevenZipArchive : AbstractArchive
///
///
- internal SevenZipArchive(SourceStream srcStream) : base(ArchiveType.SevenZip, srcStream) { }
+ internal SevenZipArchive(SourceStream srcStream)
+ : base(ArchiveType.SevenZip, srcStream) { }
protected override IEnumerable LoadVolumes(SourceStream srcStream)
{
@@ -125,7 +126,8 @@ public class SevenZipArchive : AbstractArchive LoadEntries(
IEnumerable volumes
diff --git a/src/SharpCompress/Archives/SevenZip/SevenZipArchiveEntry.cs b/src/SharpCompress/Archives/SevenZip/SevenZipArchiveEntry.cs
index 4e30f18e..9824ca47 100644
--- a/src/SharpCompress/Archives/SevenZip/SevenZipArchiveEntry.cs
+++ b/src/SharpCompress/Archives/SevenZip/SevenZipArchiveEntry.cs
@@ -5,8 +5,8 @@ namespace SharpCompress.Archives.SevenZip;
public class SevenZipArchiveEntry : SevenZipEntry, IArchiveEntry
{
- internal SevenZipArchiveEntry(SevenZipArchive archive, SevenZipFilePart part) : base(part) =>
- Archive = archive;
+ internal SevenZipArchiveEntry(SevenZipArchive archive, SevenZipFilePart part)
+ : base(part) => Archive = archive;
public Stream OpenEntryStream() => FilePart.GetCompressedStream();
diff --git a/src/SharpCompress/Archives/Tar/TarArchive.cs b/src/SharpCompress/Archives/Tar/TarArchive.cs
index 218eda42..43184b66 100644
--- a/src/SharpCompress/Archives/Tar/TarArchive.cs
+++ b/src/SharpCompress/Archives/Tar/TarArchive.cs
@@ -135,9 +135,11 @@ public class TarArchive : AbstractWritableArchive
///
///
///
- internal TarArchive(SourceStream srcStream) : base(ArchiveType.Tar, srcStream) { }
+ internal TarArchive(SourceStream srcStream)
+ : base(ArchiveType.Tar, srcStream) { }
- internal TarArchive() : base(ArchiveType.Tar) { }
+ internal TarArchive()
+ : base(ArchiveType.Tar) { }
protected override IEnumerable LoadEntries(IEnumerable volumes)
{
diff --git a/src/SharpCompress/Archives/Tar/TarWritableArchiveEntry.cs b/src/SharpCompress/Archives/Tar/TarWritableArchiveEntry.cs
index e110987b..0bbea709 100644
--- a/src/SharpCompress/Archives/Tar/TarWritableArchiveEntry.cs
+++ b/src/SharpCompress/Archives/Tar/TarWritableArchiveEntry.cs
@@ -21,7 +21,8 @@ internal sealed class TarWritableArchiveEntry : TarArchiveEntry, IWritableArchiv
long size,
DateTime? lastModified,
bool closeStream
- ) : base(archive, null, compressionType)
+ )
+ : base(archive, null, compressionType)
{
this.stream = stream;
Key = path;
diff --git a/src/SharpCompress/Archives/Zip/ZipArchive.cs b/src/SharpCompress/Archives/Zip/ZipArchive.cs
index 99a66161..14e4a93e 100644
--- a/src/SharpCompress/Archives/Zip/ZipArchive.cs
+++ b/src/SharpCompress/Archives/Zip/ZipArchive.cs
@@ -32,7 +32,8 @@ public class ZipArchive : AbstractWritableArchive
///
///
///
- internal ZipArchive(SourceStream srcStream) : base(ArchiveType.Zip, srcStream) =>
+ internal ZipArchive(SourceStream srcStream)
+ : base(ArchiveType.Zip, srcStream) =>
headerFactory = new SeekableZipHeaderFactory(
srcStream.ReaderOptions.Password,
srcStream.ReaderOptions.ArchiveEncoding
@@ -133,7 +134,7 @@ public class ZipArchive : AbstractWritableArchive
public static bool IsZipFile(Stream stream, string? password = null)
{
- var headerFactory = new StreamingZipHeaderFactory(password, new ArchiveEncoding());
+ var headerFactory = new StreamingZipHeaderFactory(password, new ArchiveEncoding(), null);
try
{
var header = headerFactory
@@ -157,7 +158,7 @@ public class ZipArchive : AbstractWritableArchive
public static bool IsZipMulti(Stream stream, string? password = null)
{
- var headerFactory = new StreamingZipHeaderFactory(password, new ArchiveEncoding());
+ var headerFactory = new StreamingZipHeaderFactory(password, new ArchiveEncoding(), null);
try
{
var header = headerFactory
@@ -217,7 +218,8 @@ public class ZipArchive : AbstractWritableArchive
return new ZipVolume(SrcStream, ReaderOptions, idx++).AsEnumerable();
}
- internal ZipArchive() : base(ArchiveType.Zip) { }
+ internal ZipArchive()
+ : base(ArchiveType.Zip) { }
protected override IEnumerable LoadEntries(IEnumerable volumes)
{
@@ -298,6 +300,6 @@ public class ZipArchive : AbstractWritableArchive
{
var stream = Volumes.Single().Stream;
stream.Position = 0;
- return ZipReader.Open(stream, ReaderOptions);
+ return ZipReader.Open(stream, ReaderOptions, Entries);
}
}
diff --git a/src/SharpCompress/Archives/Zip/ZipArchiveEntry.cs b/src/SharpCompress/Archives/Zip/ZipArchiveEntry.cs
index 59e30fd8..a94ed2c6 100644
--- a/src/SharpCompress/Archives/Zip/ZipArchiveEntry.cs
+++ b/src/SharpCompress/Archives/Zip/ZipArchiveEntry.cs
@@ -6,8 +6,8 @@ namespace SharpCompress.Archives.Zip;
public class ZipArchiveEntry : ZipEntry, IArchiveEntry
{
- internal ZipArchiveEntry(ZipArchive archive, SeekableZipFilePart? part) : base(part) =>
- Archive = archive;
+ internal ZipArchiveEntry(ZipArchive archive, SeekableZipFilePart? part)
+ : base(part) => Archive = archive;
public virtual Stream OpenEntryStream() => Parts.Single().GetCompressedStream();
diff --git a/src/SharpCompress/Archives/Zip/ZipWritableArchiveEntry.cs b/src/SharpCompress/Archives/Zip/ZipWritableArchiveEntry.cs
index a13a3dbb..628e505f 100644
--- a/src/SharpCompress/Archives/Zip/ZipWritableArchiveEntry.cs
+++ b/src/SharpCompress/Archives/Zip/ZipWritableArchiveEntry.cs
@@ -19,7 +19,8 @@ internal class ZipWritableArchiveEntry : ZipArchiveEntry, IWritableArchiveEntry
long size,
DateTime? lastModified,
bool closeStream
- ) : base(archive, null)
+ )
+ : base(archive, null)
{
this.stream = stream;
Key = path;
diff --git a/src/SharpCompress/Common/ArchiveEncoding.cs b/src/SharpCompress/Common/ArchiveEncoding.cs
index 53848ef7..f66044d3 100644
--- a/src/SharpCompress/Common/ArchiveEncoding.cs
+++ b/src/SharpCompress/Common/ArchiveEncoding.cs
@@ -26,7 +26,8 @@ public class ArchiveEncoding
/// string Func(bytes, index, length)
public Func? CustomDecoder { get; set; }
- public ArchiveEncoding() : this(Encoding.Default, Encoding.Default) { }
+ public ArchiveEncoding()
+ : this(Encoding.Default, Encoding.Default) { }
public ArchiveEncoding(Encoding def, Encoding password)
{
diff --git a/src/SharpCompress/Common/ArchiveException.cs b/src/SharpCompress/Common/ArchiveException.cs
index 0fc98baa..507d5fd8 100644
--- a/src/SharpCompress/Common/ArchiveException.cs
+++ b/src/SharpCompress/Common/ArchiveException.cs
@@ -4,5 +4,6 @@ namespace SharpCompress.Common;
public class ArchiveException : Exception
{
- public ArchiveException(string message) : base(message) { }
+ public ArchiveException(string message)
+ : base(message) { }
}
diff --git a/src/SharpCompress/Common/CryptographicException.cs b/src/SharpCompress/Common/CryptographicException.cs
index c20775a8..6127524a 100644
--- a/src/SharpCompress/Common/CryptographicException.cs
+++ b/src/SharpCompress/Common/CryptographicException.cs
@@ -4,5 +4,6 @@ namespace SharpCompress.Common;
public class CryptographicException : Exception
{
- public CryptographicException(string message) : base(message) { }
+ public CryptographicException(string message)
+ : base(message) { }
}
diff --git a/src/SharpCompress/Common/ExtractionException.cs b/src/SharpCompress/Common/ExtractionException.cs
index 44316b73..4bc4f00c 100644
--- a/src/SharpCompress/Common/ExtractionException.cs
+++ b/src/SharpCompress/Common/ExtractionException.cs
@@ -4,7 +4,9 @@ namespace SharpCompress.Common;
public class ExtractionException : Exception
{
- public ExtractionException(string message) : base(message) { }
+ public ExtractionException(string message)
+ : base(message) { }
- public ExtractionException(string message, Exception inner) : base(message, inner) { }
+ public ExtractionException(string message, Exception inner)
+ : base(message, inner) { }
}
diff --git a/src/SharpCompress/Common/FlagUtility.cs b/src/SharpCompress/Common/FlagUtility.cs
index 73215817..8f272b9d 100644
--- a/src/SharpCompress/Common/FlagUtility.cs
+++ b/src/SharpCompress/Common/FlagUtility.cs
@@ -12,8 +12,8 @@ internal static class FlagUtility
/// Flagged variable
/// Flag to test
///
- public static bool HasFlag(long bitField, T flag) where T : struct =>
- HasFlag(bitField, flag);
+ public static bool HasFlag(long bitField, T flag)
+ where T : struct => HasFlag(bitField, flag);
///
/// Returns true if the flag is set on the specified bit field.
@@ -23,8 +23,8 @@ internal static class FlagUtility
/// Flagged variable
/// Flag to test
///
- public static bool HasFlag(ulong bitField, T flag) where T : struct =>
- HasFlag(bitField, flag);
+ public static bool HasFlag(ulong bitField, T flag)
+ where T : struct => HasFlag(bitField, flag);
///
/// Returns true if the flag is set on the specified bit field.
@@ -45,8 +45,8 @@ internal static class FlagUtility
/// Flagged variable
/// Flag to test
///
- public static bool HasFlag(T bitField, T flag) where T : struct =>
- HasFlag(Convert.ToInt64(bitField), Convert.ToInt64(flag));
+ public static bool HasFlag(T bitField, T flag)
+ where T : struct => HasFlag(Convert.ToInt64(bitField), Convert.ToInt64(flag));
///
/// Returns true if the flag is set on the specified bit field.
@@ -81,6 +81,6 @@ internal static class FlagUtility
/// Flag to change
/// bool
/// The flagged variable with the flag changed
- public static long SetFlag(T bitField, T flag, bool on) where T : struct =>
- SetFlag(Convert.ToInt64(bitField), Convert.ToInt64(flag), on);
+ public static long SetFlag(T bitField, T flag, bool on)
+ where T : struct => SetFlag(Convert.ToInt64(bitField), Convert.ToInt64(flag), on);
}
diff --git a/src/SharpCompress/Common/GZip/GZipFilePart.cs b/src/SharpCompress/Common/GZip/GZipFilePart.cs
index 0dd9a2d1..fbf4ee45 100644
--- a/src/SharpCompress/Common/GZip/GZipFilePart.cs
+++ b/src/SharpCompress/Common/GZip/GZipFilePart.cs
@@ -13,7 +13,8 @@ internal sealed class GZipFilePart : FilePart
private string? _name;
private readonly Stream _stream;
- internal GZipFilePart(Stream stream, ArchiveEncoding archiveEncoding) : base(archiveEncoding)
+ internal GZipFilePart(Stream stream, ArchiveEncoding archiveEncoding)
+ : base(archiveEncoding)
{
_stream = stream;
ReadAndValidateGzipHeader();
diff --git a/src/SharpCompress/Common/IncompleteArchiveException.cs b/src/SharpCompress/Common/IncompleteArchiveException.cs
index f1ce3641..a033001a 100644
--- a/src/SharpCompress/Common/IncompleteArchiveException.cs
+++ b/src/SharpCompress/Common/IncompleteArchiveException.cs
@@ -2,5 +2,6 @@ namespace SharpCompress.Common;
public class IncompleteArchiveException : ArchiveException
{
- public IncompleteArchiveException(string message) : base(message) { }
+ public IncompleteArchiveException(string message)
+ : base(message) { }
}
diff --git a/src/SharpCompress/Common/InvalidFormatException.cs b/src/SharpCompress/Common/InvalidFormatException.cs
index b9501369..8f14df14 100644
--- a/src/SharpCompress/Common/InvalidFormatException.cs
+++ b/src/SharpCompress/Common/InvalidFormatException.cs
@@ -4,7 +4,9 @@ namespace SharpCompress.Common;
public class InvalidFormatException : ExtractionException
{
- public InvalidFormatException(string message) : base(message) { }
+ public InvalidFormatException(string message)
+ : base(message) { }
- public InvalidFormatException(string message, Exception inner) : base(message, inner) { }
+ public InvalidFormatException(string message, Exception inner)
+ : base(message, inner) { }
}
diff --git a/src/SharpCompress/Common/MultiVolumeExtractionException.cs b/src/SharpCompress/Common/MultiVolumeExtractionException.cs
index ee2f95ad..764ac808 100644
--- a/src/SharpCompress/Common/MultiVolumeExtractionException.cs
+++ b/src/SharpCompress/Common/MultiVolumeExtractionException.cs
@@ -4,8 +4,9 @@ namespace SharpCompress.Common;
public class MultiVolumeExtractionException : ExtractionException
{
- public MultiVolumeExtractionException(string message) : base(message) { }
+ public MultiVolumeExtractionException(string message)
+ : base(message) { }
- public MultiVolumeExtractionException(string message, Exception inner) : base(message, inner)
- { }
+ public MultiVolumeExtractionException(string message, Exception inner)
+ : base(message, inner) { }
}
diff --git a/src/SharpCompress/Common/MultipartStreamRequiredException.cs b/src/SharpCompress/Common/MultipartStreamRequiredException.cs
index bbe3ae93..33a842d9 100644
--- a/src/SharpCompress/Common/MultipartStreamRequiredException.cs
+++ b/src/SharpCompress/Common/MultipartStreamRequiredException.cs
@@ -2,5 +2,6 @@ namespace SharpCompress.Common;
public class MultipartStreamRequiredException : ExtractionException
{
- public MultipartStreamRequiredException(string message) : base(message) { }
+ public MultipartStreamRequiredException(string message)
+ : base(message) { }
}
diff --git a/src/SharpCompress/Common/PasswordProtectedException.cs b/src/SharpCompress/Common/PasswordProtectedException.cs
index 7b559625..9ebe3d65 100644
--- a/src/SharpCompress/Common/PasswordProtectedException.cs
+++ b/src/SharpCompress/Common/PasswordProtectedException.cs
@@ -4,7 +4,9 @@ namespace SharpCompress.Common;
public class PasswordProtectedException : ExtractionException
{
- public PasswordProtectedException(string message) : base(message) { }
+ public PasswordProtectedException(string message)
+ : base(message) { }
- public PasswordProtectedException(string message, Exception inner) : base(message, inner) { }
+ public PasswordProtectedException(string message, Exception inner)
+ : base(message, inner) { }
}
diff --git a/src/SharpCompress/Common/Rar/RarCrcBinaryReader.cs b/src/SharpCompress/Common/Rar/RarCrcBinaryReader.cs
index 97a8aaa9..b4c2d0c9 100644
--- a/src/SharpCompress/Common/Rar/RarCrcBinaryReader.cs
+++ b/src/SharpCompress/Common/Rar/RarCrcBinaryReader.cs
@@ -8,7 +8,8 @@ internal class RarCrcBinaryReader : MarkingBinaryReader
{
private uint _currentCrc;
- public RarCrcBinaryReader(Stream stream) : base(stream) { }
+ public RarCrcBinaryReader(Stream stream)
+ : base(stream) { }
public uint GetCrc32() => ~_currentCrc;
diff --git a/src/SharpCompress/Common/Rar/RarCryptoBinaryReader.cs b/src/SharpCompress/Common/Rar/RarCryptoBinaryReader.cs
index 71902fdf..0be6e74e 100644
--- a/src/SharpCompress/Common/Rar/RarCryptoBinaryReader.cs
+++ b/src/SharpCompress/Common/Rar/RarCryptoBinaryReader.cs
@@ -11,7 +11,8 @@ internal sealed class RarCryptoBinaryReader : RarCrcBinaryReader
private readonly Queue _data = new Queue();
private long _readCount;
- public RarCryptoBinaryReader(Stream stream, string password) : base(stream)
+ public RarCryptoBinaryReader(Stream stream, string password)
+ : base(stream)
{
_password = password;
diff --git a/src/SharpCompress/Common/Rar/RarCryptoWrapper.cs b/src/SharpCompress/Common/Rar/RarCryptoWrapper.cs
index e92056b4..a1cee046 100644
--- a/src/SharpCompress/Common/Rar/RarCryptoWrapper.cs
+++ b/src/SharpCompress/Common/Rar/RarCryptoWrapper.cs
@@ -15,7 +15,7 @@ internal sealed class RarCryptoWrapper : Stream
{
_actualStream = actualStream;
_salt = salt;
- _rijndael = RarRijndael.InitializeFrom(password, salt);
+ _rijndael = RarRijndael.InitializeFrom(password ?? "", salt);
}
public override void Flush() => throw new NotSupportedException();
diff --git a/src/SharpCompress/Common/Rar/RarEntry.cs b/src/SharpCompress/Common/Rar/RarEntry.cs
index f3614a40..7f280e4a 100644
--- a/src/SharpCompress/Common/Rar/RarEntry.cs
+++ b/src/SharpCompress/Common/Rar/RarEntry.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using SharpCompress.Common.Rar.Headers;
namespace SharpCompress.Common.Rar;
@@ -11,7 +11,8 @@ public abstract class RarEntry : Entry
/// As the V2017 port isn't complete, add this check to use the legacy Rar code.
///
internal bool IsRarV3 =>
- FileHeader.CompressionAlgorithm == 20
+ FileHeader.CompressionAlgorithm == 15
+ || FileHeader.CompressionAlgorithm == 20
|| FileHeader.CompressionAlgorithm == 26
|| FileHeader.CompressionAlgorithm == 29
|| FileHeader.CompressionAlgorithm == 36; //Nanook - Added 20+26 as Test arc from WinRar2.8 (algo 20) was failing with 2017 code
diff --git a/src/SharpCompress/Common/Rar/RarFilePart.cs b/src/SharpCompress/Common/Rar/RarFilePart.cs
index 7608d0ac..f87d214d 100644
--- a/src/SharpCompress/Common/Rar/RarFilePart.cs
+++ b/src/SharpCompress/Common/Rar/RarFilePart.cs
@@ -8,7 +8,8 @@ namespace SharpCompress.Common.Rar;
///
internal abstract class RarFilePart : FilePart
{
- internal RarFilePart(MarkHeader mh, FileHeader fh, int index) : base(fh.ArchiveEncoding)
+ internal RarFilePart(MarkHeader mh, FileHeader fh, int index)
+ : base(fh.ArchiveEncoding)
{
MarkHeader = mh;
FileHeader = fh;
diff --git a/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs b/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs
index 7aac0ade..ac1ad24d 100644
--- a/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs
+++ b/src/SharpCompress/Common/SevenZip/SevenZipFilePart.cs
@@ -17,7 +17,8 @@ internal class SevenZipFilePart : FilePart
int index,
CFileItem fileEntry,
ArchiveEncoding archiveEncoding
- ) : base(archiveEncoding)
+ )
+ : base(archiveEncoding)
{
_stream = stream;
_database = database;
diff --git a/src/SharpCompress/Common/Tar/TarEntry.cs b/src/SharpCompress/Common/Tar/TarEntry.cs
index 7b5e4a05..59743070 100644
--- a/src/SharpCompress/Common/Tar/TarEntry.cs
+++ b/src/SharpCompress/Common/Tar/TarEntry.cs
@@ -72,6 +72,10 @@ public class TarEntry : Entry
yield return new TarEntry(new TarFilePart(h, null), compressionType);
}
}
+ else
+ {
+ throw new IncompleteArchiveException("Unexpected EOF reading tar file");
+ }
}
}
}
diff --git a/src/SharpCompress/Common/Tar/TarFilePart.cs b/src/SharpCompress/Common/Tar/TarFilePart.cs
index c81f87e4..bfd2fe29 100644
--- a/src/SharpCompress/Common/Tar/TarFilePart.cs
+++ b/src/SharpCompress/Common/Tar/TarFilePart.cs
@@ -7,7 +7,8 @@ internal sealed class TarFilePart : FilePart
{
private readonly Stream _seekableStream;
- internal TarFilePart(TarHeader header, Stream seekableStream) : base(header.ArchiveEncoding)
+ internal TarFilePart(TarHeader header, Stream seekableStream)
+ : base(header.ArchiveEncoding)
{
_seekableStream = seekableStream;
Header = header;
diff --git a/src/SharpCompress/Common/Zip/Headers/DirectoryEndHeader.cs b/src/SharpCompress/Common/Zip/Headers/DirectoryEndHeader.cs
index 943ae47c..2e54a6dd 100644
--- a/src/SharpCompress/Common/Zip/Headers/DirectoryEndHeader.cs
+++ b/src/SharpCompress/Common/Zip/Headers/DirectoryEndHeader.cs
@@ -4,7 +4,8 @@ namespace SharpCompress.Common.Zip.Headers;
internal class DirectoryEndHeader : ZipHeader
{
- public DirectoryEndHeader() : base(ZipHeaderType.DirectoryEnd) { }
+ public DirectoryEndHeader()
+ : base(ZipHeaderType.DirectoryEnd) { }
internal override void Read(BinaryReader reader)
{
diff --git a/src/SharpCompress/Common/Zip/Headers/IgnoreHeader.cs b/src/SharpCompress/Common/Zip/Headers/IgnoreHeader.cs
index 4852228c..5a587a7b 100644
--- a/src/SharpCompress/Common/Zip/Headers/IgnoreHeader.cs
+++ b/src/SharpCompress/Common/Zip/Headers/IgnoreHeader.cs
@@ -4,7 +4,8 @@ namespace SharpCompress.Common.Zip.Headers;
internal class IgnoreHeader : ZipHeader
{
- public IgnoreHeader(ZipHeaderType type) : base(type) { }
+ public IgnoreHeader(ZipHeaderType type)
+ : base(type) { }
internal override void Read(BinaryReader reader) { }
}
diff --git a/src/SharpCompress/Common/Zip/Headers/SplitHeader.cs b/src/SharpCompress/Common/Zip/Headers/SplitHeader.cs
index e151d4e5..4151a6cb 100644
--- a/src/SharpCompress/Common/Zip/Headers/SplitHeader.cs
+++ b/src/SharpCompress/Common/Zip/Headers/SplitHeader.cs
@@ -5,7 +5,8 @@ namespace SharpCompress.Common.Zip.Headers;
internal class SplitHeader : ZipHeader
{
- public SplitHeader() : base(ZipHeaderType.Split) { }
+ public SplitHeader()
+ : base(ZipHeaderType.Split) { }
internal override void Read(BinaryReader reader) => throw new NotImplementedException();
}
diff --git a/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndHeader.cs b/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndHeader.cs
index 0356c48c..a74b4d1f 100644
--- a/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndHeader.cs
+++ b/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndHeader.cs
@@ -4,7 +4,8 @@ namespace SharpCompress.Common.Zip.Headers;
internal class Zip64DirectoryEndHeader : ZipHeader
{
- public Zip64DirectoryEndHeader() : base(ZipHeaderType.Zip64DirectoryEnd) { }
+ public Zip64DirectoryEndHeader()
+ : base(ZipHeaderType.Zip64DirectoryEnd) { }
internal override void Read(BinaryReader reader)
{
diff --git a/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndLocatorHeader.cs b/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndLocatorHeader.cs
index 9bbf2670..3020d377 100644
--- a/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndLocatorHeader.cs
+++ b/src/SharpCompress/Common/Zip/Headers/Zip64DirectoryEndLocatorHeader.cs
@@ -4,7 +4,8 @@ namespace SharpCompress.Common.Zip.Headers;
internal class Zip64DirectoryEndLocatorHeader : ZipHeader
{
- public Zip64DirectoryEndLocatorHeader() : base(ZipHeaderType.Zip64DirectoryEndLocator) { }
+ public Zip64DirectoryEndLocatorHeader()
+ : base(ZipHeaderType.Zip64DirectoryEndLocator) { }
internal override void Read(BinaryReader reader)
{
diff --git a/src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs b/src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs
index 79347014..98d230f5 100644
--- a/src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs
+++ b/src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs
@@ -9,7 +9,8 @@ namespace SharpCompress.Common.Zip.Headers;
internal abstract class ZipFileEntry : ZipHeader
{
- protected ZipFileEntry(ZipHeaderType type, ArchiveEncoding archiveEncoding) : base(type)
+ protected ZipFileEntry(ZipHeaderType type, ArchiveEncoding archiveEncoding)
+ : base(type)
{
Extra = new List();
ArchiveEncoding = archiveEncoding;
diff --git a/src/SharpCompress/Common/Zip/SeekableZipFilePart.cs b/src/SharpCompress/Common/Zip/SeekableZipFilePart.cs
index dc7e4783..63fdc933 100644
--- a/src/SharpCompress/Common/Zip/SeekableZipFilePart.cs
+++ b/src/SharpCompress/Common/Zip/SeekableZipFilePart.cs
@@ -14,7 +14,8 @@ internal class SeekableZipFilePart : ZipFilePart
SeekableZipHeaderFactory headerFactory,
DirectoryEntryHeader header,
Stream stream
- ) : base(header, stream)
+ )
+ : base(header, stream)
{
_headerFactory = headerFactory;
_directoryEntryHeader = header;
diff --git a/src/SharpCompress/Common/Zip/StreamingZipFilePart.cs b/src/SharpCompress/Common/Zip/StreamingZipFilePart.cs
index c5ed221a..1cd1f61f 100644
--- a/src/SharpCompress/Common/Zip/StreamingZipFilePart.cs
+++ b/src/SharpCompress/Common/Zip/StreamingZipFilePart.cs
@@ -1,4 +1,5 @@
using System.IO;
+using System.Net.Sockets;
using SharpCompress.Common.Zip.Headers;
using SharpCompress.Compressors.Deflate;
using SharpCompress.IO;
@@ -9,7 +10,8 @@ internal sealed class StreamingZipFilePart : ZipFilePart
{
private Stream? _decompressionStream;
- internal StreamingZipFilePart(ZipFileEntry header, Stream stream) : base(header, stream) { }
+ internal StreamingZipFilePart(ZipFileEntry header, Stream stream)
+ : base(header, stream) { }
protected override Stream CreateBaseStream() => Header.PackedStream;
@@ -36,57 +38,19 @@ internal sealed class StreamingZipFilePart : ZipFilePart
{
return new BinaryReader(rewindableStream);
}
+
if (Header.HasData && !Skipped)
{
_decompressionStream ??= GetCompressedStream();
- if (Header.CompressionMethod != ZipCompressionMethod.None)
+ _decompressionStream.Skip();
+
+ // If we had TotalIn / TotalOut we could have used them
+ Header.CompressedSize = _decompressionStream.Position;
+
+ if (_decompressionStream is DeflateStream deflateStream)
{
- _decompressionStream.Skip();
-
- // If we had TotalIn / TotalOut we could have used them
- Header.CompressedSize = _decompressionStream.Position;
-
- if (_decompressionStream is DeflateStream deflateStream)
- {
- rewindableStream.Rewind(deflateStream.InputBuffer);
- }
- }
- else
- {
- // We would need to search for the magic word
- rewindableStream.Position -= 4;
- var pos = rewindableStream.Position;
- while (Utility.Find(rewindableStream, new byte[] { 0x50, 0x4b, 0x07, 0x08 }))
- {
- // We should probably check CRC32 for positive matching as well
- var size = rewindableStream.Position - pos;
- var br = new BinaryReader(rewindableStream);
- br.ReadUInt32();
- br.ReadUInt32(); // CRC32
- var compressed_size = br.ReadUInt32();
- var uncompressed_size = br.ReadUInt32();
- var uncompressed_64bit = br.ReadInt64();
-
- var test_64bit = ((long)uncompressed_size << 32) | compressed_size;
-
- if (test_64bit == size && test_64bit == uncompressed_64bit)
- {
- Header.CompressedSize = test_64bit;
- Header.UncompressedSize = uncompressed_64bit;
- rewindableStream.Position -= 24;
- break;
- }
-
- if (compressed_size == size && compressed_size == uncompressed_size)
- {
- Header.CompressedSize = compressed_size;
- Header.UncompressedSize = uncompressed_size;
- rewindableStream.Position -= 24;
- break;
- }
- rewindableStream.Position -= 20;
- }
+ rewindableStream.Rewind(deflateStream.InputBuffer);
}
Skipped = true;
diff --git a/src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs b/src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs
index 3e5cd808..e76a2856 100644
--- a/src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs
+++ b/src/SharpCompress/Common/Zip/StreamingZipHeaderFactory.cs
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.IO;
+using System.Linq;
using SharpCompress.Common.Zip.Headers;
using SharpCompress.IO;
@@ -7,8 +8,17 @@ namespace SharpCompress.Common.Zip;
internal class StreamingZipHeaderFactory : ZipHeaderFactory
{
- internal StreamingZipHeaderFactory(string? password, ArchiveEncoding archiveEncoding)
- : base(StreamingMode.Streaming, password, archiveEncoding) { }
+ private IEnumerable? _entries;
+
+ internal StreamingZipHeaderFactory(
+ string? password,
+ ArchiveEncoding archiveEncoding,
+ IEnumerable? entries
+ )
+ : base(StreamingMode.Streaming, password, archiveEncoding)
+ {
+ _entries = entries;
+ }
internal IEnumerable ReadStreamHeader(Stream stream)
{
@@ -87,6 +97,21 @@ internal class StreamingZipHeaderFactory : ZipHeaderFactory
if (header.ZipHeaderType == ZipHeaderType.LocalEntry)
{
var local_header = ((LocalEntryHeader)header);
+ var dir_header = _entries?.FirstOrDefault(
+ entry =>
+ entry.Key == local_header.Name
+ && local_header.CompressedSize == 0
+ && local_header.UncompressedSize == 0
+ && local_header.Crc == 0
+ && local_header.IsDirectory == false
+ );
+
+ if (dir_header != null)
+ {
+ local_header.UncompressedSize = dir_header.Size;
+ local_header.CompressedSize = dir_header.CompressedSize;
+ local_header.Crc = (uint)dir_header.Crc;
+ }
// If we have CompressedSize, there is data to be read
if (local_header.CompressedSize > 0)
diff --git a/src/SharpCompress/Common/Zip/ZipFilePart.cs b/src/SharpCompress/Common/Zip/ZipFilePart.cs
index 6f5a73b9..faefdf15 100644
--- a/src/SharpCompress/Common/Zip/ZipFilePart.cs
+++ b/src/SharpCompress/Common/Zip/ZipFilePart.cs
@@ -17,7 +17,8 @@ namespace SharpCompress.Common.Zip;
internal abstract class ZipFilePart : FilePart
{
- internal ZipFilePart(ZipFileEntry header, Stream stream) : base(header.ArchiveEncoding)
+ internal ZipFilePart(ZipFileEntry header, Stream stream)
+ : base(header.ArchiveEncoding)
{
Header = header;
header.Part = this;
@@ -66,7 +67,17 @@ internal abstract class ZipFilePart : FilePart
{
case ZipCompressionMethod.None:
{
- return stream;
+ if (stream is ReadOnlySubStream)
+ {
+ return stream;
+ }
+
+ if (Header.CompressedSize > 0)
+ {
+ return new ReadOnlySubStream(stream, Header.CompressedSize);
+ }
+
+ return new DataDescriptorStream(stream);
}
case ZipCompressionMethod.Deflate:
{
diff --git a/src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs b/src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs
index 4f8a240b..a975ffbd 100644
--- a/src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs
+++ b/src/SharpCompress/Compressors/BZip2/CBZip2OutputStream.cs
@@ -319,7 +319,8 @@ internal sealed class CBZip2OutputStream : Stream
private int currentChar = -1;
private int runLength;
- public CBZip2OutputStream(Stream inStream) : this(inStream, 9) { }
+ public CBZip2OutputStream(Stream inStream)
+ : this(inStream, 9) { }
public CBZip2OutputStream(Stream inStream, int inBlockSize)
{
diff --git a/src/SharpCompress/Compressors/Deflate/Zlib.cs b/src/SharpCompress/Compressors/Deflate/Zlib.cs
index 1377b116..6fbeb4d9 100644
--- a/src/SharpCompress/Compressors/Deflate/Zlib.cs
+++ b/src/SharpCompress/Compressors/Deflate/Zlib.cs
@@ -189,7 +189,8 @@ public class ZlibException : Exception
/// This ctor collects a message attached to the exception.
///
///
- public ZlibException(string s) : base(s) { }
+ public ZlibException(string s)
+ : base(s) { }
}
internal class SharedUtils
diff --git a/src/SharpCompress/Compressors/Filters/BCJFilter.cs b/src/SharpCompress/Compressors/Filters/BCJFilter.cs
index ca8e8c7e..83a93397 100644
--- a/src/SharpCompress/Compressors/Filters/BCJFilter.cs
+++ b/src/SharpCompress/Compressors/Filters/BCJFilter.cs
@@ -21,8 +21,8 @@ internal class BCJFilter : Filter
private int _pos;
private int _prevMask;
- public BCJFilter(bool isEncoder, Stream baseStream) : base(isEncoder, baseStream, 5) =>
- _pos = 5;
+ public BCJFilter(bool isEncoder, Stream baseStream)
+ : base(isEncoder, baseStream, 5) => _pos = 5;
private static bool Test86MsByte(byte b) => b == 0x00 || b == 0xFF;
diff --git a/src/SharpCompress/Compressors/Filters/BranchExecFilter.cs b/src/SharpCompress/Compressors/Filters/BranchExecFilter.cs
index 091ceda8..9fc439d4 100644
--- a/src/SharpCompress/Compressors/Filters/BranchExecFilter.cs
+++ b/src/SharpCompress/Compressors/Filters/BranchExecFilter.cs
@@ -34,7 +34,17 @@ public sealed class BranchExecFilter
//The previous version of the code would corrupt 2 bytes in the Test.exe at 0x6CF9 (3D6D - should be 4000) - Test zip: WinZip27.Xz.zipx
public static void X86Converter(byte[] buf, uint ip, ref uint state)
{
- bool[] mask_to_allowed_status = new[] { true, true, true, false, true, false, false, false };
+ bool[] mask_to_allowed_status = new[]
+ {
+ true,
+ true,
+ true,
+ false,
+ true,
+ false,
+ false,
+ false
+ };
byte[] mask_to_bit_num = new byte[] { 0, 1, 2, 2, 3, 3, 3, 3 };
@@ -69,8 +79,7 @@ public sealed class BranchExecFilter
if (prev_mask != 0)
{
b = buf[i + 4 - mask_to_bit_num[prev_mask]];
- if (!mask_to_allowed_status[prev_mask]
- || X86TestByte(b))
+ if (!mask_to_allowed_status[prev_mask] || X86TestByte(b))
{
prev_pos = i;
prev_mask = (prev_mask << 1) | 1;
@@ -83,7 +92,8 @@ public sealed class BranchExecFilter
if (X86TestByte(buf[i + 4]))
{
- src = ((uint)buf[i + 4] << 24)
+ src =
+ ((uint)buf[i + 4] << 24)
| ((uint)buf[i + 3] << 16)
| ((uint)buf[i + 2] << 8)
| buf[i + 1];
diff --git a/src/SharpCompress/Compressors/Filters/DeltaFilter.cs b/src/SharpCompress/Compressors/Filters/DeltaFilter.cs
new file mode 100644
index 00000000..c5fbeb41
--- /dev/null
+++ b/src/SharpCompress/Compressors/Filters/DeltaFilter.cs
@@ -0,0 +1,37 @@
+using System;
+using System.IO;
+
+namespace SharpCompress.Compressors.Filters
+{
+ internal class DeltaFilter : Filter
+ {
+ private const int DISTANCE_MIN = 1;
+ private const int DISTANCE_MAX = 256;
+ private const int DISTANCE_MASK = DISTANCE_MAX - 1;
+
+ private int _distance;
+ private byte[] _history;
+ private int _position;
+
+ public DeltaFilter(bool isEncoder, Stream baseStream, byte[] info)
+ : base(isEncoder, baseStream, 1)
+ {
+ _distance = info[0];
+ _history = new byte[DISTANCE_MAX];
+ _position = 0;
+ }
+
+ protected override int Transform(byte[] buffer, int offset, int count)
+ {
+ int end = offset + count;
+
+ for (int i = offset; i < end; i++)
+ {
+ buffer[i] += _history[(_distance + _position--) & DISTANCE_MASK];
+ _history[_position & DISTANCE_MASK] = buffer[i];
+ }
+
+ return count;
+ }
+ }
+}
diff --git a/src/SharpCompress/Compressors/LZMA/BitVector.cs b/src/SharpCompress/Compressors/LZMA/BitVector.cs
index 5b40536d..9e998430 100644
--- a/src/SharpCompress/Compressors/LZMA/BitVector.cs
+++ b/src/SharpCompress/Compressors/LZMA/BitVector.cs
@@ -28,7 +28,8 @@ internal class BitVector
}
}
- public BitVector(List bits) : this(bits.Count)
+ public BitVector(List bits)
+ : this(bits.Count)
{
for (var i = 0; i < bits.Count; i++)
{
diff --git a/src/SharpCompress/Compressors/LZMA/ICoder.cs b/src/SharpCompress/Compressors/LZMA/ICoder.cs
index 71265d70..dcddf929 100644
--- a/src/SharpCompress/Compressors/LZMA/ICoder.cs
+++ b/src/SharpCompress/Compressors/LZMA/ICoder.cs
@@ -8,7 +8,8 @@ namespace SharpCompress.Compressors.LZMA;
///
internal class DataErrorException : Exception
{
- public DataErrorException() : base("Data Error") { }
+ public DataErrorException()
+ : base("Data Error") { }
}
///
@@ -16,7 +17,8 @@ internal class DataErrorException : Exception
///
internal class InvalidParamException : Exception
{
- public InvalidParamException() : base("Invalid Parameter") { }
+ public InvalidParamException()
+ : base("Invalid Parameter") { }
}
public interface ICodeProgress
diff --git a/src/SharpCompress/Compressors/LZMA/LzmaEncoder.cs b/src/SharpCompress/Compressors/LZMA/LzmaEncoder.cs
index 1dfb43b1..558fe37b 100644
--- a/src/SharpCompress/Compressors/LZMA/LzmaEncoder.cs
+++ b/src/SharpCompress/Compressors/LZMA/LzmaEncoder.cs
@@ -1725,7 +1725,10 @@ internal class Encoder : ICoder, ISetCoderProperties, IWriteCoderProperties
return -1;
}
- public void SetCoderProperties(ReadOnlySpan propIDs, ReadOnlySpan