var zp = ZipPackage.Open("test.zip", System.IO.FileMode.Create, System.IO.FileAccess.Write);
var part = zp.CreatePart(new System.Uri("/test.txt", UriKind.Relative), "");
var stream = part.GetStream(System.IO.FileMode.Create);
It seems that the assumption about the underlying stream is incorrect or the underlying stream should be allowing for this functionality.
This spawned off investigations done in dotnet/wpf#1363.
A simple reproduction in a console application can be obtained by doing:
A NotSupportedException will arise due to this code:
https://github.com/dotnet/corefx/blob/a10890f4ffe0fadf090c922578ba0e606ebdd16c/src/System.IO.Packaging/src/System/IO/Packaging/ZipPackagePart.cs#L30-L36
The call to
SetLengthfails since the underlying stream does not support this.The flow here is:
ZipArchiveEntry.GetDataCompressorcreates a newDeflateStreamwhich is then wrapped, along with the original stream, byCheckSumAndSizeWriteStream.https://github.com/dotnet/corefx/blob/78589e4d2c98bf71cefa4dbc94cde3783b60a934/src/System.IO.Compression/src/System/IO/Compression/ZipArchiveEntry.cs#L600
CheckSumAndSizeWriteStreamis never seekable and doesn't supportSetPosition:https://github.com/dotnet/corefx/blob/a10890f4ffe0fadf090c922578ba0e606ebdd16c/src/System.IO.Compression/src/System/IO/Compression/ZipCustomStreams.cs#L364
It seems that the assumption about the underlying stream is incorrect or the underlying stream should be allowing for this functionality.