bool CInArchive::FindAndReadMarker(const UInt64 *searchHeaderSizeLimit) { // if (m_Length < NHeader::kMarkerSize) // return false; m_ArchiveStartPosition = 0; m_Position = m_StreamStartPosition; if(m_Stream->Seek(m_StreamStartPosition, STREAM_SEEK_SET, NULL) != S_OK) return false; Byte marker[NHeader::kMarkerSize]; UInt32 processedSize; ReadBytes(marker, NHeader::kMarkerSize, &processedSize); if(processedSize != NHeader::kMarkerSize) return false; if (TestMarkerCandidate(marker)) return true; CByteDynamicBuffer dynamicBuffer; static const UInt32 kSearchMarkerBufferSize = 0x10000; dynamicBuffer.EnsureCapacity(kSearchMarkerBufferSize); Byte *buffer = dynamicBuffer; UInt32 numBytesPrev = NHeader::kMarkerSize - 1; memmove(buffer, marker + 1, numBytesPrev); UInt64 curTestPos = m_StreamStartPosition + 1; for (;;) { if (searchHeaderSizeLimit != NULL) if (curTestPos - m_StreamStartPosition > *searchHeaderSizeLimit) break; UInt32 numReadBytes = kSearchMarkerBufferSize - numBytesPrev; ReadBytes(buffer + numBytesPrev, numReadBytes, &processedSize); UInt32 numBytesInBuffer = numBytesPrev + processedSize; if (numBytesInBuffer < NHeader::kMarkerSize) break; UInt32 numTests = numBytesInBuffer - NHeader::kMarkerSize + 1; for(UInt32 pos = 0; pos < numTests; pos++, curTestPos++) { if (TestMarkerCandidate(buffer + pos)) { m_ArchiveStartPosition = curTestPos; m_Position = curTestPos + NHeader::kMarkerSize; if(m_Stream->Seek(m_Position, STREAM_SEEK_SET, NULL) != S_OK) return false; return true; } } numBytesPrev = numBytesInBuffer - numTests; memmove(buffer, buffer + numTests, numBytesPrev); } return false; }
void CStringItem::AddWChar(UInt16 c) { if (c == '\n') { AddChar('\\'); c = 'n'; } Buf.EnsureCapacity(Size + 2); SetUi16(Buf + Size, c); Size += 2; }
void CStringItem::AddChar(Byte c) { Buf.EnsureCapacity(Size + 2); Buf[Size++] = c; Buf[Size++] = 0; }