diff options
Diffstat (limited to 'core/fxcrt')
-rw-r--r-- | core/fxcrt/fx_basic.h | 21 | ||||
-rw-r--r-- | core/fxcrt/fx_basic_buffer.cpp | 63 | ||||
-rw-r--r-- | core/fxcrt/fx_stream.h | 8 |
3 files changed, 8 insertions, 84 deletions
diff --git a/core/fxcrt/fx_basic.h b/core/fxcrt/fx_basic.h index 8669c66f5e..e856a3e0ba 100644 --- a/core/fxcrt/fx_basic.h +++ b/core/fxcrt/fx_basic.h @@ -110,27 +110,6 @@ class CFX_WideTextBuf : public CFX_BinaryBuf { CFX_WideTextBuf& operator<<(const CFX_WideTextBuf& buf); }; -class CFX_FileBufferArchive { - public: - CFX_FileBufferArchive(); - ~CFX_FileBufferArchive(); - - void Clear(); - bool Flush(); - int32_t AppendBlock(const void* pBuf, size_t size); - int32_t AppendByte(uint8_t byte); - int32_t AppendDWord(uint32_t i); - int32_t AppendString(const CFX_ByteStringC& lpsz); - void AttachFile(const CFX_RetainPtr<IFX_WriteStream>& pFile); - - private: - static const size_t kBufSize = 32768; - - size_t m_Length; - std::unique_ptr<uint8_t, FxFreeDeleter> m_pBuffer; - CFX_RetainPtr<IFX_WriteStream> m_pFile; -}; - class CFX_UTF8Decoder { public: CFX_UTF8Decoder() { m_PendingBytes = 0; } 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<const uint8_t*>(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<int32_t>(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<IFX_WriteStream>& pFile) { - ASSERT(pFile); - m_pFile = pFile; -} diff --git a/core/fxcrt/fx_stream.h b/core/fxcrt/fx_stream.h index 9e3277720d..5237a7cb94 100644 --- a/core/fxcrt/fx_stream.h +++ b/core/fxcrt/fx_stream.h @@ -44,6 +44,14 @@ class IFX_WriteStream : virtual public CFX_Retainable { virtual bool WriteBlock(const void* pData, size_t size) = 0; }; +class IFX_ArchiveStream : public IFX_WriteStream { + public: + virtual bool WriteByte(uint8_t byte) = 0; + virtual bool WriteDWord(uint32_t i) = 0; + virtual bool WriteString(const CFX_ByteStringC& str) = 0; + virtual FX_FILESIZE CurrentOffset() const = 0; +}; + class IFX_ReadStream : virtual public CFX_Retainable { public: virtual bool IsEOF() = 0; |