From 5b590337e0778b49dd7092af4a283ed0f9c5a2e9 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Wed, 10 May 2017 13:59:14 -0400 Subject: Store the offset in the archive buffer This Cl moves the implementation of the archive buffer behind an IFX_ArchiveStream interface. The buffer holds the current offset and the offset parameter is removed from the CPDF_Creator and various other methods. Change-Id: Ia54e803b58bbfb6ef03fec4a940d2c056d541356 Reviewed-on: https://pdfium-review.googlesource.com/5255 Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- core/fxcrt/fx_basic_buffer.cpp | 63 ------------------------------------------ 1 file changed, 63 deletions(-) (limited to 'core/fxcrt/fx_basic_buffer.cpp') diff --git a/core/fxcrt/fx_basic_buffer.cpp b/core/fxcrt/fx_basic_buffer.cpp index 13057f1670..36da3f4053 100644 --- a/core/fxcrt/fx_basic_buffer.cpp +++ b/core/fxcrt/fx_basic_buffer.cpp @@ -220,66 +220,3 @@ uint32_t CFX_BitStream::GetBits(uint32_t nBits) { m_BitPos += nBits; return result; } - -CFX_FileBufferArchive::CFX_FileBufferArchive() - : m_Length(0), m_pFile(nullptr) {} - -CFX_FileBufferArchive::~CFX_FileBufferArchive() {} - -void CFX_FileBufferArchive::Clear() { - m_Length = 0; - m_pBuffer.reset(); - m_pFile.Reset(); -} - -bool CFX_FileBufferArchive::Flush() { - size_t nRemaining = m_Length; - m_Length = 0; - if (!m_pFile) - return false; - if (!m_pBuffer || !nRemaining) - return true; - return m_pFile->WriteBlock(m_pBuffer.get(), nRemaining); -} - -int32_t CFX_FileBufferArchive::AppendBlock(const void* pBuf, size_t size) { - if (!pBuf || size < 1) - return 0; - - if (!m_pBuffer) - m_pBuffer.reset(FX_Alloc(uint8_t, kBufSize)); - - const uint8_t* buffer = reinterpret_cast(pBuf); - size_t temp_size = size; - while (temp_size) { - size_t buf_size = std::min(kBufSize - m_Length, temp_size); - memcpy(m_pBuffer.get() + m_Length, buffer, buf_size); - m_Length += buf_size; - if (m_Length == kBufSize && !Flush()) - return -1; - - temp_size -= buf_size; - buffer += buf_size; - } - return pdfium::base::checked_cast(size); -} - -int32_t CFX_FileBufferArchive::AppendByte(uint8_t byte) { - return AppendBlock(&byte, 1); -} - -int32_t CFX_FileBufferArchive::AppendDWord(uint32_t i) { - char buf[32]; - FXSYS_itoa(i, buf, 10); - return AppendBlock(buf, (size_t)FXSYS_strlen(buf)); -} - -int32_t CFX_FileBufferArchive::AppendString(const CFX_ByteStringC& lpsz) { - return AppendBlock(lpsz.raw_str(), lpsz.GetLength()); -} - -void CFX_FileBufferArchive::AttachFile( - const CFX_RetainPtr& pFile) { - ASSERT(pFile); - m_pFile = pFile; -} -- cgit v1.2.3