From 2100d49cefdf95dc585cdec655df9e0e8d59ac72 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Mon, 23 Dec 2013 12:29:41 +0000 Subject: [PATCH] Little more clean up --- SharpCompress/Archive/AbstractArchive.cs | 7 ++----- .../Archive/AbstractWritableArchive.Extensions.cs | 13 ++++++++++++- SharpCompress/Archive/AbstractWritableArchive.cs | 11 ----------- SharpCompress/Archive/Zip/ZipArchive.cs | 2 +- SharpCompress/Common/Tar/TarFilePart.cs | 4 ++-- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/SharpCompress/Archive/AbstractArchive.cs b/SharpCompress/Archive/AbstractArchive.cs index d1e5ac98..69751cbe 100644 --- a/SharpCompress/Archive/AbstractArchive.cs +++ b/SharpCompress/Archive/AbstractArchive.cs @@ -40,8 +40,7 @@ namespace SharpCompress.Archive internal AbstractArchive(ArchiveType type, IEnumerable streams, Options options) { Type = type; - lazyVolumes = - new LazyReadOnlyCollection(LoadVolumes(streams.Select(CheckStreams), options)); + lazyVolumes = new LazyReadOnlyCollection(LoadVolumes(streams.Select(CheckStreams), options)); lazyEntries = new LazyReadOnlyCollection(LoadEntries(Volumes)); } @@ -51,6 +50,7 @@ namespace SharpCompress.Archive lazyVolumes = new LazyReadOnlyCollection(Enumerable.Empty()); lazyEntries = new LazyReadOnlyCollection(Enumerable.Empty()); } + public ArchiveType Type { get; private set; } void IArchiveExtractionListener.FireEntryExtractionBegin(IArchiveEntry entry) { @@ -134,9 +134,6 @@ namespace SharpCompress.Archive lazyVolumes.EnsureFullyLoaded(); } - - public ArchiveType Type { get; private set; } - void IExtractionListener.FireCompressedBytesRead(long currentPartCompressedBytes, long compressedReadBytes) { if (CompressedBytesRead != null) diff --git a/SharpCompress/Archive/AbstractWritableArchive.Extensions.cs b/SharpCompress/Archive/AbstractWritableArchive.Extensions.cs index 153e5285..6de568f5 100644 --- a/SharpCompress/Archive/AbstractWritableArchive.Extensions.cs +++ b/SharpCompress/Archive/AbstractWritableArchive.Extensions.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; using SharpCompress.Common; namespace SharpCompress.Archive @@ -80,6 +81,16 @@ namespace SharpCompress.Archive fileInfo.LastWriteTime); } } + public static TEntry AddEntry(this AbstractWritableArchive writableArchive, string key, FileInfo fileInfo) + where TEntry : IArchiveEntry + where TVolume : IVolume + { + if (!fileInfo.Exists) + { + throw new ArgumentException("FileInfo does not exist."); + } + return writableArchive.AddEntry(key, fileInfo.OpenRead(), true, fileInfo.Length, fileInfo.LastWriteTime); + } #endif } } \ No newline at end of file diff --git a/SharpCompress/Archive/AbstractWritableArchive.cs b/SharpCompress/Archive/AbstractWritableArchive.cs index 49c553ed..3b2d1039 100644 --- a/SharpCompress/Archive/AbstractWritableArchive.cs +++ b/SharpCompress/Archive/AbstractWritableArchive.cs @@ -105,17 +105,6 @@ namespace SharpCompress.Archive return false; } -#if !PORTABLE && !NETFX_CORE - public TEntry AddEntry(string key, FileInfo fileInfo) - { - if (!fileInfo.Exists) - { - throw new ArgumentException("FileInfo does not exist."); - } - return AddEntry(key, fileInfo.OpenRead(), true, fileInfo.Length, fileInfo.LastWriteTime); - } -#endif - public void SaveTo(Stream stream, CompressionInfo compressionType) { //reset streams of new entries diff --git a/SharpCompress/Archive/Zip/ZipArchive.cs b/SharpCompress/Archive/Zip/ZipArchive.cs index 77bf436a..61a5e3f8 100644 --- a/SharpCompress/Archive/Zip/ZipArchive.cs +++ b/SharpCompress/Archive/Zip/ZipArchive.cs @@ -181,7 +181,7 @@ namespace SharpCompress.Archive.Zip protected override IEnumerable LoadEntries(IEnumerable volumes) { var volume = volumes.Single(); - Stream stream = volumes.Single().Stream; + Stream stream = volume.Stream; foreach (ZipHeader h in headerFactory.ReadSeekableHeader(stream)) { if (h != null) diff --git a/SharpCompress/Common/Tar/TarFilePart.cs b/SharpCompress/Common/Tar/TarFilePart.cs index c0d1341f..ae170dfc 100644 --- a/SharpCompress/Common/Tar/TarFilePart.cs +++ b/SharpCompress/Common/Tar/TarFilePart.cs @@ -6,12 +6,12 @@ namespace SharpCompress.Common.Tar { internal class TarFilePart : FilePart { - private Stream seekableStream; + private readonly Stream seekableStream; internal TarFilePart(TarHeader header, Stream seekableStream) { this.seekableStream = seekableStream; - this.Header = header; + Header = header; } internal TarHeader Header { get; private set; }