diff options
author | Ubuntu <pt@ubuntu.hqa1tsbjfibefdog2agivzhj1f.fx.internal.cloudapp.net> | 2016-12-07 23:26:10 +0300 |
---|---|---|
committer | Peter Tiedemann <pt@configit.com> | 2016-12-08 07:37:41 +0300 |
commit | a3543c4ac2966d1fada9fcb3d572dfdfe8cbca88 (patch) | |
tree | 43751c54bd6d6ce55a7fb65fc6a1f5fa06a10a69 /mcs/class/System.IO.Compression | |
parent | dd88ff52e2f130ee188661a34794aa7c7b564fa8 (diff) |
Fix bug 48516
Diffstat (limited to 'mcs/class/System.IO.Compression')
-rw-r--r-- | mcs/class/System.IO.Compression/Test/System.IO.Compression/ZipTest.cs | 16 | ||||
-rw-r--r-- | mcs/class/System.IO.Compression/ZipArchive.cs | 19 |
2 files changed, 29 insertions, 6 deletions
diff --git a/mcs/class/System.IO.Compression/Test/System.IO.Compression/ZipTest.cs b/mcs/class/System.IO.Compression/Test/System.IO.Compression/ZipTest.cs index f1b83746b47..343746863e3 100644 --- a/mcs/class/System.IO.Compression/Test/System.IO.Compression/ZipTest.cs +++ b/mcs/class/System.IO.Compression/Test/System.IO.Compression/ZipTest.cs @@ -507,6 +507,11 @@ namespace MonoTests.System.IO.Compression /// Simulate "CanSeek" is false, which is the case when you are retreiving data from web. /// </summary> public override bool CanSeek => false; + + public override long Position { + get {throw new NotSupportedException();} + set {throw new NotSupportedException();} + } } [Test] @@ -517,5 +522,16 @@ namespace MonoTests.System.IO.Compression { } } + + [Test] + public void ZipWriteNonSeekableStream() { + var stream = new MyFakeStream( "test.nupkg", FileMode.Open ); + using ( var archive = new ZipArchive( stream, ZipArchiveMode.Create ) ) { + var entry = archive.CreateEntry( "foo" ); + using ( var es = entry.Open() ) { + es.Write( new byte[] { 4, 2 }, 0, 2 ); + } + } + } } } diff --git a/mcs/class/System.IO.Compression/ZipArchive.cs b/mcs/class/System.IO.Compression/ZipArchive.cs index 5df9434321c..4aa7318e4c8 100644 --- a/mcs/class/System.IO.Compression/ZipArchive.cs +++ b/mcs/class/System.IO.Compression/ZipArchive.cs @@ -227,13 +227,20 @@ namespace System.IO.Compression private void Save() { - using (var newZip = new MemoryStream()) { - zipFile.SaveTo(newZip, CompressionType.Deflate, entryNameEncoding ?? Encoding.UTF8); + if (mode == ZipArchiveMode.Create) + { + zipFile.SaveTo(stream, CompressionType.Deflate, entryNameEncoding ?? Encoding.UTF8); + } + else { + using (var newZip = new MemoryStream()) + { + zipFile.SaveTo(newZip, CompressionType.Deflate, entryNameEncoding ?? Encoding.UTF8); - stream.SetLength(0); - stream.Position = 0; - newZip.Position = 0; - newZip.CopyTo(stream); + stream.SetLength(0); + stream.Position = 0; + newZip.Position = 0; + newZip.CopyTo(stream); + } } } |