private void MaybeUnsetCompressionMethodForWriting(int cycle)
{
// if we've already tried with compression... turn it off this time
if (cycle > 1)
{
_CompressionMethod = 0x0;
return;
}
// compression for directories = 0x00 (No Compression)
if (IsDirectory)
{
_CompressionMethod = 0x0;
return;
}
if (this._Source == ZipEntrySource.ZipFile)
{
return; // do nothing
}
// If __FileDataPosition is zero, then that means we will get the data
// from a file or stream.
// It is never possible to compress a zero-length file, so we check for
// this condition.
if (this._Source == ZipEntrySource.Stream)
{
// workitem 7742
if (_sourceStream != null && _sourceStream.CanSeek)
{
// Length prop will throw if CanSeek is false
long fileLength = _sourceStream.Length;
if (fileLength == 0)
{
_CompressionMethod = 0x00;
return;
}
}
}
else if ((this._Source == ZipEntrySource.FileSystem) && (SharedUtilities.GetFileLength(LocalFileName) == 0L))
{
_CompressionMethod = 0x00;
return;
}
// Ok, we're getting the data to be compressed from a
// non-zero-length file or stream, or a file or stream of
// unknown length, and we presume that it is non-zero. In
// that case we check the callback to see if the app wants
// to tell us whether to compress or not.
if (SetCompression != null)
CompressionLevel = SetCompression(LocalFileName, _FileNameInArchive);
// finally, set CompressionMethod to None if CompressionLevel is None
if (CompressionLevel == (short)Crisis.Ionic.Zlib.CompressionLevel.None &&
CompressionMethod == Crisis.Ionic.Zip.CompressionMethod.Deflate)
_CompressionMethod = 0x00;
return;
}