Skip to content

Commit

Permalink
add test for #731
Browse files Browse the repository at this point in the history
  • Loading branch information
piksel committed May 24, 2022
1 parent d843d6d commit 3393e8f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
12 changes: 7 additions & 5 deletions test/ICSharpCode.SharpZipLib.Tests/TestSupport/Streams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,15 @@ public class MemoryStreamWithoutSeek : TrackedMemoryStream
/// </summary>
/// <value></value>
/// <returns>true if the stream is open.</returns>
public override bool CanSeek
public override bool CanSeek => false;

/// <inheritdoc />
public override long Position
{
get
{
return false;
}
get => throw new NotSupportedException("Getting position is not supported");
set => throw new NotSupportedException("Setting position is not supported");
}

}

/// <summary>
Expand Down
7 changes: 3 additions & 4 deletions test/ICSharpCode.SharpZipLib.Tests/Zip/StreamHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,10 @@ public void ReadAndWriteZip64NonSeekable()
outStream.Close();
}

Assert.That(msw.ToArray(), Does.PassTestArchive());

msw.Position = 0;
var msBytes = msw.ToArray();
Assert.That(msBytes, Does.PassTestArchive());

using (var zis = new ZipInputStream(msw))
using (var zis = new ZipInputStream(new MemoryStream(msBytes)))
{
while (zis.GetNextEntry() != null)
{
Expand Down
21 changes: 21 additions & 0 deletions test/ICSharpCode.SharpZipLib.Tests/Zip/ZipStreamAsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,26 @@ public async Task WriteZipStreamWithZipCryptoAsync()
ZipTesting.AssertValidZip(ms, password, false);
}

[Test]
[Category("Zip")]
[Category("Async")]
public async Task WriteReadOnlyZipStreamAsync ()
{
using var ms = new MemoryStreamWithoutSeek();

using(var outStream = new ZipOutputStream(ms) { IsStreamOwner = false })
{
await outStream.PutNextEntryAsync(new ZipEntry("FirstFile"));
await Utils.WriteDummyDataAsync(outStream, 12);

await outStream.PutNextEntryAsync(new ZipEntry("SecondFile"));
await Utils.WriteDummyDataAsync(outStream, 12);

await outStream.FinishAsync(CancellationToken.None);
}

ZipTesting.AssertValidZip(new MemoryStream(ms.ToArray()));
}

}
}

0 comments on commit 3393e8f

Please sign in to comment.