summaryrefslogtreecommitdiff
path: root/core/fpdfapi/edit/cpdf_objectstream.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-05-10 13:59:14 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-05-10 19:41:00 +0000
commit5b590337e0778b49dd7092af4a283ed0f9c5a2e9 (patch)
tree4aae9dd27685bf2cca6954d5a1a7ef197466b808 /core/fpdfapi/edit/cpdf_objectstream.cpp
parentaa7022833db1a6e21b81fcca30b45ba652298f32 (diff)
downloadpdfium-5b590337e0778b49dd7092af4a283ed0f9c5a2e9.tar.xz
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 <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fpdfapi/edit/cpdf_objectstream.cpp')
-rw-r--r--core/fpdfapi/edit/cpdf_objectstream.cpp56
1 files changed, 14 insertions, 42 deletions
diff --git a/core/fpdfapi/edit/cpdf_objectstream.cpp b/core/fpdfapi/edit/cpdf_objectstream.cpp
index 9b636f2e54..208adacf47 100644
--- a/core/fpdfapi/edit/cpdf_objectstream.cpp
+++ b/core/fpdfapi/edit/cpdf_objectstream.cpp
@@ -51,8 +51,8 @@ FX_FILESIZE CPDF_ObjectStream::End(CPDF_Creator* pCreator) {
if (m_Items.empty())
return 0;
- CFX_FileBufferArchive* pFile = pCreator->GetFile();
- FX_FILESIZE ObjOffset = pCreator->GetOffset();
+ IFX_ArchiveStream* archive = pCreator->GetArchive();
+ FX_FILESIZE ObjOffset = archive->CurrentOffset();
if (!m_dwObjNum)
m_dwObjNum = pCreator->GetNextObjectNumber();
@@ -60,29 +60,14 @@ FX_FILESIZE CPDF_ObjectStream::End(CPDF_Creator* pCreator) {
for (const auto& pair : m_Items)
tempBuffer << pair.objnum << " " << pair.offset << " ";
- int32_t len = pFile->AppendDWord(m_dwObjNum);
- if (len < 0)
+ if (!archive->WriteDWord(m_dwObjNum) ||
+ !archive->WriteString(" 0 obj\r\n<</Type /ObjStm /N ") ||
+ !archive->WriteDWord(pdfium::CollectionSize<uint32_t>(m_Items)) ||
+ !archive->WriteString("/First ") ||
+ !archive->WriteDWord(static_cast<uint32_t>(tempBuffer.GetLength())) ||
+ !archive->WriteString("/Length ")) {
return -1;
- pCreator->IncrementOffset(len);
-
- len = pFile->AppendString(" 0 obj\r\n<</Type /ObjStm /N ");
- if (len < 0)
- return -1;
- pCreator->IncrementOffset(len);
-
- len = pFile->AppendDWord(pdfium::CollectionSize<uint32_t>(m_Items));
- if (len < 0)
- return -1;
- pCreator->IncrementOffset(len);
-
- if (pFile->AppendString("/First ") < 0)
- return -1;
-
- len = pFile->AppendDWord(static_cast<uint32_t>(tempBuffer.GetLength()));
- if (len < 0 || pFile->AppendString("/Length ") < 0)
- return -1;
- pCreator->IncrementOffset(len + 15);
-
+ }
tempBuffer << m_Buffer;
CPDF_FlateEncoder encoder(tempBuffer.GetBuffer(), tempBuffer.GetLength(),
@@ -90,26 +75,13 @@ FX_FILESIZE CPDF_ObjectStream::End(CPDF_Creator* pCreator) {
CPDF_Encryptor encryptor(pCreator->GetCryptoHandler(), m_dwObjNum,
encoder.GetData(), encoder.GetSize());
- len = pFile->AppendDWord(encryptor.GetSize());
- if (len < 0)
- return -1;
- pCreator->IncrementOffset(len);
-
- if (pFile->AppendString("/Filter /FlateDecode") < 0)
- return -1;
- pCreator->IncrementOffset(20);
-
- len = pFile->AppendString(">>stream\r\n");
- if (len < 0 ||
- pFile->AppendBlock(encryptor.GetData(), encryptor.GetSize()) < 0) {
+ if (!archive->WriteDWord(encryptor.GetSize()) ||
+ !archive->WriteString("/Filter /FlateDecode") ||
+ !archive->WriteString(">>stream\r\n") ||
+ !archive->WriteBlock(encryptor.GetData(), encryptor.GetSize()) ||
+ !archive->WriteString("\r\nendstream\r\nendobj\r\n")) {
return -1;
}
- pCreator->IncrementOffset(len + encryptor.GetSize());
-
- len = pFile->AppendString("\r\nendstream\r\nendobj\r\n");
- if (len < 0)
- return -1;
- pCreator->IncrementOffset(len);
return ObjOffset;
}