add caching and some cleanup

This commit is contained in:
Adam Hathcock 2023-03-21 13:41:36 +00:00
parent 813d9eace3
commit fa2a52ff41
5 changed files with 69 additions and 42 deletions

View file

@ -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:

View file

@ -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

View file

@ -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(
@ -37,8 +39,19 @@ Target(
}
);
Target(
Format,
() =>
{
Run("dotnet", "tool restore", "./csharp");
Run("dotnet", "csharpier --check .", "./csharp");
}
);
Target(Restore, DependsOn(Format), () => Run("dotnet", "restore --locked-mode", "./csharp"));
Target(
Build,
DependsOn(Restore),
() =>
{
Run("dotnet", "build src/SharpCompress/SharpCompress.csproj -c Release");
@ -63,7 +76,10 @@ 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 --no-build --verbosity=normal"
);
}
}
);

View file

@ -6,32 +6,29 @@ namespace SharpCompress.Compressors.Xz.Filters;
public abstract class BlockFilter : ReadOnlyStream
{
[CLSCompliant(false)]
public enum FilterTypes : ulong
private enum FilterTypes : ulong
{
DELTA = 0x03,
ARCH_x86_FILTER = 0x04,
ARCH_PowerPC_FILTER = 0x05,
ARCH_IA64_FILTER = 0x06,
ARCH_ARM_FILTER = 0x07,
ARCH_ARMTHUMB_FILTER = 0x08,
ARCH_SPARC_FILTER = 0x09,
LZMA2 = 0x21
//Delta = 0x03,
ArchX86Filter = 0x04,
ArchPowerPcFilter = 0x05,
ArchIa64Filter = 0x06,
ArchArmFilter = 0x07,
ArchArmThumbFilter = 0x08,
ArchSparcFilter = 0x09,
Lzma2 = 0x21
}
private static readonly Dictionary<FilterTypes, Func<BlockFilter>> FilterMap = new Dictionary<
FilterTypes,
Func<BlockFilter>
>
{
{ FilterTypes.ARCH_x86_FILTER, () => new X86Filter() },
{ FilterTypes.ARCH_PowerPC_FILTER, () => new PowerPCFilter() },
{ FilterTypes.ARCH_IA64_FILTER, () => new IA64Filter() },
{ FilterTypes.ARCH_ARM_FILTER, () => new ArmFilter() },
{ FilterTypes.ARCH_ARMTHUMB_FILTER, () => new ArmThumbFilter() },
{ FilterTypes.ARCH_SPARC_FILTER, () => new SparcFilter() },
{ FilterTypes.LZMA2, () => new Lzma2Filter() }
};
private static readonly Dictionary<FilterTypes, Func<BlockFilter>> FILTER_MAP =
new()
{
{ FilterTypes.ArchX86Filter, () => new X86Filter() },
{ FilterTypes.ArchPowerPcFilter, () => new PowerPCFilter() },
{ FilterTypes.ArchIa64Filter, () => new IA64Filter() },
{ FilterTypes.ArchArmFilter, () => new ArmFilter() },
{ FilterTypes.ArchArmThumbFilter, () => new ArmThumbFilter() },
{ FilterTypes.ArchSparcFilter, () => new SparcFilter() },
{ FilterTypes.Lzma2, () => new Lzma2Filter() }
};
public abstract bool AllowAsLast { get; }
public abstract bool AllowAsNonLast { get; }
@ -43,12 +40,12 @@ public abstract class BlockFilter : ReadOnlyStream
public static BlockFilter Read(BinaryReader reader)
{
var filterType = (FilterTypes)reader.ReadXZInteger();
if (!FilterMap.ContainsKey(filterType))
if (!FILTER_MAP.ContainsKey(filterType))
{
throw new NotImplementedException($"Filter {filterType} has not yet been implemented");
}
var filter = FilterMap[filterType]()!;
var filter = FILTER_MAP[filterType]();
var sizeOfProperties = reader.ReadXZInteger();
if (sizeOfProperties > int.MaxValue)

View file

@ -9,10 +9,10 @@ namespace SharpCompress.IO;
public class SourceStream : Stream
{
private long _prevSize;
private List<FileInfo> _files;
private List<Stream> _streams;
private Func<int, FileInfo?> _getFilePart;
private Func<int, Stream?> _getStreamPart;
private readonly List<FileInfo> _files;
private readonly List<Stream> _streams;
private readonly Func<int, FileInfo?> _getFilePart;
private readonly Func<int, Stream?> _getStreamPart;
private int _stream;
public SourceStream(FileInfo file, Func<int, FileInfo?> getPart, ReaderOptions options)
@ -39,10 +39,10 @@ public class SourceStream : Stream
{
_streams.Add(stream!);
_getStreamPart = getStreamPart!;
_getFilePart = new Func<int, FileInfo>(a => null!);
if (stream is FileStream)
_getFilePart = _ => null!;
if (stream is FileStream fileStream)
{
_files.Add(new FileInfo(((FileStream)stream!).Name));
_files.Add(new FileInfo(fileStream.Name));
}
}
else
@ -50,7 +50,7 @@ public class SourceStream : Stream
_files.Add(file!);
_streams.Add(_files[0].OpenRead());
_getFilePart = getFilePart!;
_getStreamPart = new Func<int, Stream>(a => null!);
_getStreamPart = _ => null!;
}
_stream = 0;
_prevSize = 0;
@ -98,9 +98,9 @@ public class SourceStream : Stream
}
//throw new Exception($"Stream part {idx} not available.");
_streams.Add(s);
if (s is FileStream)
if (s is FileStream stream)
{
_files.Add(new FileInfo(((FileStream)s).Name));
_files.Add(new FileInfo(stream.Name));
}
}
}
@ -123,11 +123,11 @@ public class SourceStream : Stream
public override bool CanWrite => false;
public override long Length => (!IsVolumes ? _streams.Sum(a => a.Length) : Current.Length);
public override long Length => !IsVolumes ? _streams.Sum(a => a.Length) : Current.Length;
public override long Position
{
get => _prevSize + Current.Position; //_prevSize is 0 for multivolume
get => _prevSize + Current.Position; //_prevSize is 0 for multi-volume
set => Seek(value, SeekOrigin.Begin);
}
@ -222,9 +222,12 @@ public class SourceStream : Stream
{
try
{
stream?.Dispose();
stream.Dispose();
}
catch
{
// ignored
}
catch { }
}
_streams.Clear();
_files.Clear();