new entry streams must be readable and seekable

This commit is contained in:
Adam Hathcock
2013-12-20 15:33:20 +00:00
parent f862cc6947
commit c1562c5829
7 changed files with 22 additions and 12 deletions

View File

@@ -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,

View File

@@ -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())

View File

@@ -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,

View File

@@ -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)

View File

@@ -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;

View File

@@ -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);

View File

@@ -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)