From 74af0889b955a34b31ef2b58a2ab861d44cdf0de Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Mon, 3 Oct 2016 10:16:26 +0100 Subject: [PATCH 1/6] Make PpmdProperties lazy to avoid unnecessary allocations. --- README.md | 2 +- src/SharpCompress/Compressors/PPMd/PpmdProperties.cs | 7 ------- src/SharpCompress/Compressors/PPMd/PpmdVersion.cs | 9 +++++++++ src/SharpCompress/Writers/Zip/ZipWriter.cs | 6 +++--- 4 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 src/SharpCompress/Compressors/PPMd/PpmdVersion.cs diff --git a/README.md b/README.md index 83c2d35c..1b1ef1db 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ The major feature is support for non-seekable streams so large files can be proc ## Need Help? Post Issues on Github! -Check the [Supported Formats](FORMATS.md) and [basic usage.](USAGE.md) +Check the [Supported Formats](FORMATS.md) and [Basic Usage.](USAGE.md) ## A Simple Request diff --git a/src/SharpCompress/Compressors/PPMd/PpmdProperties.cs b/src/SharpCompress/Compressors/PPMd/PpmdProperties.cs index 7e02d6c0..25e90b6e 100644 --- a/src/SharpCompress/Compressors/PPMd/PpmdProperties.cs +++ b/src/SharpCompress/Compressors/PPMd/PpmdProperties.cs @@ -3,13 +3,6 @@ using SharpCompress.Converters; namespace SharpCompress.Compressors.PPMd { - public enum PpmdVersion - { - H, - H7z, - I1 - } - public class PpmdProperties { public PpmdVersion Version = PpmdVersion.I1; diff --git a/src/SharpCompress/Compressors/PPMd/PpmdVersion.cs b/src/SharpCompress/Compressors/PPMd/PpmdVersion.cs new file mode 100644 index 00000000..c4d17015 --- /dev/null +++ b/src/SharpCompress/Compressors/PPMd/PpmdVersion.cs @@ -0,0 +1,9 @@ +namespace SharpCompress.Compressors.PPMd +{ + public enum PpmdVersion + { + H, + H7z, + I1 + } +} \ No newline at end of file diff --git a/src/SharpCompress/Writers/Zip/ZipWriter.cs b/src/SharpCompress/Writers/Zip/ZipWriter.cs index 37c216b1..f93cf3cf 100644 --- a/src/SharpCompress/Writers/Zip/ZipWriter.cs +++ b/src/SharpCompress/Writers/Zip/ZipWriter.cs @@ -19,7 +19,7 @@ namespace SharpCompress.Writers.Zip { private readonly CompressionType compressionType; private readonly CompressionLevel compressionLevel; - private readonly PpmdProperties ppmdProperties = new PpmdProperties(); // Caching properties to speed up PPMd + private readonly Lazy ppmdProperties = new Lazy(() => new PpmdProperties()); // Caching properties to speed up PPMd private readonly List entries = new List(); private readonly string zipComment; private long streamPosition; @@ -252,8 +252,8 @@ namespace SharpCompress.Writers.Zip } case ZipCompressionMethod.PPMd: { - counting.Write(writer.ppmdProperties.Properties, 0, 2); - return new PpmdStream(writer.ppmdProperties, counting, true); + counting.Write(writer.ppmdProperties.Value.Properties, 0, 2); + return new PpmdStream(writer.ppmdProperties.Value, counting, true); } default: { From 131b5b97142609fec753a3c082451402e8aa72cd Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Mon, 3 Oct 2016 11:20:29 +0100 Subject: [PATCH 2/6] Can't use Lazy on .NET 3.5 :( --- src/SharpCompress/Writers/Zip/ZipWriter.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/SharpCompress/Writers/Zip/ZipWriter.cs b/src/SharpCompress/Writers/Zip/ZipWriter.cs index f93cf3cf..d89294b5 100644 --- a/src/SharpCompress/Writers/Zip/ZipWriter.cs +++ b/src/SharpCompress/Writers/Zip/ZipWriter.cs @@ -19,10 +19,10 @@ namespace SharpCompress.Writers.Zip { private readonly CompressionType compressionType; private readonly CompressionLevel compressionLevel; - private readonly Lazy ppmdProperties = new Lazy(() => new PpmdProperties()); // Caching properties to speed up PPMd private readonly List entries = new List(); private readonly string zipComment; private long streamPosition; + private PpmdProperties ppmdProps; public ZipWriter(Stream destination, ZipWriterOptions zipWriterOptions) : base(ArchiveType.Zip) @@ -34,6 +34,18 @@ namespace SharpCompress.Writers.Zip InitalizeStream(destination, !zipWriterOptions.LeaveStreamOpen); } + private PpmdProperties PpmdProperties + { + get + { + if (ppmdProps == null) + { + ppmdProps = new PpmdProperties(); + } + return ppmdProps; + } + } + protected override void Dispose(bool isDisposing) { if (isDisposing) @@ -252,8 +264,8 @@ namespace SharpCompress.Writers.Zip } case ZipCompressionMethod.PPMd: { - counting.Write(writer.ppmdProperties.Value.Properties, 0, 2); - return new PpmdStream(writer.ppmdProperties.Value, counting, true); + counting.Write(writer.PpmdProperties.Properties, 0, 2); + return new PpmdStream(writer.PpmdProperties, counting, true); } default: { From 671f9cd0cb2dde6ef9576a3f890099c4d17c9e0c Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Mon, 3 Oct 2016 12:58:23 +0100 Subject: [PATCH 3/6] Empty commit to kick build From f26ba91386e4561db1fe21299f6c77ec8b239397 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Mon, 3 Oct 2016 13:32:53 +0100 Subject: [PATCH 4/6] Fix null password on ReaderFactory. Fix null options on SevenZipArchive --- src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs | 4 ++-- src/SharpCompress/Common/Volume.cs | 4 ++-- src/SharpCompress/Readers/AbstractReader.cs | 2 +- src/SharpCompress/Readers/ReaderFactory.cs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs b/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs index 84115144..e8aac7b7 100644 --- a/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs +++ b/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs @@ -30,7 +30,7 @@ namespace SharpCompress.Archives.SevenZip /// /// /// - public static SevenZipArchive Open(FileInfo fileInfo, ReaderOptions readerOptions) + public static SevenZipArchive Open(FileInfo fileInfo, ReaderOptions readerOptions = null) { fileInfo.CheckNotNull("fileInfo"); return new SevenZipArchive(fileInfo, readerOptions ?? new ReaderOptions()); @@ -44,7 +44,7 @@ namespace SharpCompress.Archives.SevenZip public static SevenZipArchive Open(Stream stream, ReaderOptions readerOptions = null) { stream.CheckNotNull("stream"); - return new SevenZipArchive(stream, readerOptions); + return new SevenZipArchive(stream, readerOptions ?? new ReaderOptions()); } #if !NO_FILE diff --git a/src/SharpCompress/Common/Volume.cs b/src/SharpCompress/Common/Volume.cs index 39d00621..d5921ab7 100644 --- a/src/SharpCompress/Common/Volume.cs +++ b/src/SharpCompress/Common/Volume.cs @@ -8,10 +8,10 @@ namespace SharpCompress.Common { private readonly Stream actualStream; - internal Volume(Stream stream, ReaderOptions readerFactoryOptions) + internal Volume(Stream stream, ReaderOptions readerOptions) { actualStream = stream; - ReaderOptions = readerFactoryOptions; + ReaderOptions = readerOptions; } internal Stream Stream { get { return new NonDisposingStream(actualStream); } } diff --git a/src/SharpCompress/Readers/AbstractReader.cs b/src/SharpCompress/Readers/AbstractReader.cs index 810d7c5e..380e8df5 100644 --- a/src/SharpCompress/Readers/AbstractReader.cs +++ b/src/SharpCompress/Readers/AbstractReader.cs @@ -29,7 +29,7 @@ namespace SharpCompress.Readers Options = options; } - internal ReaderOptions Options { get; private set; } + internal ReaderOptions Options { get; } public ArchiveType ArchiveType { get; } diff --git a/src/SharpCompress/Readers/ReaderFactory.cs b/src/SharpCompress/Readers/ReaderFactory.cs index 9149b8b0..a1a931f4 100644 --- a/src/SharpCompress/Readers/ReaderFactory.cs +++ b/src/SharpCompress/Readers/ReaderFactory.cs @@ -33,7 +33,7 @@ namespace SharpCompress.Readers }; RewindableStream rewindableStream = new RewindableStream(stream); rewindableStream.StartRecording(); - if (ZipArchive.IsZipFile(rewindableStream, null)) + if (ZipArchive.IsZipFile(rewindableStream, options.Password)) { rewindableStream.Rewind(true); return ZipReader.Open(rewindableStream, options); From d7e29f7c4d8e791ac58919cfb1238841dcb61f89 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Mon, 3 Oct 2016 13:37:04 +0100 Subject: [PATCH 5/6] Fix occasionally failing test --- test/SharpCompress.Test/Zip/ZipReaderTests.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/SharpCompress.Test/Zip/ZipReaderTests.cs b/test/SharpCompress.Test/Zip/ZipReaderTests.cs index 0927a31b..115138eb 100644 --- a/test/SharpCompress.Test/Zip/ZipReaderTests.cs +++ b/test/SharpCompress.Test/Zip/ZipReaderTests.cs @@ -228,6 +228,8 @@ namespace SharpCompress.Test [Fact] public void TestSharpCompressWithEmptyStream() { + ResetScratch(); + MemoryStream stream = new NonSeekableMemoryStream(); using (IWriter zipWriter = WriterFactory.Open(stream, ArchiveType.Zip, CompressionType.Deflate)) @@ -250,7 +252,9 @@ namespace SharpCompress.Test byte[] buf = new byte[bufSize]; int bytesRead = 0; while ((bytesRead = entry.Read(buf, 0, bufSize)) > 0) + { tempStream.Write(buf, 0, bytesRead); + } } } } From 844ba228eed48a5acc676295b5e963680faaf901 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Mon, 3 Oct 2016 13:44:19 +0100 Subject: [PATCH 6/6] Make 0.13.1 --- README.md | 11 +++++++++++ src/SharpCompress/project.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1b1ef1db..534985b2 100644 --- a/README.md +++ b/README.md @@ -31,25 +31,36 @@ I'm always looking for help or ideas. Please submit code or email with ideas. Un ## Version Log +### Version 0.13.1 + +* [Fix null password on ReaderFactory. Fix null options on SevenZipArchive](https://github.com/adamhathcock/sharpcompress/pull/188) +* [Make PpmdProperties lazy to avoid unnecessary allocations.](https://github.com/adamhathcock/sharpcompress/pull/185) + ### Version 0.13.0 + * Breaking change: Big refactor of Options on API. * 7Zip supports Deflate ### Version 0.12.4 + * Forward only zip issue fix https://github.com/adamhathcock/sharpcompress/issues/160 * Try to fix frameworks again by copying targets from JSON.NET ### Version 0.12.3 + * 7Zip fixes https://github.com/adamhathcock/sharpcompress/issues/73 * Maybe all profiles will work with project.json now ### Version 0.12.2 + * Support Profile 259 again ### Version 0.12.1 + * Support Silverlight 5 ### Version 0.12.0 + * .NET Core RTM! * Bug fix for Tar long paths diff --git a/src/SharpCompress/project.json b/src/SharpCompress/project.json index 75defd2a..e39224f4 100644 --- a/src/SharpCompress/project.json +++ b/src/SharpCompress/project.json @@ -1,5 +1,5 @@ { - "version": "0.13.0", + "version": "0.13.1", "title": "SharpCompress - Pure C# Decompression/Compression", "authors": [ "Adam Hathcock" ], "language": "en-US",