int ExtractAndCrc(Stream archiveStream, Stream targetOutput, short compressionMethod, long compressedFileDataSize, long uncompressedSize) { int crcResult; var input = archiveStream; // change for workitem 8098 input.Seek(FileDataPosition, SeekOrigin.Begin); var bytes = new byte[BufferSize]; // The extraction process varies depending on how the entry was // stored. It could have been encrypted, and it coould have // been compressed, or both, or neither. So we need to check // both the encryption flag and the compression flag, and take // the proper action in all cases. var leftToRead = (compressionMethod != (short)CompressionMethod.None) ? uncompressedSize : compressedFileDataSize; // Get a stream that either decrypts or not. _inputDecryptorStream = GetExtractDecryptor(input); var input3 = GetExtractDecompressor( _inputDecryptorStream ); var bytesWritten = 0L; // As we read, we maybe decrypt, and then we maybe decompress. Then we write. using (var s1 = new Crc.CrcCalculatorStream(input3)) { while (leftToRead > 0) { //Console.WriteLine("ExtractOne: LeftToRead {0}", LeftToRead); // Casting LeftToRead down to an int is ok here in the else clause, // because that only happens when it is less than bytes.Length, // which is much less than MAX_INT. int len = (leftToRead > bytes.Length) ? bytes.Length : (int)leftToRead; int n = s1.Read(bytes, 0, len); // must check data read - essential for detecting corrupt zip files _CheckRead(n); targetOutput.Write(bytes, 0, n); leftToRead -= n; bytesWritten += n; if (_ioOperationCanceled) break; } crcResult = s1.Crc; } return crcResult; }
int ExtractAndCrc(Stream archiveStream, Stream targetOutput, short compressionMethod, long compressedFileDataSize, long uncompressedSize) { int crcResult; var input = archiveStream; // change for workitem 8098 input.Seek(FileDataPosition, SeekOrigin.Begin); // workitem 10178 Ionic.Zip.SharedUtilities.Workaround_Ladybug318918(input); var bytes = new byte[BufferSize]; // The extraction process varies depending on how the entry was // stored. It could have been encrypted, and it coould have // been compressed, or both, or neither. So we need to check // both the encryption flag and the compression flag, and take // the proper action in all cases. var leftToRead = (compressionMethod != (short)CompressionMethod.None) ? uncompressedSize : compressedFileDataSize; // Get a stream that either decrypts or not. _inputDecryptorStream = GetExtractDecryptor(input); var input3 = GetExtractDecompressor(_inputDecryptorStream); var bytesWritten = 0L; // As we read, we maybe decrypt, and then we maybe decompress. Then we write. using (var s1 = new Crc.CrcCalculatorStream(input3)) { while (leftToRead > 0) { //Console.WriteLine("ExtractOne: LeftToRead {0}", LeftToRead); // Casting LeftToRead down to an int is ok here in the else clause, // because that only happens when it is less than bytes.Length, // which is much less than MAX_INT. int len = (leftToRead > bytes.Length) ? bytes.Length : (int)leftToRead; int n = s1.Read(bytes, 0, len); // must check data read - essential for detecting corrupt zip files _CheckRead(n); targetOutput.Write(bytes, 0, n); leftToRead -= n; bytesWritten += n; // fire the progress event, check for cancels OnExtractProgress(bytesWritten, uncompressedSize); if (_ioOperationCanceled) break; } crcResult = s1.Crc; } return crcResult; }