Skip to content

Commit b3d0e14

Browse files
committed
Fix severe perf degradation reading Stored file in Mono
When reading a stored file, ZipFile returns a PartialInputStream directly instead of wrapping it with a decompression layer. PartialInputStream handles sharing the underlying stream among multiple threads by calling Seek() before each read. Unlike Microsoft's reference implementation, Mono's FileStream flushes its internal read buffer on every Seek.
1 parent e012155 commit b3d0e14

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/Zip/ZipFile.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -3778,8 +3778,11 @@ public override int Read(byte[] buffer, int offset, int count)
37783778
return 0;
37793779
}
37803780
}
3781-
3782-
baseStream_.Seek(readPos_, SeekOrigin.Begin);
3781+
// Protect against Stream implementations that throw away their buffer on every Seek
3782+
// (for example, Mono FileStream)
3783+
if (baseStream_.Position != readPos_) {
3784+
baseStream_.Seek(readPos_, SeekOrigin.Begin);
3785+
}
37833786
int readCount = baseStream_.Read(buffer, offset, count);
37843787
if (readCount > 0) {
37853788
readPos_ += readCount;

0 commit comments

Comments
 (0)