From 9540b01bcce1eeb07ebd787c899d13c53521cdcd Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Thu, 10 Oct 2019 09:24:41 +0100 Subject: [PATCH] NET Standard 1.3 and 2.0 only (#482) * Remove NET35, NET45 and NET Standard 1.0 * Update README and memset * Remove NETCORE build flag * NET 46 too? * Update packages and usage --- README.md | 2 +- build.cake | 5 +- src/SharpCompress/Archives/AbstractArchive.cs | 4 +- .../Archives/AbstractWritableArchive.cs | 2 - src/SharpCompress/Archives/ArchiveFactory.cs | 4 -- .../Archives/GZip/GZipArchive.cs | 6 -- .../Archives/IArchiveEntryExtensions.cs | 11 ++-- .../Archives/IArchiveExtensions.cs | 14 ++--- .../Archives/IWritableArchiveExtensions.cs | 11 +--- .../Archives/Rar/FileInfoRarArchiveVolume.cs | 5 +- .../Archives/Rar/FileInfoRarFilePart.cs | 5 +- src/SharpCompress/Archives/Rar/RarArchive.cs | 11 +--- .../Archives/Rar/RarArchiveVolumeFactory.cs | 7 +-- .../Archives/Rar/SeekableFilePart.cs | 2 - .../Archives/SevenZip/SevenZipArchive.cs | 5 -- src/SharpCompress/Archives/Tar/TarArchive.cs | 11 +--- src/SharpCompress/Archives/Zip/ZipArchive.cs | 15 +---- src/SharpCompress/Common/ArchiveEncoding.cs | 7 --- src/SharpCompress/Common/ExtractionMethods.cs | 7 +-- src/SharpCompress/Common/GZip/GZipVolume.cs | 2 - src/SharpCompress/Common/IEntry.Extensions.cs | 5 +- src/SharpCompress/Common/IVolume.cs | 4 -- .../Common/Rar/Headers/FileHeader.cs | 9 --- .../Common/Rar/Headers/RarHeaderFactory.cs | 8 --- .../Common/Rar/RarCryptoBinaryReader.cs | 6 +- .../Common/Rar/RarCryptoWrapper.cs | 5 +- src/SharpCompress/Common/Rar/RarRijndael.cs | 4 +- .../Common/Zip/Headers/ZipFileEntry.cs | 4 +- .../Common/Zip/WinzipAesCryptoStream.cs | 3 - .../Common/Zip/WinzipAesEncryptionData.cs | 3 - src/SharpCompress/Common/Zip/ZipFilePart.cs | 2 - .../Common/Zip/ZipHeaderFactory.cs | 7 --- .../Compressors/LZMA/AesDecoderStream.cs | 8 +-- src/SharpCompress/Compressors/LZMA/Log.cs | 8 --- .../Compressors/LZMA/Registry.cs | 2 - src/SharpCompress/EnumExtensions.cs | 18 ------ src/SharpCompress/IO/MarkingBinaryReader.cs | 7 --- .../Readers/IReaderExtensions.cs | 6 +- src/SharpCompress/SharpCompress.csproj | 22 ++----- src/SharpCompress/Utility.cs | 59 +------------------ .../Writers/IWriterExtensions.cs | 16 ++--- .../SharpCompress.Test.csproj | 2 +- 42 files changed, 44 insertions(+), 300 deletions(-) delete mode 100644 src/SharpCompress/EnumExtensions.cs diff --git a/README.md b/README.md index 47fce793..26e1dc35 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # SharpCompress -SharpCompress is a compression library in pure C# for .NET 3.5, 4.5, .NET Standard 1.0, 1.3 that can unrar, un7zip, unzip, untar unbzip2 and ungzip with forward-only reading and file random access APIs. Write support for zip/tar/bzip2/gzip are implemented. +SharpCompress is a compression library in pure C# for .NET Standard 1.3 and 2.0 that can unrar, un7zip, unzip, untar unbzip2 and ungzip with forward-only reading and file random access APIs. Write support for zip/tar/bzip2/gzip are implemented. The major feature is support for non-seekable streams so large files can be processed on the fly (i.e. download stream). diff --git a/build.cake b/build.cake index 1f0caa98..92c77257 100644 --- a/build.cake +++ b/build.cake @@ -24,16 +24,13 @@ Task("Build") { var settings = new DotNetCoreBuildSettings { - Framework = "netstandard1.0", + Framework = "netstandard1.3", Configuration = "Release", NoRestore = true }; DotNetCoreBuild("./src/SharpCompress/SharpCompress.csproj", settings); - settings.Framework = "netstandard1.3"; - DotNetCoreBuild("./src/SharpCompress/SharpCompress.csproj", settings); - settings.Framework = "netstandard2.0"; DotNetCoreBuild("./src/SharpCompress/SharpCompress.csproj", settings); } diff --git a/src/SharpCompress/Archives/AbstractArchive.cs b/src/SharpCompress/Archives/AbstractArchive.cs index 2981f734..88a2424e 100644 --- a/src/SharpCompress/Archives/AbstractArchive.cs +++ b/src/SharpCompress/Archives/AbstractArchive.cs @@ -23,8 +23,7 @@ namespace SharpCompress.Archives protected ReaderOptions ReaderOptions { get; } private bool disposed; - -#if !NO_FILE + internal AbstractArchive(ArchiveType type, FileInfo fileInfo, ReaderOptions readerOptions) { Type = type; @@ -40,7 +39,6 @@ namespace SharpCompress.Archives protected abstract IEnumerable LoadVolumes(FileInfo file); -#endif internal AbstractArchive(ArchiveType type, IEnumerable streams, ReaderOptions readerOptions) { diff --git a/src/SharpCompress/Archives/AbstractWritableArchive.cs b/src/SharpCompress/Archives/AbstractWritableArchive.cs index 5f38d459..677cb04a 100644 --- a/src/SharpCompress/Archives/AbstractWritableArchive.cs +++ b/src/SharpCompress/Archives/AbstractWritableArchive.cs @@ -28,12 +28,10 @@ namespace SharpCompress.Archives { } -#if !NO_FILE internal AbstractWritableArchive(ArchiveType type, FileInfo fileInfo, ReaderOptions readerFactoryOptions) : base(type, fileInfo, readerFactoryOptions) { } -#endif public override ICollection Entries { diff --git a/src/SharpCompress/Archives/ArchiveFactory.cs b/src/SharpCompress/Archives/ArchiveFactory.cs index eee47bcf..fb9dad6a 100644 --- a/src/SharpCompress/Archives/ArchiveFactory.cs +++ b/src/SharpCompress/Archives/ArchiveFactory.cs @@ -6,7 +6,6 @@ using SharpCompress.Archives.SevenZip; using SharpCompress.Archives.Tar; using SharpCompress.Archives.Zip; using SharpCompress.Common; -using SharpCompress.Compressors.LZMA; using SharpCompress.Readers; namespace SharpCompress.Archives @@ -82,8 +81,6 @@ namespace SharpCompress.Archives } } -#if !NO_FILE - /// /// Constructor expects a filepath to an existing file. /// @@ -148,6 +145,5 @@ namespace SharpCompress.Archives } } } -#endif } } diff --git a/src/SharpCompress/Archives/GZip/GZipArchive.cs b/src/SharpCompress/Archives/GZip/GZipArchive.cs index f3a94f81..7108be56 100644 --- a/src/SharpCompress/Archives/GZip/GZipArchive.cs +++ b/src/SharpCompress/Archives/GZip/GZipArchive.cs @@ -13,8 +13,6 @@ namespace SharpCompress.Archives.GZip { public class GZipArchive : AbstractWritableArchive { -#if !NO_FILE - /// /// Constructor expects a filepath to an existing file. /// @@ -36,7 +34,6 @@ namespace SharpCompress.Archives.GZip fileInfo.CheckNotNull(nameof(fileInfo)); return new GZipArchive(fileInfo, readerOptions ?? new ReaderOptions()); } -#endif /// /// Takes a seekable Stream as a source @@ -54,8 +51,6 @@ namespace SharpCompress.Archives.GZip return new GZipArchive(); } -#if !NO_FILE - /// /// Constructor with a FileInfo object to an existing file. /// @@ -100,7 +95,6 @@ namespace SharpCompress.Archives.GZip SaveTo(stream, new WriterOptions(CompressionType.GZip)); } } -#endif public static bool IsGZipFile(Stream stream) { diff --git a/src/SharpCompress/Archives/IArchiveEntryExtensions.cs b/src/SharpCompress/Archives/IArchiveEntryExtensions.cs index e1716fb3..e1edb20a 100644 --- a/src/SharpCompress/Archives/IArchiveEntryExtensions.cs +++ b/src/SharpCompress/Archives/IArchiveEntryExtensions.cs @@ -36,12 +36,10 @@ namespace SharpCompress.Archives } streamListener.FireEntryExtractionEnd(archiveEntry); } - -#if !NO_FILE - -/// -/// Extract to specific directory, retaining filename -/// + + /// + /// Extract to specific directory, retaining filename + /// public static void WriteToDirectory(this IArchiveEntry entry, string destinationDirectory, ExtractionOptions options = null) { @@ -65,6 +63,5 @@ namespace SharpCompress.Archives } }); } -#endif } } \ No newline at end of file diff --git a/src/SharpCompress/Archives/IArchiveExtensions.cs b/src/SharpCompress/Archives/IArchiveExtensions.cs index 7b669666..391ad3d4 100644 --- a/src/SharpCompress/Archives/IArchiveExtensions.cs +++ b/src/SharpCompress/Archives/IArchiveExtensions.cs @@ -1,18 +1,13 @@ -#if !NO_FILE -using System.Linq; +using System.Linq; using SharpCompress.Common; -#endif - namespace SharpCompress.Archives { public static class IArchiveExtensions { -#if !NO_FILE - -/// -/// Extract to specific directory, retaining filename -/// + /// + /// Extract to specific directory, retaining filename + /// public static void WriteToDirectory(this IArchive archive, string destinationDirectory, ExtractionOptions options = null) { @@ -21,6 +16,5 @@ namespace SharpCompress.Archives entry.WriteToDirectory(destinationDirectory, options); } } -#endif } } \ No newline at end of file diff --git a/src/SharpCompress/Archives/IWritableArchiveExtensions.cs b/src/SharpCompress/Archives/IWritableArchiveExtensions.cs index bee42a49..606841d4 100644 --- a/src/SharpCompress/Archives/IWritableArchiveExtensions.cs +++ b/src/SharpCompress/Archives/IWritableArchiveExtensions.cs @@ -1,6 +1,4 @@ -#if !NO_FILE -using System; -#endif +using System; using System.IO; using SharpCompress.Writers; @@ -8,8 +6,6 @@ namespace SharpCompress.Archives { public static class IWritableArchiveExtensions { -#if !NO_FILE - public static void AddEntry(this IWritableArchive writableArchive, string entryPath, string filePath) { @@ -39,11 +35,7 @@ namespace SharpCompress.Archives this IWritableArchive writableArchive, string filePath, string searchPattern = "*.*", SearchOption searchOption = SearchOption.AllDirectories) { -#if NET35 - foreach (var path in Directory.GetFiles(filePath, searchPattern, searchOption)) -#else foreach (var path in Directory.EnumerateFiles(filePath, searchPattern, searchOption)) -#endif { var fileInfo = new FileInfo(path); writableArchive.AddEntry(path.Substring(filePath.Length), fileInfo.OpenRead(), true, fileInfo.Length, @@ -58,6 +50,5 @@ namespace SharpCompress.Archives } return writableArchive.AddEntry(key, fileInfo.OpenRead(), true, fileInfo.Length, fileInfo.LastWriteTime); } -#endif } } \ No newline at end of file diff --git a/src/SharpCompress/Archives/Rar/FileInfoRarArchiveVolume.cs b/src/SharpCompress/Archives/Rar/FileInfoRarArchiveVolume.cs index dbc1d170..a3f57300 100644 --- a/src/SharpCompress/Archives/Rar/FileInfoRarArchiveVolume.cs +++ b/src/SharpCompress/Archives/Rar/FileInfoRarArchiveVolume.cs @@ -1,6 +1,4 @@ - -#if !NO_FILE -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using System.Linq; using SharpCompress.Common.Rar; @@ -44,4 +42,3 @@ namespace SharpCompress.Archives.Rar } } } -#endif diff --git a/src/SharpCompress/Archives/Rar/FileInfoRarFilePart.cs b/src/SharpCompress/Archives/Rar/FileInfoRarFilePart.cs index 4b31a774..2b487c46 100644 --- a/src/SharpCompress/Archives/Rar/FileInfoRarFilePart.cs +++ b/src/SharpCompress/Archives/Rar/FileInfoRarFilePart.cs @@ -1,6 +1,4 @@ - -#if !NO_FILE -using System.IO; +using System.IO; using SharpCompress.Common.Rar.Headers; namespace SharpCompress.Archives.Rar @@ -25,4 +23,3 @@ namespace SharpCompress.Archives.Rar } } } -#endif \ No newline at end of file diff --git a/src/SharpCompress/Archives/Rar/RarArchive.cs b/src/SharpCompress/Archives/Rar/RarArchive.cs index 3305796c..06dff06d 100644 --- a/src/SharpCompress/Archives/Rar/RarArchive.cs +++ b/src/SharpCompress/Archives/Rar/RarArchive.cs @@ -15,8 +15,6 @@ namespace SharpCompress.Archives.Rar internal Lazy UnpackV2017 { get; } = new Lazy(() => new SharpCompress.Compressors.Rar.UnpackV2017.Unpack()); internal Lazy UnpackV1 { get; } = new Lazy(() => new SharpCompress.Compressors.Rar.UnpackV1.Unpack()); -#if !NO_FILE - /// /// Constructor with a FileInfo object to an existing file. /// @@ -31,7 +29,6 @@ namespace SharpCompress.Archives.Rar { return RarArchiveVolumeFactory.GetParts(file, ReaderOptions); } -#endif /// /// Takes multiple seekable Streams for a multi-part archive @@ -63,9 +60,6 @@ namespace SharpCompress.Archives.Rar public override bool IsSolid => Volumes.First().IsSolidArchive; #region Creation - -#if !NO_FILE - /// /// Constructor with a FileInfo object to an existing file. /// @@ -87,7 +81,6 @@ namespace SharpCompress.Archives.Rar fileInfo.CheckNotNull(nameof(fileInfo)); return new RarArchive(fileInfo, options ?? new ReaderOptions()); } -#endif /// /// Takes a seekable Stream as a source @@ -111,7 +104,6 @@ namespace SharpCompress.Archives.Rar return new RarArchive(streams, options ?? new ReaderOptions()); } -#if !NO_FILE public static bool IsRarFile(string filePath) { return IsRarFile(new FileInfo(filePath)); @@ -128,8 +120,7 @@ namespace SharpCompress.Archives.Rar return IsRarFile(stream); } } -#endif - + public static bool IsRarFile(Stream stream, ReaderOptions options = null) { try diff --git a/src/SharpCompress/Archives/Rar/RarArchiveVolumeFactory.cs b/src/SharpCompress/Archives/Rar/RarArchiveVolumeFactory.cs index 57eb3c69..0ecd5c2c 100644 --- a/src/SharpCompress/Archives/Rar/RarArchiveVolumeFactory.cs +++ b/src/SharpCompress/Archives/Rar/RarArchiveVolumeFactory.cs @@ -3,11 +3,9 @@ using System.Collections.Generic; using System.IO; using SharpCompress.Common.Rar; using SharpCompress.Readers; -#if !NO_FILE using System.Linq; using System.Text; using SharpCompress.Common.Rar.Headers; -#endif namespace SharpCompress.Archives.Rar { @@ -25,8 +23,7 @@ namespace SharpCompress.Archives.Rar yield return part; } } - -#if !NO_FILE + internal static IEnumerable GetParts(FileInfo fileInfo, ReaderOptions options) { FileInfoRarArchiveVolume part = new FileInfoRarArchiveVolume(fileInfo, options); @@ -141,7 +138,5 @@ namespace SharpCompress.Archives.Rar throw new ArgumentException("Filename invalid or next archive could not be found:" + fileInfo.FullName); } - -#endif } } \ No newline at end of file diff --git a/src/SharpCompress/Archives/Rar/SeekableFilePart.cs b/src/SharpCompress/Archives/Rar/SeekableFilePart.cs index b7d3affc..937bd39a 100644 --- a/src/SharpCompress/Archives/Rar/SeekableFilePart.cs +++ b/src/SharpCompress/Archives/Rar/SeekableFilePart.cs @@ -19,12 +19,10 @@ namespace SharpCompress.Archives.Rar internal override Stream GetCompressedStream() { stream.Position = FileHeader.DataStartPosition; -#if !NO_CRYPTO if (FileHeader.R4Salt != null) { return new RarCryptoWrapper(stream, password, FileHeader.R4Salt); } -#endif return stream; } diff --git a/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs b/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs index 9cf64142..dd56eeff 100644 --- a/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs +++ b/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs @@ -13,8 +13,6 @@ namespace SharpCompress.Archives.SevenZip public class SevenZipArchive : AbstractArchive { private ArchiveDatabase database; -#if !NO_FILE - /// /// Constructor expects a filepath to an existing file. /// @@ -36,7 +34,6 @@ namespace SharpCompress.Archives.SevenZip fileInfo.CheckNotNull("fileInfo"); return new SevenZipArchive(fileInfo, readerOptions ?? new ReaderOptions()); } -#endif /// /// Takes a seekable Stream as a source /// @@ -48,7 +45,6 @@ namespace SharpCompress.Archives.SevenZip return new SevenZipArchive(stream, readerOptions ?? new ReaderOptions()); } -#if !NO_FILE internal SevenZipArchive(FileInfo fileInfo, ReaderOptions readerOptions) : base(ArchiveType.SevenZip, fileInfo, readerOptions) { @@ -75,7 +71,6 @@ namespace SharpCompress.Archives.SevenZip return IsSevenZipFile(stream); } } -#endif internal SevenZipArchive(Stream stream, ReaderOptions readerOptions) : base(ArchiveType.SevenZip, stream.AsEnumerable(), readerOptions) diff --git a/src/SharpCompress/Archives/Tar/TarArchive.cs b/src/SharpCompress/Archives/Tar/TarArchive.cs index 96c13cb1..2e4ab65a 100644 --- a/src/SharpCompress/Archives/Tar/TarArchive.cs +++ b/src/SharpCompress/Archives/Tar/TarArchive.cs @@ -15,8 +15,6 @@ namespace SharpCompress.Archives.Tar { public class TarArchive : AbstractWritableArchive { -#if !NO_FILE - /// /// Constructor expects a filepath to an existing file. /// @@ -38,7 +36,6 @@ namespace SharpCompress.Archives.Tar fileInfo.CheckNotNull(nameof(fileInfo)); return new TarArchive(fileInfo, readerOptions ?? new ReaderOptions()); } -#endif /// /// Takes a seekable Stream as a source @@ -51,8 +48,6 @@ namespace SharpCompress.Archives.Tar return new TarArchive(stream, readerOptions ?? new ReaderOptions()); } -#if !NO_FILE - public static bool IsTarFile(string filePath) { return IsTarFile(new FileInfo(filePath)); @@ -69,7 +64,6 @@ namespace SharpCompress.Archives.Tar return IsTarFile(stream); } } -#endif public static bool IsTarFile(Stream stream) { @@ -85,9 +79,7 @@ namespace SharpCompress.Archives.Tar } return false; } - -#if !NO_FILE - + /// /// Constructor with a FileInfo object to an existing file. /// @@ -102,7 +94,6 @@ namespace SharpCompress.Archives.Tar { return new TarVolume(file.OpenRead(), ReaderOptions).AsEnumerable(); } -#endif /// /// Takes multiple seekable Streams for a multi-part archive diff --git a/src/SharpCompress/Archives/Zip/ZipArchive.cs b/src/SharpCompress/Archives/Zip/ZipArchive.cs index f75cdc90..5377bce7 100644 --- a/src/SharpCompress/Archives/Zip/ZipArchive.cs +++ b/src/SharpCompress/Archives/Zip/ZipArchive.cs @@ -22,9 +22,7 @@ namespace SharpCompress.Archives.Zip /// if the compression method is set to deflate /// public CompressionLevel DeflateCompressionLevel { get; set; } - -#if !NO_FILE - + /// /// Constructor expects a filepath to an existing file. /// @@ -46,7 +44,6 @@ namespace SharpCompress.Archives.Zip fileInfo.CheckNotNull(nameof(fileInfo)); return new ZipArchive(fileInfo, readerOptions ?? new ReaderOptions()); } -#endif /// /// Takes a seekable Stream as a source @@ -58,9 +55,7 @@ namespace SharpCompress.Archives.Zip stream.CheckNotNull(nameof(stream)); return new ZipArchive(stream, readerOptions ?? new ReaderOptions()); } - -#if !NO_FILE - + public static bool IsZipFile(string filePath, string password = null) { return IsZipFile(new FileInfo(filePath), password); @@ -77,7 +72,6 @@ namespace SharpCompress.Archives.Zip return IsZipFile(stream, password); } } -#endif public static bool IsZipFile(Stream stream, string password = null) { @@ -101,9 +95,7 @@ namespace SharpCompress.Archives.Zip return false; } } - -#if !NO_FILE - + /// /// Constructor with a FileInfo object to an existing file. /// @@ -119,7 +111,6 @@ namespace SharpCompress.Archives.Zip { return new ZipVolume(file.OpenRead(), ReaderOptions).AsEnumerable(); } -#endif internal ZipArchive() : base(ArchiveType.Zip) diff --git a/src/SharpCompress/Common/ArchiveEncoding.cs b/src/SharpCompress/Common/ArchiveEncoding.cs index e5465030..e4418fd5 100644 --- a/src/SharpCompress/Common/ArchiveEncoding.cs +++ b/src/SharpCompress/Common/ArchiveEncoding.cs @@ -28,21 +28,14 @@ namespace SharpCompress.Common public ArchiveEncoding() { -#if NETSTANDARD1_0 - Default = Encoding.GetEncoding("cp437"); - Password = Encoding.GetEncoding("cp437"); -#else Default = Encoding.GetEncoding(437); Password = Encoding.GetEncoding(437); -#endif } -#if NETSTANDARD1_3 || NETSTANDARD2_0 static ArchiveEncoding() { Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); } -#endif public string Decode(byte[] bytes) { diff --git a/src/SharpCompress/Common/ExtractionMethods.cs b/src/SharpCompress/Common/ExtractionMethods.cs index 15efd220..22972e3e 100644 --- a/src/SharpCompress/Common/ExtractionMethods.cs +++ b/src/SharpCompress/Common/ExtractionMethods.cs @@ -1,14 +1,10 @@ -#if !NO_FILE -using System; +using System; using System.IO; -#endif namespace SharpCompress.Common { internal static class ExtractionMethods { - -#if !NO_FILE /// /// Extract to specific directory, retaining filename /// @@ -93,6 +89,5 @@ namespace SharpCompress.Common entry.PreserveExtractionOptions(destinationFileName, options); } } -#endif } } \ No newline at end of file diff --git a/src/SharpCompress/Common/GZip/GZipVolume.cs b/src/SharpCompress/Common/GZip/GZipVolume.cs index 7da73560..51c5e246 100644 --- a/src/SharpCompress/Common/GZip/GZipVolume.cs +++ b/src/SharpCompress/Common/GZip/GZipVolume.cs @@ -10,13 +10,11 @@ namespace SharpCompress.Common.GZip { } -#if !NO_FILE public GZipVolume(FileInfo fileInfo, ReaderOptions options) : base(fileInfo.OpenRead(), options) { options.LeaveStreamOpen = false; } -#endif public override bool IsFirstVolume => true; diff --git a/src/SharpCompress/Common/IEntry.Extensions.cs b/src/SharpCompress/Common/IEntry.Extensions.cs index 76d75a8f..9c1e31af 100644 --- a/src/SharpCompress/Common/IEntry.Extensions.cs +++ b/src/SharpCompress/Common/IEntry.Extensions.cs @@ -1,6 +1,4 @@ - -#if !NO_FILE -using System.IO; +using System.IO; using SharpCompress.Readers; namespace SharpCompress.Common @@ -48,4 +46,3 @@ namespace SharpCompress.Common } } } -#endif \ No newline at end of file diff --git a/src/SharpCompress/Common/IVolume.cs b/src/SharpCompress/Common/IVolume.cs index d5dac255..f19971fe 100644 --- a/src/SharpCompress/Common/IVolume.cs +++ b/src/SharpCompress/Common/IVolume.cs @@ -1,9 +1,5 @@ using System; -#if !NO_FILE -using System.IO; -#endif - namespace SharpCompress.Common { public interface IVolume : IDisposable diff --git a/src/SharpCompress/Common/Rar/Headers/FileHeader.cs b/src/SharpCompress/Common/Rar/Headers/FileHeader.cs index 09ded0fc..9e60c12a 100644 --- a/src/SharpCompress/Common/Rar/Headers/FileHeader.cs +++ b/src/SharpCompress/Common/Rar/Headers/FileHeader.cs @@ -195,17 +195,12 @@ namespace SharpCompress.Common.Rar.Headers private static string ConvertPathV5(string path) { -#if NO_FILE - // not sure what to do here - throw new NotImplementedException("TODO"); -#else if (Path.DirectorySeparatorChar == '\\') { // replace embedded \\ with valid filename char return path.Replace('\\', '-').Replace('/', '\\'); } return path; -#endif } @@ -361,9 +356,6 @@ namespace SharpCompress.Common.Rar.Headers private static string ConvertPathV4(string path) { -#if NO_FILE - return path.Replace('\\', '/'); -#else if (Path.DirectorySeparatorChar == '/') { return path.Replace('\\', '/'); @@ -373,7 +365,6 @@ namespace SharpCompress.Common.Rar.Headers return path.Replace('/', '\\'); } return path; -#endif } public override string ToString() diff --git a/src/SharpCompress/Common/Rar/Headers/RarHeaderFactory.cs b/src/SharpCompress/Common/Rar/Headers/RarHeaderFactory.cs index 8c4f34f7..d5b2b80b 100644 --- a/src/SharpCompress/Common/Rar/Headers/RarHeaderFactory.cs +++ b/src/SharpCompress/Common/Rar/Headers/RarHeaderFactory.cs @@ -48,15 +48,11 @@ namespace SharpCompress.Common.Rar.Headers } else { -#if !NO_CRYPTO if (Options.Password == null) { throw new CryptographicException("Encrypted Rar archive has no password specified."); } reader = new RarCryptoBinaryReader(stream, Options.Password); -#else - throw new CryptographicException("Rar encryption unsupported on this platform"); -#endif } var header = RarHeader.TryReadBase(reader, _isRar5, Options.ArchiveEncoding); @@ -138,11 +134,7 @@ namespace SharpCompress.Common.Rar.Headers } else { -#if !NO_CRYPTO fh.PackedStream = new RarCryptoWrapper(ms, Options.Password, fh.R4Salt); -#else - throw new NotSupportedException("RarCrypto not supported"); -#endif } } break; diff --git a/src/SharpCompress/Common/Rar/RarCryptoBinaryReader.cs b/src/SharpCompress/Common/Rar/RarCryptoBinaryReader.cs index 66c0d606..d1893fa4 100644 --- a/src/SharpCompress/Common/Rar/RarCryptoBinaryReader.cs +++ b/src/SharpCompress/Common/Rar/RarCryptoBinaryReader.cs @@ -1,5 +1,4 @@ -#if !NO_CRYPTO -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; namespace SharpCompress.Common.Rar @@ -111,5 +110,4 @@ namespace SharpCompress.Common.Rar ClearQueue(); } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/SharpCompress/Common/Rar/RarCryptoWrapper.cs b/src/SharpCompress/Common/Rar/RarCryptoWrapper.cs index 50e1520c..5ffc0d01 100644 --- a/src/SharpCompress/Common/Rar/RarCryptoWrapper.cs +++ b/src/SharpCompress/Common/Rar/RarCryptoWrapper.cs @@ -1,5 +1,3 @@ - -#if !NO_CRYPTO using System; using System.Collections.Generic; using System.IO; @@ -95,5 +93,4 @@ namespace SharpCompress.Common.Rar base.Dispose(disposing); } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/SharpCompress/Common/Rar/RarRijndael.cs b/src/SharpCompress/Common/Rar/RarRijndael.cs index f5d7fd1a..726d0bc5 100644 --- a/src/SharpCompress/Common/Rar/RarRijndael.cs +++ b/src/SharpCompress/Common/Rar/RarRijndael.cs @@ -1,5 +1,4 @@ -#if !NO_CRYPTO -using System; +using System; using System.Collections.Generic; using System.Security.Cryptography; using System.Text; @@ -110,4 +109,3 @@ namespace SharpCompress.Common.Rar } } } -#endif \ No newline at end of file diff --git a/src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs b/src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs index accae7d0..bbd26991 100644 --- a/src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs +++ b/src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs @@ -65,10 +65,8 @@ namespace SharpCompress.Common.Zip.Headers return encryptionData; } - -#if !NO_CRYPTO + internal WinzipAesEncryptionData WinzipAesEncryptionData { get; set; } -#endif internal ushort LastModifiedDate { get; set; } diff --git a/src/SharpCompress/Common/Zip/WinzipAesCryptoStream.cs b/src/SharpCompress/Common/Zip/WinzipAesCryptoStream.cs index 62e6cff2..5b4ab6f7 100644 --- a/src/SharpCompress/Common/Zip/WinzipAesCryptoStream.cs +++ b/src/SharpCompress/Common/Zip/WinzipAesCryptoStream.cs @@ -1,5 +1,3 @@ - -#if !NO_CRYPTO using System; using System.IO; using System.Security.Cryptography; @@ -181,4 +179,3 @@ namespace SharpCompress.Common.Zip } } } -#endif \ No newline at end of file diff --git a/src/SharpCompress/Common/Zip/WinzipAesEncryptionData.cs b/src/SharpCompress/Common/Zip/WinzipAesEncryptionData.cs index 49f3dd24..75774108 100644 --- a/src/SharpCompress/Common/Zip/WinzipAesEncryptionData.cs +++ b/src/SharpCompress/Common/Zip/WinzipAesEncryptionData.cs @@ -1,5 +1,3 @@ - -#if !NO_CRYPTO using System; using System.Security.Cryptography; using SharpCompress.Converters; @@ -76,4 +74,3 @@ namespace SharpCompress.Common.Zip } } } -#endif \ No newline at end of file diff --git a/src/SharpCompress/Common/Zip/ZipFilePart.cs b/src/SharpCompress/Common/Zip/ZipFilePart.cs index f68a1f6f..9c521766 100644 --- a/src/SharpCompress/Common/Zip/ZipFilePart.cs +++ b/src/SharpCompress/Common/Zip/ZipFilePart.cs @@ -165,12 +165,10 @@ namespace SharpCompress.Common.Zip case ZipCompressionMethod.WinzipAes: { -#if !NO_FILE if (Header.WinzipAesEncryptionData != null) { return new WinzipAesCryptoStream(plainStream, Header.WinzipAesEncryptionData, Header.CompressedSize - 10); } -#endif return plainStream; } diff --git a/src/SharpCompress/Common/Zip/ZipHeaderFactory.cs b/src/SharpCompress/Common/Zip/ZipHeaderFactory.cs index 3810da0a..0d6b9402 100644 --- a/src/SharpCompress/Common/Zip/ZipHeaderFactory.cs +++ b/src/SharpCompress/Common/Zip/ZipHeaderFactory.cs @@ -1,8 +1,6 @@ using System; using System.IO; -#if !NO_CRYPTO using System.Linq; -#endif using SharpCompress.Common.Zip.Headers; using SharpCompress.IO; using System.Text; @@ -132,10 +130,6 @@ namespace SharpCompress.Common.Zip if (entryHeader.CompressionMethod == ZipCompressionMethod.WinzipAes) { -#if NO_CRYPTO - throw new NotSupportedException("Cannot decrypt Winzip AES with Silverlight or WP7."); -#else - ExtraData data = entryHeader.Extra.SingleOrDefault(x => x.Type == ExtraDataType.WinZipAes); if (data != null) { @@ -150,7 +144,6 @@ namespace SharpCompress.Common.Zip entryHeader.CompressedSize -= (uint)(salt.Length + 2); } -#endif } } diff --git a/src/SharpCompress/Compressors/LZMA/AesDecoderStream.cs b/src/SharpCompress/Compressors/LZMA/AesDecoderStream.cs index 744336df..41c45c78 100644 --- a/src/SharpCompress/Compressors/LZMA/AesDecoderStream.cs +++ b/src/SharpCompress/Compressors/LZMA/AesDecoderStream.cs @@ -1,6 +1,4 @@ - -#if !NO_CRYPTO -using System; +using System; using System.IO; using System.Security.Cryptography; using System.Text; @@ -195,7 +193,7 @@ namespace SharpCompress.Compressors.LZMA } else { -#if NETSTANDARD1_3 +#if NETSTANDARD1_3 || NETSTANDARD2_0 using (IncrementalHash sha = IncrementalHash.CreateHash(HashAlgorithmName.SHA256)) { byte[] counter = new byte[8]; @@ -262,5 +260,3 @@ namespace SharpCompress.Compressors.LZMA #endregion } } - -#endif \ No newline at end of file diff --git a/src/SharpCompress/Compressors/LZMA/Log.cs b/src/SharpCompress/Compressors/LZMA/Log.cs index f3b4eab5..f4cbed5e 100644 --- a/src/SharpCompress/Compressors/LZMA/Log.cs +++ b/src/SharpCompress/Compressors/LZMA/Log.cs @@ -34,34 +34,26 @@ namespace SharpCompress.Compressors.LZMA if (NEEDS_INDENT) { NEEDS_INDENT = false; -#if !NO_FILE Debug.Write(INDENT.Peek()); -#endif } } public static void Write(object value) { EnsureIndent(); -#if !NO_FILE Debug.Write(value); -#endif } public static void Write(string text) { EnsureIndent(); -#if !NO_FILE Debug.Write(text); -#endif } public static void Write(string format, params object[] args) { EnsureIndent(); -#if !NO_FILE Debug.Write(string.Format(format, args)); -#endif } public static void WriteLine() diff --git a/src/SharpCompress/Compressors/LZMA/Registry.cs b/src/SharpCompress/Compressors/LZMA/Registry.cs index edc02854..8495c4bc 100644 --- a/src/SharpCompress/Compressors/LZMA/Registry.cs +++ b/src/SharpCompress/Compressors/LZMA/Registry.cs @@ -36,10 +36,8 @@ namespace SharpCompress.Compressors.LZMA case K_LZMA: case K_LZMA2: return new LzmaStream(info, inStreams.Single(), -1, limit); -#if !NO_CRYPTO case CMethodId.K_AES_ID: return new AesDecoderStream(inStreams.Single(), info, pass, limit); -#endif case K_BCJ: return new BCJFilter(false, inStreams.Single()); case K_BCJ2: diff --git a/src/SharpCompress/EnumExtensions.cs b/src/SharpCompress/EnumExtensions.cs deleted file mode 100644 index 5f5fe0d6..00000000 --- a/src/SharpCompress/EnumExtensions.cs +++ /dev/null @@ -1,18 +0,0 @@ - -#if NET35 -using System; - -namespace SharpCompress -{ - internal static class EnumExtensions - { - public static bool HasFlag(this Enum enumRef, Enum flag) - { - long value = Convert.ToInt64(enumRef); - long flagVal = Convert.ToInt64(flag); - - return (value & flagVal) == flagVal; - } - } -} -#endif \ No newline at end of file diff --git a/src/SharpCompress/IO/MarkingBinaryReader.cs b/src/SharpCompress/IO/MarkingBinaryReader.cs index e1037995..0b9dc576 100644 --- a/src/SharpCompress/IO/MarkingBinaryReader.cs +++ b/src/SharpCompress/IO/MarkingBinaryReader.cs @@ -74,13 +74,6 @@ namespace SharpCompress.IO throw new NotSupportedException(); } -#if !SILVERLIGHT - public override decimal ReadDecimal() - { - throw new NotSupportedException(); - } -#endif - public override double ReadDouble() { throw new NotSupportedException(); diff --git a/src/SharpCompress/Readers/IReaderExtensions.cs b/src/SharpCompress/Readers/IReaderExtensions.cs index d63cc967..97b710ef 100644 --- a/src/SharpCompress/Readers/IReaderExtensions.cs +++ b/src/SharpCompress/Readers/IReaderExtensions.cs @@ -1,13 +1,10 @@ -#if !NO_FILE -using System.IO; +using System.IO; using SharpCompress.Common; -#endif namespace SharpCompress.Readers { public static class IReaderExtensions { -#if !NO_FILE public static void WriteEntryTo(this IReader reader, string filePath) { using (Stream stream = File.Open(filePath, FileMode.Create, FileAccess.Write)) @@ -61,6 +58,5 @@ namespace SharpCompress.Readers } }); } -#endif } } \ No newline at end of file diff --git a/src/SharpCompress/SharpCompress.csproj b/src/SharpCompress/SharpCompress.csproj index ce617455..a175e336 100644 --- a/src/SharpCompress/SharpCompress.csproj +++ b/src/SharpCompress/SharpCompress.csproj @@ -6,7 +6,7 @@ 0.24.0 0.24.0 Adam Hathcock - net45;net35;netstandard1.0;netstandard1.3;netstandard2.0 + netstandard1.3;netstandard2.0;net46 true true SharpCompress @@ -19,23 +19,11 @@ https://github.com/adamhathcock/sharpcompress/blob/master/LICENSE.txt false false - SharpCompress is a compression library for NET Standard 1.0 that can unrar, decompress 7zip, decompress xz, zip/unzip, tar/untar lzip/unlzip, bzip2/unbzip2 and gzip/ungzip with forward-only reading and file random access APIs. Write support for zip/tar/bzip2/gzip is implemented. + SharpCompress is a compression library for NET Standard 1.3/2.0 that can unrar, decompress 7zip, decompress xz, zip/unzip, tar/untar lzip/unlzip, bzip2/unbzip2 and gzip/ungzip with forward-only reading and file random access APIs. Write support for zip/tar/bzip2/gzip is implemented. - - $(DefineConstants);NO_FILE;NO_CRYPTO;SILVERLIGHT - - - $(DefineConstants);NETCORE - - - - - - - $(DefineConstants);NETCORE - - - + + + diff --git a/src/SharpCompress/Utility.cs b/src/SharpCompress/Utility.cs index 6e139d0b..fee2c68e 100644 --- a/src/SharpCompress/Utility.cs +++ b/src/SharpCompress/Utility.cs @@ -1,14 +1,8 @@ using System; -#if NETCORE using System.Buffers; -#endif using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Reflection; -using System.Reflection.Emit; -using System.Runtime.InteropServices; - +using System.Runtime.CompilerServices; using SharpCompress.Readers; namespace SharpCompress @@ -76,46 +70,11 @@ namespace SharpCompress array[index] = val; } } - -#if NET45 - // super fast memset, up to 40x faster than for loop on large arrays - // see https://stackoverflow.com/questions/1897555/what-is-the-equivalent-of-memset-in-c - private static readonly Action MemsetDelegate = CreateMemsetDelegate(); - - private static Action CreateMemsetDelegate() - { - var dynamicMethod = new DynamicMethod( - "Memset", - MethodAttributes.Public | MethodAttributes.Static, - CallingConventions.Standard, - null, - new[] { typeof(IntPtr), typeof(byte), typeof(uint) }, - typeof(Utility), - true); - var generator = dynamicMethod.GetILGenerator(); - generator.Emit(OpCodes.Ldarg_0); - generator.Emit(OpCodes.Ldarg_1); - generator.Emit(OpCodes.Ldarg_2); - generator.Emit(OpCodes.Initblk); - generator.Emit(OpCodes.Ret); - return (Action)dynamicMethod.CreateDelegate(typeof(Action)); - } - public static void Memset(byte[] array, byte what, int length) { - var gcHandle = GCHandle.Alloc(array, GCHandleType.Pinned); - MemsetDelegate(gcHandle.AddrOfPinnedObject(), what, (uint)length); - gcHandle.Free(); + ref byte ptr = ref array[0]; + Unsafe.InitBlock(ref ptr, what, (uint)length); } -#else - public static void Memset(byte[] array, byte what, int length) - { - for (var i = 0; i < length; i++) - { - array[i] = what; - } - } -#endif public static void Memset(T[] array, T what, int length) { @@ -256,9 +215,7 @@ namespace SharpCompress } finally { -#if NETCORE ArrayPool.Shared.Return(buffer); -#endif } } @@ -274,9 +231,7 @@ namespace SharpCompress } finally { -#if NETCORE ArrayPool.Shared.Return(buffer); -#endif } } @@ -361,9 +316,7 @@ namespace SharpCompress } finally { -#if NETCORE ArrayPool.Shared.Return(array); -#endif } } @@ -386,9 +339,7 @@ namespace SharpCompress } finally { -#if NETCORE ArrayPool.Shared.Return(array); -#endif } } @@ -399,11 +350,7 @@ namespace SharpCompress private static byte[] GetTransferByteArray() { -#if NETCORE return ArrayPool.Shared.Rent(81920); -#else - return new byte[81920]; -#endif } public static bool ReadFully(this Stream stream, byte[] buffer) diff --git a/src/SharpCompress/Writers/IWriterExtensions.cs b/src/SharpCompress/Writers/IWriterExtensions.cs index 2dbd2d9c..dc2d2c77 100644 --- a/src/SharpCompress/Writers/IWriterExtensions.cs +++ b/src/SharpCompress/Writers/IWriterExtensions.cs @@ -1,6 +1,4 @@ -#if !NO_FILE -using System; -#endif +using System; using System.IO; using System.Linq; using System.Linq.Expressions; @@ -14,7 +12,6 @@ namespace SharpCompress.Writers writer.Write(entryPath, source, null); } -#if !NO_FILE public static void Write(this IWriter writer, string entryPath, FileInfo source) { if (!source.Exists) @@ -37,7 +34,10 @@ namespace SharpCompress.Writers writer.WriteAll(directory, searchPattern, null, option); } - public static void WriteAll(this IWriter writer, string directory, string searchPattern = "*", Expression> fileSearchFunc = null, + public static void WriteAll(this IWriter writer, + string directory, + string searchPattern = "*", + Expression> fileSearchFunc = null, SearchOption option = SearchOption.TopDirectoryOnly) { if (!Directory.Exists(directory)) @@ -49,16 +49,10 @@ namespace SharpCompress.Writers { fileSearchFunc = n => true; } -#if NET35 - foreach (var file in Directory.GetDirectories(directory, searchPattern, option).Where(fileSearchFunc.Compile())) -#else foreach (var file in Directory.EnumerateFiles(directory, searchPattern, option).Where(fileSearchFunc.Compile())) -#endif { writer.Write(file.Substring(directory.Length), file); } } - -#endif } } \ No newline at end of file diff --git a/tests/SharpCompress.Test/SharpCompress.Test.csproj b/tests/SharpCompress.Test/SharpCompress.Test.csproj index 6f798583..4396e820 100644 --- a/tests/SharpCompress.Test/SharpCompress.Test.csproj +++ b/tests/SharpCompress.Test/SharpCompress.Test.csproj @@ -12,7 +12,7 @@ - +