diff --git a/SabreTools.Compression/Blast/State.cs b/SabreTools.Compression/Blast/State.cs index b946c7a..82e2671 100644 --- a/SabreTools.Compression/Blast/State.cs +++ b/SabreTools.Compression/Blast/State.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using static SabreTools.Compression.Blast.Constants; namespace SabreTools.Compression.Blast @@ -148,7 +147,9 @@ namespace SabreTools.Compression.Blast { try { - OutHow.AddRange(Output.Take((int)Next)); + byte[] next = new byte[Next]; + Array.Copy(Output, next, next.Length); + OutHow.AddRange(next); return true; } catch diff --git a/SabreTools.Compression/ExtensionAttribute.cs b/SabreTools.Compression/ExtensionAttribute.cs new file mode 100644 index 0000000..f7d035b --- /dev/null +++ b/SabreTools.Compression/ExtensionAttribute.cs @@ -0,0 +1,9 @@ +#if NET20 + +namespace System.Runtime.CompilerServices +{ + [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)] + internal sealed class ExtensionAttribute : Attribute {} +} + +#endif \ No newline at end of file diff --git a/SabreTools.Compression/LZ/Decompressor.cs b/SabreTools.Compression/LZ/Decompressor.cs index a11d599..147f43d 100644 --- a/SabreTools.Compression/LZ/Decompressor.cs +++ b/SabreTools.Compression/LZ/Decompressor.cs @@ -1,5 +1,5 @@ +using System; using System.IO; -using System.Linq; using System.Text; using SabreTools.IO.Extensions; using SabreTools.Models.Compression.LZ; @@ -181,7 +181,8 @@ namespace SabreTools.Compression.LZ } // Initialize the table with all spaces - byte[] table = Enumerable.Repeat((byte)' ', LZ_TABLE_SIZE).ToArray(); + byte[] table = new byte[LZ_TABLE_SIZE]; + table = Array.ConvertAll(table, b => (byte)' '); // Build the state var state = new State @@ -247,7 +248,8 @@ namespace SabreTools.Compression.LZ state.RealCurrent = 0; state.ByteType = 0; state.StringLength = 0; - state.Table = Enumerable.Repeat((byte)' ', LZ_TABLE_SIZE).ToArray(); + state.Table = new byte[LZ_TABLE_SIZE]; + state.Table = Array.ConvertAll(state.Table, b => (byte)' '); state.CurrentTableEntry = 0xFF0; } diff --git a/SabreTools.Compression/MSZIP/DeflateDecompressor.cs b/SabreTools.Compression/MSZIP/DeflateDecompressor.cs index a6667dc..54583aa 100644 --- a/SabreTools.Compression/MSZIP/DeflateDecompressor.cs +++ b/SabreTools.Compression/MSZIP/DeflateDecompressor.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using SabreTools.IO.Streams; using SabreTools.Models.Compression.MSZIP; using static SabreTools.Models.Compression.MSZIP.Constants; @@ -316,13 +315,15 @@ namespace SabreTools.Compression.MSZIP if (distance == null) return null; - byte[] arr = bytes.Skip(bytes.Count - (int)distance).Take((int)length).ToArray(); + byte[] bytesArr = [.. bytes]; + byte[] arr = new byte[(int)length]; + Array.Copy(bytesArr, bytes.Count - (int)distance, arr, 0, (int)length); bytes.AddRange(arr); } } // Return the decoded array - return bytes.ToArray(); + return [.. bytes]; } /// diff --git a/SabreTools.Compression/MSZIP/HuffmanDecoder.cs b/SabreTools.Compression/MSZIP/HuffmanDecoder.cs index 1f954b8..1570102 100644 --- a/SabreTools.Compression/MSZIP/HuffmanDecoder.cs +++ b/SabreTools.Compression/MSZIP/HuffmanDecoder.cs @@ -1,6 +1,8 @@ using System; using System.IO; +#if NET35_OR_GREATER || NETCOREAPP using System.Linq; +#endif using SabreTools.IO.Streams; namespace SabreTools.Compression.MSZIP @@ -27,7 +29,15 @@ namespace SabreTools.Compression.MSZIP HuffmanNode? root = null; // Determine the value for max_bits +#if NET20 + uint max_bits = 0; + foreach (uint u in lengths) + { + max_bits = u > max_bits ? u : max_bits; + } +#else uint max_bits = lengths.Max(); +#endif // Count the number of codes for each code length int[] bl_count = new int[max_bits + 1];