diff --git a/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs b/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs
index e82c6ce2f..f05e3c563 100644
--- a/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs
+++ b/src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs
@@ -1839,6 +1839,29 @@ public void Add(ZipEntry entry)
AddUpdate(new ZipUpdate(UpdateCommand.Add, entry));
}
+ ///
+ /// Add a with data.
+ ///
+ /// The source of the data for this entry.
+ /// The entry to add.
+ /// This can be used to add file entries with a custom data source.
+ public void Add(IStaticDataSource dataSource, ZipEntry entry)
+ {
+ if (entry == null)
+ {
+ throw new ArgumentNullException(nameof(entry));
+ }
+
+ if (dataSource == null)
+ {
+ throw new ArgumentNullException(nameof(dataSource));
+ }
+
+ CheckUpdating();
+
+ AddUpdate(new ZipUpdate(dataSource, entry));
+ }
+
///
/// Add a directory entry to the archive.
///
diff --git a/test/ICSharpCode.SharpZipLib.Tests/Zip/ZipFileHandling.cs b/test/ICSharpCode.SharpZipLib.Tests/Zip/ZipFileHandling.cs
index e4b068c14..6d9a1ea9c 100644
--- a/test/ICSharpCode.SharpZipLib.Tests/Zip/ZipFileHandling.cs
+++ b/test/ICSharpCode.SharpZipLib.Tests/Zip/ZipFileHandling.cs
@@ -1371,6 +1371,7 @@ public void FileStreamNotClosedWhenNotOwner()
/// Check that input stream is closed when construction fails and leaveOpen is false
///
[Test]
+ [Category("Zip")]
public void StreamClosedOnError()
{
var ms = new TrackedMemoryStream(new byte[32]);
@@ -1397,6 +1398,7 @@ public void StreamClosedOnError()
/// Check that input stream is not closed when construction fails and leaveOpen is true
///
[Test]
+ [Category("Zip")]
public void StreamNotClosedOnError()
{
var ms = new TrackedMemoryStream(new byte[32]);
@@ -1418,5 +1420,66 @@ public void StreamNotClosedOnError()
Assert.IsTrue(blewUp, "Should have failed to load the file");
Assert.IsFalse(ms.IsClosed, "Underlying stream should NOT be closed");
}
+
+ [Test]
+ [Category("Zip")]
+ public void HostSystemPersistedFromOutputStream()
+ {
+ using (var ms = new MemoryStream())
+ {
+ var fileName = "testfile";
+
+ using (var zos = new ZipOutputStream(ms) { IsStreamOwner = false })
+ {
+ var source = new StringMemoryDataSource("foo");
+ zos.PutNextEntry(new ZipEntry(fileName) { HostSystem = (int)HostSystemID.Unix });
+ source.GetSource().CopyTo(zos);
+ zos.CloseEntry();
+ zos.Finish();
+ }
+
+ ms.Seek(0, SeekOrigin.Begin);
+
+ using (var zis = new ZipFile(ms))
+ {
+ var ze = zis.GetEntry(fileName);
+ Assert.NotNull(ze);
+
+ Assert.AreEqual((int)HostSystemID.Unix, ze.HostSystem);
+ Assert.AreEqual(ZipConstants.VersionMadeBy, ze.VersionMadeBy);
+ }
+ }
+ }
+
+ [Test]
+ [Category("Zip")]
+ public void HostSystemPersistedFromZipFile()
+ {
+ using (var ms = new MemoryStream())
+ {
+ var fileName = "testfile";
+
+ using (var zof = new ZipFile(ms, true))
+ {
+ var ze = zof.EntryFactory.MakeFileEntry(fileName, false);
+ ze.HostSystem = (int)HostSystemID.Unix;
+
+ zof.BeginUpdate();
+ zof.Add(new StringMemoryDataSource("foo"), ze);
+ zof.CommitUpdate();
+ }
+
+ ms.Seek(0, SeekOrigin.Begin);
+
+ using (var zis = new ZipFile(ms))
+ {
+ var ze = zis.GetEntry(fileName);
+ Assert.NotNull(ze);
+
+ Assert.AreEqual((int)HostSystemID.Unix, ze.HostSystem);
+ Assert.AreEqual(ZipConstants.VersionMadeBy, ze.VersionMadeBy);
+ }
+ }
+ }
}
}