-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Make DeflateStream write out headers and footers on empty streams. #118570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
fde5a97
aa5f184
5946bf2
dbbc400
29e2bfc
6385ab4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -702,30 +702,40 @@ | |
{ | ||
// stream stack: backingStream -> DeflateStream -> CheckSumWriteStream | ||
|
||
// By default we compress with deflate, except if compression level is set to NoCompression then stored is used. | ||
// Stored is also used for empty files, but we don't actually call through this function for that - we just write the stored value in the header | ||
// Deflate64 is not supported on all platforms | ||
// By default we compress with deflate, except if compression level | ||
// is set to NoCompression then stored is used. | ||
// | ||
Check failure on line 707 in src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchiveEntry.cs
|
||
// Stored is also used for empty files, but we can't know at this | ||
// point if user will write anything to the stream or not. For that | ||
// reason, we defer the instantiation of the compression stream | ||
// until the first write to the CheckSumAndSizeWriteStream happens. | ||
// If the user never writes anything, this will be detected during | ||
// saving and the compression method in the file header will be | ||
// changed to Stored. | ||
// | ||
// Note: Deflate64 is not supported on all platforms | ||
Debug.Assert(CompressionMethod == CompressionMethodValues.Deflate | ||
|| CompressionMethod == CompressionMethodValues.Stored); | ||
Func<Stream> compressorStreamFactory; | ||
|
||
bool isIntermediateStream = true; | ||
Stream compressorStream; | ||
|
||
switch (CompressionMethod) | ||
{ | ||
case CompressionMethodValues.Stored: | ||
compressorStream = backingStream; | ||
compressorStreamFactory = () => backingStream; | ||
isIntermediateStream = false; | ||
break; | ||
case CompressionMethodValues.Deflate: | ||
case CompressionMethodValues.Deflate64: | ||
default: | ||
compressorStream = new DeflateStream(backingStream, _compressionLevel, leaveBackingStreamOpen); | ||
compressorStreamFactory = () => new DeflateStream(backingStream, _compressionLevel, leaveBackingStreamOpen); | ||
break; | ||
|
||
} | ||
bool leaveCompressorStreamOpenOnClose = leaveBackingStreamOpen && !isIntermediateStream; | ||
var checkSumStream = new CheckSumAndSizeWriteStream( | ||
compressorStream, | ||
compressorStreamFactory, | ||
backingStream, | ||
leaveCompressorStreamOpenOnClose, | ||
this, | ||
|
@@ -975,7 +985,6 @@ | |
CompressionMethod = CompressionMethodValues.Stored; | ||
compressedSizeTruncated = 0; | ||
uncompressedSizeTruncated = 0; | ||
Debug.Assert(_compressedSize == 0); | ||
Debug.Assert(_uncompressedSize == 0); | ||
Debug.Assert(_crc32 == 0); | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.