diff --git a/SharpCompress/Archive/AbstractWritableArchive.cs b/SharpCompress/Archive/AbstractWritableArchive.cs index 7cf81902..2eb10d13 100644 --- a/SharpCompress/Archive/AbstractWritableArchive.cs +++ b/SharpCompress/Archive/AbstractWritableArchive.cs @@ -97,7 +97,17 @@ namespace SharpCompress.Archive SaveTo(stream, compressionType, OldEntries, newEntries); } - protected abstract TEntry CreateEntry(string filePath, Stream source, long size, DateTime? modified, + protected TEntry CreateEntry(string filePath, Stream source, long size, DateTime? modified, + bool closeStream) + { + if (!source.CanRead || !source.CanSeek) + { + throw new ArgumentException("Streams must be readable and seekable to use the Writing Archive API"); + } + return CreateEntryInternal(filePath, source, size, modified, closeStream); + } + + protected abstract TEntry CreateEntryInternal(string filePath, Stream source, long size, DateTime? modified, bool closeStream); protected abstract void SaveTo(Stream stream, CompressionInfo compressionType, diff --git a/SharpCompress/Archive/GZip/GZipArchive.cs b/SharpCompress/Archive/GZip/GZipArchive.cs index eea5b89d..7c8e0c5f 100644 --- a/SharpCompress/Archive/GZip/GZipArchive.cs +++ b/SharpCompress/Archive/GZip/GZipArchive.cs @@ -158,10 +158,10 @@ namespace SharpCompress.Archive.GZip public void SaveTo(Stream stream) { - this.SaveTo(stream, CompressionType.GZip); + SaveTo(stream, CompressionType.GZip); } - protected override GZipArchiveEntry CreateEntry(string filePath, Stream source, long size, DateTime? modified, + protected override GZipArchiveEntry CreateEntryInternal(string filePath, Stream source, long size, DateTime? modified, bool closeStream) { if (Entries.Any()) diff --git a/SharpCompress/Archive/Tar/TarArchive.cs b/SharpCompress/Archive/Tar/TarArchive.cs index f464c2da..e3e7b838 100644 --- a/SharpCompress/Archive/Tar/TarArchive.cs +++ b/SharpCompress/Archive/Tar/TarArchive.cs @@ -183,7 +183,7 @@ namespace SharpCompress.Archive.Tar return new TarArchive(); } - protected override TarArchiveEntry CreateEntry(string filePath, Stream source, + protected override TarArchiveEntry CreateEntryInternal(string filePath, Stream source, long size, DateTime? modified, bool closeStream) { return new TarWritableArchiveEntry(this, source, CompressionType.Unknown, filePath, size, modified, diff --git a/SharpCompress/Archive/Tar/TarArchiveEntry.cs b/SharpCompress/Archive/Tar/TarArchiveEntry.cs index 5c3d8e95..a4622dc5 100644 --- a/SharpCompress/Archive/Tar/TarArchiveEntry.cs +++ b/SharpCompress/Archive/Tar/TarArchiveEntry.cs @@ -7,7 +7,7 @@ namespace SharpCompress.Archive.Tar { public class TarArchiveEntry : TarEntry, IArchiveEntry { - private TarArchive archive; + private readonly TarArchive archive; internal TarArchiveEntry(TarArchive archive, TarFilePart part, CompressionType compressionType) : base(part, compressionType) diff --git a/SharpCompress/Archive/Tar/TarWritableArchiveEntry.cs b/SharpCompress/Archive/Tar/TarWritableArchiveEntry.cs index 15644ace..82b7de78 100644 --- a/SharpCompress/Archive/Tar/TarWritableArchiveEntry.cs +++ b/SharpCompress/Archive/Tar/TarWritableArchiveEntry.cs @@ -8,16 +8,16 @@ namespace SharpCompress.Archive.Tar { internal class TarWritableArchiveEntry : TarArchiveEntry { - private string path; - private long size; - private DateTime? lastModified; - private bool closeStream; + private readonly string path; + private readonly long size; + private readonly DateTime? lastModified; + private readonly bool closeStream; internal TarWritableArchiveEntry(TarArchive archive, Stream stream, CompressionType compressionType, string path, long size, DateTime? lastModified, bool closeStream) : base(archive, null, compressionType) { - this.Stream = stream; + Stream = stream; this.path = path; this.size = size; this.lastModified = lastModified; diff --git a/SharpCompress/Archive/Zip/ZipArchive.cs b/SharpCompress/Archive/Zip/ZipArchive.cs index 4f5bece8..dea6d7a3 100644 --- a/SharpCompress/Archive/Zip/ZipArchive.cs +++ b/SharpCompress/Archive/Zip/ZipArchive.cs @@ -220,7 +220,7 @@ namespace SharpCompress.Archive.Zip } } - protected override ZipArchiveEntry CreateEntry(string filePath, Stream source, long size, DateTime? modified, + protected override ZipArchiveEntry CreateEntryInternal(string filePath, Stream source, long size, DateTime? modified, bool closeStream) { return new ZipWritableArchiveEntry(this, source, filePath, size, modified, closeStream); diff --git a/SharpCompress/Archive/Zip/ZipArchiveEntry.cs b/SharpCompress/Archive/Zip/ZipArchiveEntry.cs index 17ec0cf9..be5ebe5a 100644 --- a/SharpCompress/Archive/Zip/ZipArchiveEntry.cs +++ b/SharpCompress/Archive/Zip/ZipArchiveEntry.cs @@ -6,7 +6,7 @@ namespace SharpCompress.Archive.Zip { public class ZipArchiveEntry : ZipEntry, IArchiveEntry { - private ZipArchive archive; + private readonly ZipArchive archive; internal ZipArchiveEntry(ZipArchive archive, SeekableZipFilePart part) : base(part)