1 // Copyright 2017 The PDFium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef CORE_FXCRT_CFX_MEMORYSTREAM_H_ 8 #define CORE_FXCRT_CFX_MEMORYSTREAM_H_ 9 10 #include "core/fxcrt/data_vector.h" 11 #include "core/fxcrt/fx_stream.h" 12 #include "core/fxcrt/retain_ptr.h" 13 #include "third_party/base/containers/span.h" 14 15 class CFX_MemoryStream final : public IFX_SeekableStream { 16 public: 17 CONSTRUCT_VIA_MAKE_RETAIN; 18 19 // IFX_SeekableStream 20 FX_FILESIZE GetSize() override; 21 FX_FILESIZE GetPosition() override; 22 bool IsEOF() override; 23 size_t ReadBlock(pdfium::span<uint8_t> buffer) override; 24 bool ReadBlockAtOffset(pdfium::span<uint8_t> buffer, 25 FX_FILESIZE offset) override; 26 bool WriteBlockAtOffset(pdfium::span<const uint8_t> buffer, 27 FX_FILESIZE offset) override; 28 bool Flush() override; 29 30 pdfium::span<const uint8_t> GetSpan() const; 31 32 private: 33 CFX_MemoryStream(); 34 ~CFX_MemoryStream() override; 35 36 DataVector<uint8_t> m_data; 37 size_t m_nCurSize = 0; 38 size_t m_nCurPos = 0; 39 }; 40 41 #endif // CORE_FXCRT_CFX_MEMORYSTREAM_H_ 42