static HRESULT GetStreamCRC(ISequentialInStream *inStream, UInt32 &resultCRC) { CCRC crc; crc.Init(); const UInt32 kBufferSize = (1 << 14); Byte buffer[kBufferSize]; for (;;) { UInt32 realProcessedSize; RINOK(inStream->Read(buffer, kBufferSize, &realProcessedSize)); if(realProcessedSize == 0) { resultCRC = crc.GetDigest(); return S_OK; } crc.Update(buffer, realProcessedSize); } }
STDMETHODIMP COutVolumeStream::Write(const void *data, UInt32 size, UInt32 *processedSize) { if(processedSize != NULL) *processedSize = 0; while(size > 0) { if (!_volumeStream) { RINOK(VolumeCallback->GetVolumeSize(_volIndex, &_volSize)); RINOK(VolumeCallback->GetVolumeStream(_volIndex, &_volumeStream)); _volIndex++; _curPos = 0; RINOK(_archive.Create(_volumeStream, true)); RINOK(_archive.SkeepPrefixArchiveHeader()); _crc.Init(); continue; } UInt64 pureSize = COutArchive::GetVolPureSize(_volSize, _file.Name.Length()); UInt32 curSize = (UInt32)MyMin(UInt64(size), pureSize - _curPos); _crc.Update(data, curSize); UInt32 realProcessed; RINOK(_volumeStream->Write(data, curSize, &realProcessed)) data = (void *)((Byte *)data + realProcessed); size -= realProcessed; if(processedSize != NULL) *processedSize += realProcessed; _curPos += realProcessed; if (realProcessed != curSize && realProcessed == 0) return E_FAIL; if (_curPos == pureSize) { RINOK(Flush()); } } return S_OK; }